如何处理异步套接字接收C ++? [英] How to handle asynchronous socket receiving in C++?
问题描述
我目前使用一个线程来处理连接和发送异步调用。这是所有工作正常,但现在我想使异步接收过。我应该如何获得无需暂停整个队列在等待数据的数据?我现在能想到的唯一的解决办法是第二个线程。
I'm currently using a thread to handle Connect and Send calls asynchronously. This is all working fine, but now I want to make receiving asynchronous too. How should I receive data without pausing the whole queue while waiting for data? The only solution I can think of right now is a second thread.
推荐答案
。看看非阻塞套接字和轮询API,如 选择(2)
/的 调查(2)
/的 的epoll(4)
/的 的kqueue(2)
Look into non-blocking sockets and polling APIs like select(2)
/poll(2)
/epoll(4)
/kqueue(2)
.
具体到C ++,看看<一个href=\"http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio.html\"><$c$c>boost::asio$c$c>.
Specifically in C++, look into boost::asio
.
这篇关于如何处理异步套接字接收C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!