6

我正在尝试并排创建 atcp::acceptor和 a ,但是在等待来自. 如堆栈跟踪所示,访问冲突发生在 Boost IOCP 实现中。libtorrent::sessionstd::cin

  • 视窗 8.1
  • MSVC 12.0 (Visual Studio 2013)
  • 提升 v1.57.0
  • libtorrent-rasterbar v1.0.3

一个让我重现问题的最小示例,

#include <boost/asio.hpp>
#include <libtorrent/session.hpp>

int main(int argc, char *argv[])
{
    boost::asio::io_service io_service;
    boost::asio::ip::tcp::acceptor acceptor(io_service);

    libtorrent::session s;

    std::string line;
    std::getline(std::cin, line); // <----- trigger

    return 0;
}

堆栈跟踪是

lt_test.exe!boost::asio::detail::win_iocp_socket_service_base::do_open(boost::asio::detail::win_iocp_socket_service_base::base_implementation_type & impl, int family, int type, int protocol, boost::system::error_code & ec) Line 300   C++
lt_test.exe!boost::asio::detail::win_iocp_socket_service<boost::asio::ip::tcp>::open(boost::asio::detail::win_iocp_socket_service<boost::asio::ip::tcp>::implementation_type & impl, const boost::asio::ip::tcp & protocol, boost::system::error_code & ec) Line 192  C++
lt_test.exe!boost::asio::socket_acceptor_service<boost::asio::ip::tcp>::open(boost::asio::detail::win_iocp_socket_service<boost::asio::ip::tcp>::implementation_type & impl, const boost::asio::ip::tcp & protocol, boost::system::error_code & ec) Line 144  C++
lt_test.exe!boost::asio::basic_socket_acceptor<boost::asio::ip::tcp,boost::asio::socket_acceptor_service<boost::asio::ip::tcp> >::open(const boost::asio::ip::tcp & protocol, boost::system::error_code & ec) Line 310    C++
lt_test.exe!libtorrent::aux::session_impl::setup_listener(libtorrent::listen_socket_t * s, boost::asio::ip::basic_endpoint<boost::asio::ip::tcp> ep, int & retries, bool v6_only, int flags, boost::system::error_code & ec) Line 2089    C++
lt_test.exe!libtorrent::aux::session_impl::open_listen_port(int flags, boost::system::error_code & ec) Line 2243  C++
lt_test.exe!libtorrent::aux::session_impl::init() Line 1258   C++
lt_test.exe!libtorrent::aux::session_impl::main_thread() Line 4880    C++
lt_test.exe!boost::_mfi::mf0<void,libtorrent::aux::session_impl>::operator()(libtorrent::aux::session_impl * p) Line 50   C++
lt_test.exe!boost::_bi::list1<boost::_bi::value<libtorrent::aux::session_impl *> >::operator()<boost::_mfi::mf0<void,libtorrent::aux::session_impl>,boost::_bi::list0>(boost::_bi::type<void> __formal, boost::_mfi::mf0<void,libtorrent::aux::session_impl> & f, boost::_bi::list0 & a, int __formal) Line 254   C++
lt_test.exe!boost::_bi::bind_t<void,boost::_mfi::mf0<void,libtorrent::aux::session_impl>,boost::_bi::list1<boost::_bi::value<libtorrent::aux::session_impl *> > >::operator()() Line 21   C++
lt_test.exe!boost::asio::detail::win_thread::func<boost::_bi::bind_t<void,boost::_mfi::mf0<void,libtorrent::aux::session_impl>,boost::_bi::list1<boost::_bi::value<libtorrent::aux::session_impl *> > > >::run() Line 117 C++
lt_test.exe!boost::asio::detail::win_thread_function(void * arg) Line 118 C++
[External Code] 
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]  

删除acceptor会使访问冲突异常消失。

这是什么原因造成的?

4

2 回答 2

1

我遇到了同样的问题。通过添加BOOST_ASIO_ENABLE_CANCELIO预处理器定义,我得到了帮助。在这里您可以找到更多信息。

于 2017-12-04T12:31:10.690 回答
0

我遇到了同样的问题,我的代码没有任何问题,确实使用了另一个接受器工作者的构造函数,这让我崩溃了:

this->acceptor = boost::make_shared<boost::asio::ip::tcp::acceptor>(io_service_, endpoint);

而这不是

this->acceptor = boost::make_shared<boost::asio::ip::tcp::acceptor>(io_service_, endpoint.protocol());

注意 protocol() 调用,我正在使用另一个构造函数,令人惊讶的是,它起作用了......

于 2018-10-17T18:07:06.683 回答