1.服务端listen成功后,系统就自动接收客户端请求了
man listen:
其中有一段
The behavior of the backlog argument on TCP sockets changed with Linux
2.2. Now it specifies the queue length for completely established
sockets waiting to be accepted, instead of the number of incomplete
connection requests. The maximum length of the queue for incomplete
sockets can be set using /proc/sys/net/ipv4/tcp_max_syn_backlog. When
syncookies are enabled there is no logical maximum length and this set‐
ting is ignored. See tcp(7) for more information.
也就是说,listen成功后,系统会自动接受bocklog个客户端请求,并不需要服务端accept,就算服务端没有accept,客户端connect仍然返回成功。accept仅仅是从backlog队列中取出一个已经建立了完整TCP连接的套接字。
2.一个fd socket了connect后,不能再次connect
再次connect,会报错:Transport endpoint is already connected
此时想要再次connect,必须重置fd..
连接建立后socket的状态被置为SS_ISCONNECTED,因此在调用close重置此socket状态之前,会报错。。
原文地址:http://blog.csdn.net/tc725210/article/details/43274267