在 boost::asio::ip::tcp::socket 上设置非阻塞时出现错误文件描述符错误
我是 boost 的新手,我一直在尝试 boost::asio 。问题是在设置某些选项时我总是收到“错误文件描述符”错误/异常(我需要使其成为非阻塞)。即使这里也失败了:
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
int main( )
{
boost::asio::io_service io_service;
tcp::socket socket( io_service );
boost::asio::socket_base::non_blocking_io option(true);
socket.io_control( option );
return 0;
}
在运行时弹出:
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >'
what(): Bad file descriptor
这真的很令人沮丧,因为我已经尝试了一切。如果重要的话,操作系统是 Linux x64。
I'm new to boost and I've been trying out boost::asio. The problem is I always get an "Bad File Descriptor" error/exception when setting some options (I need to make it non-blocking). Even this here fails:
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
int main( )
{
boost::asio::io_service io_service;
tcp::socket socket( io_service );
boost::asio::socket_base::non_blocking_io option(true);
socket.io_control( option );
return 0;
}
During run-time this pops up:
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >'
what(): Bad file descriptor
Which is getting really frustrating as I've tried everything. OS is Linux x64 if it matters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您调用了 未打开的套接字构造函数
套接字
。您可以使用在调用socket::io_control()
之前打开socket
的其他重载之一,或者显式打开socket
。You invoked the socket constructor that does not open the
socket
. You could use one of the other overloads that open thesocket
prior to invokingsocket::io_control()
, or open thesocket
explicitly.