11

Does the SO_RCVTIMEO option affect accept (causing it to return EAGAIN or EWOULDBLOCK if the timeout expires)? Is there any behavior specified by the standard? I can't find it in the documentation for accept or use of options:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_10_16

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
  • 1
    I seem to recall the answer being no but I don't remember if the context was SO or something I read. Stevens only mentions read, readv, recv, recvfrom and recvmsg as being affected. It would seem if accept was affected by the option it would be documented somewhere because, well, it would be a useful in some instances. – Duck May 11 '11 at 18:35
  • Also, is it not the case that a connection will not go into the pending queue until the 3-way is already completed? That would negate the point since you going to return with a new socket or not. – Duck May 11 '11 at 18:43
  • I was thinking of a blocking socket and the time `accept` spends blocked when there is no connection attempt. – R.. GitHub STOP HELPING ICE May 11 '11 at 18:45
  • 1
    I know but I thinking what a receive timeout would mean for accept. There is nothing to receive at the app level and does the reception of the SYN/ACK really mean anything when there could be a significant delay between them? A timer based on that doesn't seem to work which is why I don't think SO_RCVTIMEO is proper in this context. Some other timer mechanism would be proper, namely something based on the semantics of there is nothing/something in the queue as opposed to a read buffer. – Duck May 11 '11 at 19:06

1 Answers1

17

While on POSIX SO_RCVTIMEO is defined for "an input function", and SO_SNDTIMEO is defined for "an output function", I can'r find any definition for "input function" or "output function", so I'll just say they are read/receive and write/send at least.

In the specific case of Linux, SO_RCVTIMEO affects accept(), as can be seen by looking at inet_csk_accept(), and SO_SND_TIMEO affects connect(), as can be seen by looking at tcp_sendmsg().

ninjalj
  • 42,493
  • 9
  • 106
  • 148