Error handling 如何将Windows系统错误代码映射到boost::error\u条件?

Error handling 如何将Windows系统错误代码映射到boost::error\u条件?,error-handling,cross-platform,boost-asio,Error Handling,Cross Platform,Boost Asio,在下面的代码中,我想用通用boost系统错误代码替换Windows WinSock错误WSAEINTR=10004,但如何将调试器中找到的代码映射到通用枚举 timeout_.expires_from_now(posix_time::seconds(15)); timeout_.async_wait( boost::bind(&cancel_socket_fn,this,_1) ); asio::streambuf rd_buf; unsigned length = read_until

在下面的代码中,我想用通用boost系统错误代码替换Windows WinSock错误WSAEINTR=10004,但如何将调试器中找到的代码映射到通用枚举

timeout_.expires_from_now(posix_time::seconds(15));
timeout_.async_wait( boost::bind(&cancel_socket_fn,this,_1) );
asio::streambuf rd_buf;
unsigned length = read_until( socket_, rd_buf,delimiter_string, error );
timeout_.cancel();

if(error) 
{
    // how do I make this portable?
    if(error.value()==WSAEINTR) throw request_timeout_exception()
    else throw my_asio_exception(error,"Unable to read header");
}

如果(错误==boost::asio::错误::中断)

我认为这是一个设计错误,因为如果从调用io_service::run()(或类似)的线程调用此代码,那么在read_until()完成之前不会调用cancel_socket_fn()。或者,如果它们位于不同的线程中,则会出现同步问题,因为计时器方法不是线程安全的

cancel_socket_fn(system::error_code e) { socket_.cancel(); }