accept返回的fd是否继承listen fd的options

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ssss1223ss/article/details/89786941

<<UNIX Netwok programming>> 7.4

The following socket options are inherited by a connected TCP socket from the listening socket: SO_DEBUG,SO_DONTROUTE,SO_KEEPALIVE,SO_LINGER,SO_OOBINLINE,SO_RCVBUF,SO_RCVLOWAT,SO_SNDBUF,SO_SNDLOWAT,TCP_MAXSEG,TCP_NODELAY.This is importnat with TCP because the connected socket is not returned to a server by accept until the three-way handshake is completed by the TCP layer.To ensure that one of these socket options is set for the connected socket when the three-way handshake completes, we must set that option for the listening socket.

在UNIX系统上,这些socket optionSO_DEBUG, SO_DONTROUTE, SO_KEEPALIVE, SO_LINGER,SO_OOBINLINE, SO_RCVBUF, SO_RCVLOWAT, SO_SNDBUF, SO_SNDLOWAT, TCP_MAXSEG, TCP_NODELAY会被accept的fd从listen fd继承,因为三次握手在内核TCP协议栈,此时有些行为还来不及在应用层设置,所以需要从listen fd继承。

不同版本,不同操作系统行为可能不同,需要进一步测试。

猜你喜欢

转载自blog.csdn.net/ssss1223ss/article/details/89786941
fd