是一个在运行时抛出访问冲突的小片段。我正在使用Visual Studio 2015并提升1.60.0并在调用
时m_socket.async_connect(end_point, yieldw[ec]);
在增强文件中发生访问冲突" socket_ops.ipp"在
行"socket_type s = error_wrapper(::WSASocketW(af, type, protocol, 0, 0,WSA_FLAG_OVERLAPPED),ec);"
例外是" ConsoleApplication4.exe中0x000007FEFD598A2F(KernelBase.dll)的未处理异常:0xC0000005:访问冲突读取位置0xFFFFFFFFFFFFFFFF。"
#include "stdafx.h"
#include <memory>
#include <boost/asio/io_service.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/asio/write.hpp>
#include <cassert>
#include <thread>
#include <chrono>
int main()
{
boost::asio::io_service m_io_service;
//boost::asio::io_service::strand m_socket_strand{ m_io_service };
boost::asio::io_service::work m_work(m_io_service);
boost::asio::ip::tcp::socket m_socket(m_io_service);
std::thread thread([&]() {
m_io_service.run();
});
boost::asio::ip::tcp protocol_family{ boost::asio::ip::tcp::v4() };
boost::asio::ip::tcp::resolver::query query(protocol_family, "localhost", std::to_string(2101));
boost::asio::ip::tcp::resolver resolver(m_io_service);
boost::asio::ip::tcp::resolver::iterator iterator{ resolver.resolve(query) }; // Hosts can have multiple addresses.
/*boost::asio::ip::tcp::resolver::iterator end_iterator{ iterator };
end_iterator++;
boost::asio::ip::tcp::resolver::iterator end;
if (end_iterator != end)
{
std::ostringstream endpoint_descripiton;
}*/
assert(iterator != boost::asio::ip::tcp::resolver::iterator());
auto end_point = iterator->endpoint();
boost::asio::spawn(m_io_service, [&, end_point](boost::asio::yield_context yieldw)
{
boost::system::error_code ec;
m_socket.async_connect(end_point, yieldw[ec]);
if (ec != boost::system::errc::success)
{
std::this_thread::sleep_for(std::chrono::seconds(5));
}
else
{
}
});
std::this_thread::sleep_for(std::chrono::seconds(20));
return 0;
}
答案 0 :(得分:0)
好好挖掘后我发现这个问题只发生在x64调试中,所有其他配置都很好。所以我想我的设置或库可能还有其他问题。在尝试了最新的升级1_63_0并发现错误消失后,我重新跟踪版本,直到错误再次出现,然后检查最后一个工作副本的发行说明。我发现以下https://svn.boost.org/trac/boost/ticket/12215与我遇到的问题相同。使用boost 1_62_0或更高版本可以解决问题。