Reputation: 7749
When reading from a (non-stream) socket in Linux, I can get the (hardware-generated) timestamp of the last received message via a ioctl(sock, SIOCGSTAMP, &tv)
. However, this poses two problems:
read()
one message at a time, followed by the ioctl()
to get the timestamp. (If I'm reading more than one message in a read()
-call, the following ioctl
only yields the timestamp of the last message.)My question is how to achieve receiving messages and their timestamps in as few syscalls as possible. It would be perfect if there was a syscall with semantics like "read as much messages as are pending and their timestamps".
Upvotes: 6
Views: 8622
Reputation: 84151
Use recvmmsg(2)
system call, if available with your kernel, and set SO_TIMESTAMP
option.
Upvotes: 6