How to set timeout in recvmmsg()?

As an alternative, you could use setsockopt with SO_RCVTIMEO option to set a timeout on the socket. This will affect all read operations performed on it.


See here: http://permalink.gmane.org/gmane.linux.man/3440

Basically the timeout parameter specifies a maximum amount of time to wait for more messages, but the underlying receive operation is still blocking. So if you set a timeout of 5 seconds and receive one message every second, it will stop after receiving (about) 5 messages even if there is space in the buffers for more. What it will not do is return after 5 seconds if there is no data coming at all. For that you should use one of the usual mechanisms, like select() or epoll() with a timeout, or busy waiting, etc.

Tags:

C