是否可以在 select() 的无限循环中使用 nanosleep?
我有一个 C 程序,它使用 for(;;)
循环和 select()
从套接字执行接收/发送操作监视文件描述符。我还需要这个程序每 80 毫秒发送一个数据包到一个数据包,我该如何实现呢? 也许我可以使用 fork()
,子进程只需每 80 毫秒在 select()
监视的文件描述符之一中写入一个 ack 即可。 有更好的解决方案吗?
I have a C program that do recv/send operations from/to socket using a for(;;)
loop and a select()
to monitor the file descriptor. I need also this program to send a packet every 80msec to a packet, how can I implement this?
Maybe I can use a fork()
and the child process simply write an ack in one of the file descriptor monitored by the select()
every 80msec.
Is there better solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当调用 select() 时,您可以使用超时参数来限制选择等待时间。
将超时限制为 80 毫秒并发送所需的数据包相当容易。
When calling select() you can use the timeout argument to limit the selection waiting time.
It is rather easy to limit the timeout to 80msec and send the required packet.