文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Unix_Network_Programming

Unix_Network_Programming

时间:2007-02-14  来源:ffjnfj

TCP options:
1. MSS, maximum segment size.
2. Window scale, 高速/长延时的连接需要增大window,也叫长肥管道(long fat pipe)。

主动发起关闭连接的一端会进入TIME_WAIT,因为"ACK FIN"的操作是没有ACK的,
如果是被动关闭的话,如果她收到了FIN的ACK,则连接就确定是关闭的了.
TIME_WAIT将持续2MSL, Max Segment Lifetime.
There are two reasons for the TIME_WAIT state:
1. To implement TCP's full-duplex connection termination reliably
2.  To allow old duplicate segments to expire in the network
1) 如果最后一个ACK丢了,那么passive端就会重传FIN,这样就需要维持这样一个状态,
否则就会reset,过程需要2TIME_WAIT,一来一去
2) 当新的连接建立时(同样的IP/PORT), 必须保证前面的连接的segment不再在网络中
如果passive端不断的重传,这个过程会持续多久?如果足够多的话便有可能超过2MSL,
-般在多次超时就会放弃,或固定的时间(报错)

对于listening socket和connected socket,他们使用的port是一样的,这样要在server
端区分出client的数据是发送给谁的,就要知道socketpair(client:port, server:port)

The smallest MTU in the path between two hosts is called the path MTU. Today,
the Ethernet MTU of 1,500 bytes is often the path MTU.

The IPv4 DF("don't fragment") bit and its implied IPv6 counterpart can be used
for path MTU discovery

Three conditions that generate an RST are: when a SYN arrives for a port that
has no listening server (what we just described), when TCP wants to abort an
existing connection, and when TCP receives a segment for a connection that does
not exist.

RPC normally let the kernel choose an ephemeral port for their listening socket
since this port is then registered with the RPC port mapper. Clients have to
contact the port mapper to obtain the ephemeral port before they can connect to
the server.

We must be careful to distinguish between the interface on which a packet
arrives versus the destination IP address of that packet. Most implementations
employ the former, meaning it is okay for a packet to arrive with a destination
IP address that identifies an interface other than the interface on which the
packet arrives.

When connect is interrupted by a caught signal and is not automatically
restarted, we must call select to wait for the connection to complete

linux在系统调用sleep时,收到signal会restart吗?

在signal
handler中调用标准I/O(比如printf)是不好的,因为I/O函数一般都不是re-entrant

since a daemon runs without a controlling terminal, it should never receive the
SIGHUP signal from the kernel. Therefore, many daemons use this signal as a
notification from the administrator that the daemon's configuration file has
changed, and the daemon should reread the file. Two other signals that a daemon
should never receive are SIGINT and SIGWINCH, so daemons can safely use these
signals as another way for administrators to indicate some change that the
daemon should react to.

inet的wait标志 一般tcp server都会设置为nowait,而udp
server则会设置为wait。因为tcp连接有listening/connected socket, 而udp
server只有一个socket,这样inet就分不清楚新来的datagram是给udp
server的,还是从另外的client来的,
如果设置为nowait,那么就有可能inet先看到这个datagram,从而重新fork另一个进程,
这是没必要的,甚至还有可能引起错误。所以对于udp server一般都设为wait,也就是
inet要wait该进程死了才能fork另一个。

UDP可以发送0个字节的datagram,而TCP则不行,因为要有序列号

It is normal for the descriptor number in the
receiving process to differ from the descriptor number in the sending process.
Passing a descriptor is not passing a descriptor number, but involves creating
a new descriptor in the receiving process that refers to the same file table
entry within the kernel as the descriptor that was sent by the sending process.

Unix Domain Protocols可以使用ancillary data来发送文件描述符,比如子进程可以
打开一个文件,然后把fd发送给父进程使用。比如子进程是suid的,那么父进程就可以
得到它。(sendmsg/recvmsg) 也可以发送credentials(也就是一些uid,gid之类),比如
有一个程序想使用1024以下的port,但又不是root,怎么办呢?通过另外一个server
打开一个该port的fd(binded/bound socket),认证请求进程,发送fd

排行榜 更多 +
我的酒厂

我的酒厂

音乐节奏 下载
一起单车

一起单车

模拟经营 下载
文字成精

文字成精

休闲益智 下载