Socket reading and timestamps

2019-05-03 06:54发布

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 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".

1条回答
甜甜的少女心
2楼-- · 2019-05-03 07:39

Use recvmmsg(2) system call, if available with your kernel, and set SO_TIMESTAMP option.

查看更多
登录 后发表回答