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:
- It is another syscall (I'm receiving about 24000 messages per second, so each syscall is notifiable)
- If using this approach, I can only
read()
one message at a time, followed by theioctl()
to get the timestamp. (If I'm reading more than one message in aread()
-call, the followingioctl
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".
Use
recvmmsg(2)
system call, if available with your kernel, and setSO_TIMESTAMP
option.