Socket reading and timestamps

放肆的年华 提交于 2020-01-13 10:46:29

问题


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:


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



来源:https://stackoverflow.com/questions/13304672/socket-reading-and-timestamps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!