插座的阅读和时间戳 [英] Socket reading and timestamps

查看:177
本文介绍了插座的阅读和时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux的(非流)套接字读取时,我可以通过的ioctl最后收到的消息(硬件产生的)时间戳(袜子,SIOCGSTAMP,&安培; TV)。然而,这造成两个问题:

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:


  • 这是另一个系统调用(我收到约每秒24000的消息,所以每个系统调用是法定报告)

  • 如果使用这种方法,我只能阅读()在一个时间一个消息,接着是的ioctl()来得到时间戳。 (如果我读了阅读() -call,以下的ioctl 仅产生了多个消息最后一条消息的时间戳。)

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

推荐答案

使用的 的recvmmsg(2) 系统调用,如果有你的内核,并设置的 SO_TIMESTAMP 选项。

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

这篇关于插座的阅读和时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆