Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个C程序,它使用for(;;)循环和 aselect()来监视文件描述符从/到套接字执行接收/发送操作。我还需要这个程序每 80 毫秒向一个数据包发送一个数据包,我该如何实现呢?也许我可以使用 a并且子进程只需在每 80 毫秒fork()监视的文件描述符之一中写入一个 ack 。select()有更好的解决方案吗?
for(;;)
select()
fork()
调用 select() 时,您可以使用 timeout 参数来限制选择等待时间。
struct timeval { long tv_sec; /* seconds */ long tv_usec; /* microseconds */ }; int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
将超时限制为 80 毫秒并发送所需的数据包是相当容易的。