简体   繁体   English

如何正确关闭IOCP服务器?

[英]How do I properly shut down an IOCP server?

I can find tonnes of article's about starting up an IOCP server, but none about properly shutting it down =/ 我可以找到有关启动IOCP服务器的大量文章,但没有关于正确关闭它的信息= /

What is the proper way to shut the server down when you are done? 完成后关闭服务器的正确方法是什么? more specifically, I already use PostQueuedCompletionStatus() to tell the worker threads to quit, but don't I also need to cancel all the pending IO, and close all the sockets before I quit? 更具体地说,我已经使用PostQueuedCompletionStatus()告诉工作线程退出,但是我还不需要取消所有未决的IO,并在退出之前关闭所有套接字吗?

I found CancelSynchronousIo() on MSDN, and it seems like I could have each worker thread call this function when it receives the completion notification to quit...is this the proper way to do it? 我在MSDN上发现了CancelSynchronousIo() ,似乎当每个工作线程都收到要退出的完成通知时,我可以让每个工作线程都调用此函数...这是正确的方法吗?

thanks for any help on this. 感谢您对此的任何帮助。

If you loop through all of the open connections and shut down all of the sockets then all of the pending I/O will complete on its own and the server will shut down. 如果您遍历所有打开的连接并关闭所有套接字,则所有未决的I / O将自行完成,服务器将关闭。 You can either close with a lingering close to allow any pending write data to complete or you can turn linger off on the sockets and cause pending write data to be discarded and the connections to be reset with an RST rather than shutdown cleanly. 您可以关闭时关闭以允许任何待处理的写数据完成,也可以关闭套接字上的延迟并导致丢弃待处理的写数据,并使用RST重置连接,而不是彻底关闭。

I have some IOCP server examples here , which you may already have seen, but which show how you could achieve a clean shutdown. 这里有一些IOCP服务器示例,您可能已经看到了,但是这些示例显示了如何实现完全关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows关闭时如何执行功能 - How can I Execute a Function when Windows Shut down 如何关闭SQLBase窗口 - How to shut down SQLBase Window 当在后台线程上创建的 Dispatcher 没有关闭时会发生什么? 如何确保调度员正确关闭? - What happens when a Dispatcher created on a background thread is not shutdown? How to make sure that a dispatcher is properly shut down? 我应该为IOCP创建多少个线程? - How many threads I should create for IOCP? 连接非 IOCP 客户端和 IOCP 服务器 - Connecting non-IOCP client with IOCP Server 使用异步i / o和IOCP实现echo服务器的最佳方法是什么? - What is the best way to implement an echo server with async i/o and IOCP? gRPC:在C ++中关闭异步服务器的推荐方法是什么? - gRPC: What is the recommended way to shut down an asynchronous server in C++? 我不想要一个服务器进程,这是一个守护进程关闭 - 即使在收到杀死信号。 有什么方法可以确保吗? - I dont want a server process which is a daemon to shut down - even on recieving kill signal. Is there any way to ensure this? 如何使用C ++捕获Windows关闭/重新启动消息 - How to capture windows shut down/ Restart message using C++ 我可以在IOCP上使用accept()吗? - Can I use accept() with IOCP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM