How is it possible to have send timeout on a non blocking socket?

How is it possible to have send timeout on a non blocking socket?

It isn't. Timeouts are for blocking mode. A non-blocking recv() won't block, and therefore cannot time out either.

I have seen a lot of code which uses SO_SNDTIMEO.

Not in non-blocking mode unless the code concerned is nonsense.


SO_SNDTIMEO is useful for a blocking socket. If the socket's buffer is full, send() can block, in which case it may be useful to use the SO_SNDTIMEO socket option. For non-blocking sockets, if the socket's buffer is full, send will fail immediately, so there is no point in setting SO_SNDTIMEO with a non-blocking socket.