How to set timeout in recvmmsg()?

c

Solution

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.

Problem

I build a simple application using c that used `recvmmsg()`, and the fifth parameter passed is timeout of `type struct timespec`. I set timeout to 5 seconds, but it's not working, it gets blocking infinity. The code is as the following: ``` struct timespec timeout; timeout.tv_sec = 5; timeout.tv_nsec = 0; result = recvmmsg(fd, datagrams, BATCH_SIZE, 0, &timeout); ```

Original source

Related problems