CodeFree/6_solution/高性能定时器/最小堆定时器/readme.md

3 lines
720 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

测试代码为使用epoll实现的一个回射服务器每个客户端连接服务端后会为每个连接设置一个定时器超时时间为15秒每次进行数据交互后就会重置连接对应的定时器如果定时器超时就会被服务器踢掉。程序中使用epoll_wait来将I/O事件与定时事件进行统一处理使用定时容器中最小的超时时间作为epoll_wait的超时时长。启动服务端连接三个客户端进行测试。可以看到三个客户端在超时时间到的时候都被踢掉了。如果客户端在超时时间内发送数据那么服务端就会重置相应客户端的定时器。
文章来源https://mp.weixin.qq.com/s/9VTINJ_rMOmElQUnIuD_7Q