如何在C ++中处理异步套接字接收? [英] How to handle asynchronous socket receiving in C++?

查看:189
本文介绍了如何在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,例如 select(2) / 投票(2 ) / epoll(4) / kqueue(2)

Look into non-blocking sockets and polling APIs like select(2)/poll(2)/epoll(4)/kqueue(2).

特别是在C ++中,查看 boost :: asio

Specifically in C++, look into boost::asio.

这篇关于如何在C ++中处理异步套接字接收?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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