libtorrent和tcp :: acceptor在Windows上发生访问冲突

时间:2017-11-30 10:00:35

标签: c++ visual-c++ boost-asio libtorrent

libtorrent版本(或分支): master / libtorrent-1_1_5

平台/结构: 的Win32

编译器和编译器版本: MSVC-14.0

提升版: 升压1.65.1

以下代码总是导致崩溃。

import processing.serial.*;

Serial myPort;  // Create object from Serial class
String val;     // Data received from the serial port
float myVal = 0;

void setup()
{
  String portName = Serial.list()[6];
  myPort = new Serial(this,portName,9600);
}


void draw()
{
 while (myPort.available() > 0)
 {
    val = myPort.readStringUntil('\n');
    if (myPort != null)
    {
      myVal = float(val);
      println(myVal);
    }
  }
}

调用堆栈:

#include "libtorrent/session.hpp"

#include <chrono>
#include <thread>

using namespace std;
int main()
{
    libtorrent::session session;

    boost::asio::io_service io_service;
        boost::asio::ip::tcp::acceptor acceptor(io_service);

    std::this_thread::sleep_for(chrono::seconds(15));
    return 0;
}

libtorrent编译选项:

>   test-crow-libtorrent.exe!boost::asio::detail::win_iocp_socket_service_base::do_open(struct boost::asio::detail::win_iocp_socket_service_base::base_implementation_type &,int,int,int,class boost::system::error_code &) C++
    test-crow-libtorrent.exe!libtorrent::aux::session_impl::setup_listener(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class boost::asio::ip::tcp const &,int,int,class boost::system::error_code &)    C++
    test-crow-libtorrent.exe!libtorrent::aux::session_impl::open_listen_port(void)  C++
    test-crow-libtorrent.exe!libtorrent::aux::session_impl::init(class boost::shared_ptr<struct libtorrent::settings_pack>) C++
    test-crow-libtorrent.exe!boost::_mfi::mf1<void,struct libtorrent::aux::session_impl,class boost::shared_ptr<struct libtorrent::settings_pack> >::operator()(struct libtorrent::aux::session_impl *,class boost::shared_ptr<struct libtorrent::settings_pack>)   C++
    test-crow-libtorrent.exe!boost::asio::asio_handler_invoke<class boost::_bi::bind_t<void,class boost::_mfi::mf1<void,struct libtorrent::aux::session_impl,class boost::shared_ptr<struct libtorrent::settings_pack> >,class boost::_bi::list2<class boost::_bi::value<struct libtorrent::aux::session_impl *>,class boost::_bi::value<class boost::shared_ptr<struct libtorrent::settings_pack> > > > >(class boost::_bi::bind_t<void,class boost::_mfi::mf1<void,struct libtorrent::aux::session_impl,class boost::shared_ptr<struct libtorrent::settings_pack> >,class boost::_bi::list2<class boost::_bi::value<struct libtorrent::aux::session_impl *>,class boost::_bi::value<class boost::shared_ptr<struct libtorrent::settings_pack> > > > &,...)    C++
    test-crow-libtorrent.exe!boost::asio::detail::completion_handler<class boost::_bi::bind_t<void,class boost::_mfi::mf1<void,struct libtorrent::aux::session_impl,class boost::shared_ptr<struct libtorrent::settings_pack> >,class boost::_bi::list2<class boost::_bi::value<struct libtorrent::aux::session_impl *>,class boost::_bi::value<class boost::shared_ptr<struct libtorrent::settings_pack> > > > >::do_complete(class boost::asio::detail::win_iocp_io_service *,class boost::asio::detail::win_iocp_operation *,class boost::system::error_code const &,unsigned int)   C++
    test-crow-libtorrent.exe!boost::asio::detail::win_iocp_io_service::do_one(bool,class boost::system::error_code &)   C++
    test-crow-libtorrent.exe!boost::asio::detail::win_iocp_io_service::run(class boost::system::error_code &)   C++
    test-crow-libtorrent.exe!boost::asio::io_service::run(void) C++
    test-crow-libtorrent.exe!thread_start<unsigned int (__stdcall*)(void *)>(void * const parameter) Line 115   C++
    kernel32.dll!@BaseThreadInitThunk@12�() Unknown
    ntdll.dll!__RtlUserThreadStart()    Unknown
    ntdll.dll!__RtlUserThreadStart@8�() Unknown

仅在发布版本上发生崩溃。

有人可以帮助我吗?

2 个答案:

答案 0 :(得分:1)

这很可能是由于libtorrent和您的测试应用程序使用链接不兼容的选项造成的。如果libtorrent与运行时静态链接,那么您有责任确保与它相关的任何内容也是如此。

或者,您可以使用适当的构建工具来强制实现链接兼容性(例如boost-build)。

答案 1 :(得分:0)

问题在于预处理器。当您使用boost-build之外的工具构建应用程序(使用libtorrent)时,需要添加BOOST_ASIO_ENABLE_CANCELIO

Here您可以找到有关此问题的更多信息。