c++ - Windows 上的 Boost asio 套接字无法异步连接

标签 c++ windows sockets boost-asio

调用async_connect时出错,是

uncaught exception of type N5boost16exception_detail10clone_implINS0_19error_info_injectorINS_6system12system_errorEEEEE
- socket_select_interrupter: The attempted operation is not supported for the type of object referenced

分解:

uncaught exception of type boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> > - socket_select_interrupter: The attempted operation is not supported for the type of object referenced

这里是一些相关的代码:

typedef boost::shared_ptr<boost::asio::ip::tcp::socket> tTCPSocketPtr;

boost::shared_ptr<boost::asio::io_service> ioService =  boost::shared_ptr<boost::asio::io_service> (new boost::asio::io_service());

socketPtr = tTCPSocketPtr(new boost::asio::ip::tcp::socket(*ioService));

boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::address::from_string(this->ipAddress),  this->port);


// Set a deadline for the connect operation.
deadline->expires_from_now(boost::posix_time::seconds(5));

socketPtr->async_connect(endpoint,
        boost::bind(&AConnection::handle_connect,
        shared_from_this(), _1, endpoint)); //errors out here

我用谷歌搜索过,没有发现任何有用的东西。

我该如何解决这个错误? 谢谢你, 某人

最佳答案

您没有显示足够的代码。

不过,使用我的 Crystal 球,我可以猜到您收到的是 Win32 错误代码,这可能意味着您使用的句柄无效。

看到您使用了 enable_shared_from_this,我猜这会导致您的问题(尽管它在代码中未显示)。

我最好的猜测是您可能在构造函数内部使用 shared_from_this(这会导致错误)。

关于c++ - Windows 上的 Boost asio 套接字无法异步连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27255882/

相关文章:

c++ - 如何在 C++ 中为模板函数实例创建快捷方式?

node.js - 提取文件图标并以html显示

windows - 在 Windows 上运行 'docker-compose up' 会引发 "No module named fnctl"错误

java - 如何通过数据报套接字发送对象

c++ - 简单类迭代器的开始、结束规范

c++ - 在函数/类声明附近编写 C++ 单元测试

c++ - %[^\n] 在 scanf() 格式字符串中是什么意思

c++ - 如何进入控制台程序并从中读取内容?

java - 尝试读取字节时输入流错误

delphi - 如何检测TThreadList引用的指针是否无效以避免AV