在下面的代码中,我想用通用的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");
}
...
cancel_socket_fn(system::error_code e) { socket_.cancel(); }
最佳答案
如果(错误== boost::asio::error::interrupted)...
我认为这是一个设计错误,因为如果从调用io_service::run()(或类似函数)的线程中调用此代码,则在read_until()完成之前将不会调用cancel_socket_fn()。或者,如果它们位于不同的线程中,则这是同步问题,因为计时器方法不是线程安全的。
关于error-handling - 如何映射Windows系统错误代码以增强::error_condition?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6909702/