在 Windows 上从 1_55 更新到 1_62 后,在 LIB 中创建 boost::asio::ip::udp::socket 崩溃

Creating a boost::asio::ip::udp::socket crashing in LIB after updating from 1_55 to 1_62 on Windows

这让我抓狂。主要是因为它在 90% 的时间里都会发生,但偶尔我也能做到。

这是背景故事。我使用 MSVC++ 2012 编译了 boost 1_55,我们已经使用它很长一段时间了。我们终于切换到 2013 工具链,我的任务是升级所有内容。

我选择获取最新的提升 1_62,并使用 2013 32 位工具集重新编译。我遇到的问题是,现在我已经重新编译了,但在创建 udp 套接字时遇到了崩溃。

所以我有一个我们开发的静态库link。我从该库继承并调用一个打开 UDP 端口的方法。

为了示例的缘故,我更改了我的代码以最好地说明这一点:

在 class 构造函数中,我有以下内容:

        boost::asio::io_service test;
        boost::asio::ip::udp::socket socket(test);

        this->StartListen();

效果很好。在 StartListen 中,我调用 Init 我有以下内容:

        boost::asio::ip::udp::endpoint listen_endpoint(
        boost::asio::ip::address::from_string(m_bindAddress), m_usPort);
    m_mcast_endpoint.reset(new boost::asio::ip::udp::endpoint(
        boost::asio::ip::address::from_string(m_sendAddress), m_usPort));
    m_socket.reset(new boost::asio::ip::udp::socket(m_ioservice));

这在 m_socket.reset 上爆炸了:

Unhandled exception at 0x77D798C1 (ntdll.dll) in program.exe: 0xC0000374: A heap has been corrupted (parameters: 0x77DAC8D0).

有趣的是,当我将示例更改为开始时立即收听时,如下所示:

  void Multicast::StartListen()
{
    boost::asio::io_service take2;
    boost::asio::ip::udp::socket socket_test(take2);

我明白了:

Unhandled exception at 0x6384D4A1 in program.exe: 0xC00001A5: An invalid exception handler routine has been detected (parameters: 0x00000003).

我真的不知道这里发生了什么。我用

构建了 boost

b2.exe --build-type=complete --stagedir=bin32 address-model=32 stage

一切似乎都是正确的。我错过了什么?

好吧,我取得了更多进步。当您在库中创建一个 boost UDP 套接字,并在调用该库的代码中创建一个 boost UDP 套接字时,就会出现此问题。

So: 
Main 
| 
| Create UDP Socket 
| 
CALL LIBRARY 
 | 
 | 
 | Create UDP SOCKET <--- Heap corruption

也许您使用 1_55 的 headers 进行编译,但 link 使用 1_62

的库进行编译

问题出在 Boost.ASIO 并从两个单独的项目中使用它。在两个项目属性中放置 BOOST_ASIO_DISABLE_IOCP 定义解决了这个问题。可能 "better way" 使用 IOCP,但这解决了它。