如何更改CSocket以使用非阻塞模式 [英] How to change a CSocket to use nonblocking mode

查看:340
本文介绍了如何更改CSocket以使用非阻塞模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改CSocket以使用非阻塞模式?

How to change a CSocket to use nonblocking mode?

推荐答案

对于非阻塞调用,您需要使用CAsyncSocket.阻塞的说明如下:
http://msdn.microsoft.com/en-us/library/3tbz7kf5%28v = vs.100%29.aspx [ ^ ].

我建议使用CSocket并阻止线程调用.在单独的线程中进行所有联网.我认为异步API是在线程不常见且目前没有任何意义的情况下提供的.线程解决方案更加简单明了,异步回调等的角色由线程通信原语扮演,这些原语更加明确,可以为您提供更多的控制权.

—SA
For non-blocking calls you need to use CAsyncSocket instead. Blocking is explained here:
http://msdn.microsoft.com/en-us/library/3tbz7kf5%28v=vs.100%29.aspx[^].

I would advise to use CSocket and blocking calls with threads. Do all networking in separate threads. I think asynchronous APIs were offered when threads were not a commonplace and presently does not make a lot of sense. Threaded solutions are more straightforward, and the role of asynchronous callbacks, etc are played by thread communication primitives which are more explicit and give you more control.

—SA


这篇关于如何更改CSocket以使用非阻塞模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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