为什么tcp 协议下中的connect虽然也会阻塞,但是被信号中断时不能立刻重试

tcp 协议下, connect虽然也会阻塞,但是被信号中断后不能立刻重试。by 《Linux C编程一站式学习》37章第2节

为什么connect被信号中断后不能立刻重试呢?
而accept却可以立即重试呢?

阅读 5.2k
1 个回答

是否 和这个问题 一样?
http://segmentfault.com/q/1010000000672648

connect 在 signal handler返回后, 不会被 自动重启.

http://linux.die.net/man/7/signal

The following interfaces are never restarted after being interrupted by a signal handler, regardless of the use of SA_RESTART; they always fail with the error EINTR when interrupted by a signal handler:
*

Socket interfaces, when a timeout has been set on the socket using setsockopt(2): accept(2), recv(2), recvfrom(2), and recvmsg(2), if a receive timeout (SO_RCVTIMEO) has been set; connect(2), send(2), sendto(2), and sendmsg(2), if a send timeout (SO_SNDTIMEO) has been set.