2011-08-02 32 views
1

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

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(); } 

回答

0

如果(错误==的boost ::支持ASIO ::错误::打断)...

而且我觉得这里是一个设计错误,因为如果这个代码是从调用io_service :: run()(或类似的)的线程调用的,然后在read_until()完成之前不会调用cancel_socket_fn()。或者如果他们在不同的线程中,那么这里是同步问题,因为定时器方法不是线程安全的。

相关问题