提高:: ASIO set_option错误 [英] boost::asio set_option error
问题描述
我有一个简单的的boost ::支持ASIO ::知识产权::这几乎没做什么TCP ::受体
- 它接受一个无限循环的连接。然后,我有在同一时间运行尝试连接多个连接器的...
I have a simple boost::asio::ip::tcp::acceptor
which does almost nothing - it accepts connections in an infinite loop. I then have a number of connectors running at the same time trying to connect...
pSocket->async_connect(endpoint,
[=](boost::system::error_code error)
{
if(!error)
{
boost::asio::ip::tcp::no_delay noDelay(true);
pSocket->set_option(noDelay, error);
assert(!error);
std::cout << error.message() << '\n'; // "An invalid argument was supplied"
}
});
一切都在无限循环运行,我跑2客户端和1台服务器,所有的环回连接。过了一会儿(数百个成功的连接和断开的)设置连接的套接字我得到错误的 no_delay
选项时一个无效的参数提供
。
在什么条件下可以设定在一个插座导致这个错误的选项?
有没有人见过这个,并且知道为什么它的发生和/或方式来解决它?
Under what conditions can setting an option on a socket cause this error? Has anyone seen this before, and know why it's happening and/or a way to fix it?
更新:
如果我改变设定 set_option
喜欢的东西...
do
{
pSocket->set_option(noDelay, error);
} while(error);
...它会成功 - 通常是在第二次尝试失败后,
...it will succeed - usually on the second try after it fails.
推荐答案
昨天我调试一步一步set_option,即set_option使用io_service_impl对象的问题,但它包含坏插座的指针,这就是为什么它压垮。但在套接字创建没有设置这个插座,所以我觉得你不能这样对插座设置选项。
Yesterday i debug set_option step by step, problem that set_option uses io_service_impl object but it contains bad socket pointer, that's why it crushes. But on socket creation nothing is set this socket, so i think you cant set option on socket in this way.
您必须set_option之前打开插座,前试试这个 async_connect
和 set_option
:
You must open socket before set_option, try this before async_connect
and set_option
:
sock->open(boost::asio::ip::tcp::v4());
误差称为错误的文件描述符
这对非初始化插槽直上set_option电话。
Error is called Bad file descriptor
which direct on non-initialized socket on set_option call.
这篇关于提高:: ASIO set_option错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!