[英]remote_endpoint: Transport endpoint is not connected
Exception is emitted from io_service:run
on Linux. 从
io_service:run
发出异常io_service:run
在Linux上运行。
This is what happens. 这就是发生的事情。 I implemented simple asynchronous echo server using Boost.Asio.
我使用Boost.Asio实现了简单的异步echo服务器。 It is single threaded and everything is asynchronous, that is I use only asynchronous versions of accept, send and receive functions.
它是单线程的,一切都是异步的,也就是说我只使用了accept,send和receive函数的异步版本。 When a client doesn't disconnect gracefully (eg it crashes) server's event loop throws boost::system::system_error exception remote_endpoint: Transport endpoint is not connected .
当客户端没有正常断开连接(例如它崩溃)时,服务器的事件循环抛出boost :: system :: system_error异常remote_endpoint:传输端点未连接 。 Why it happens an how to deal with it?
为什么会发生如何应对呢? Is it caused by SIGPIPE signal?
它是由SIGPIPE信号引起的吗? If so, what is the best way to keep the server running?
如果是这样,保持服务器运行的最佳方法是什么? Handle exception or handle signal?
处理异常或处理信号?
The exception indicates that the throwing version of basic_stream_socket::remote_endpoint()
was invoked, where in the underlying call to getpeername()
returned with an error of ENOTCONN
. 该异常表示调用了
basic_stream_socket::remote_endpoint()
的抛出版本,其中在getpeername()
的底层调用中返回了错误ENOTCONN
。 Per the effect of exceptions thrown from handlers documentation, exceptions thrown within a handler are permitted to propagate up through the throwing thread's invocation of run()
, run_one()
, poll()
, or poll_one()
. 根据处理程序文档抛出的异常的影响,允许在处理程序中抛出的异常通过抛出线程调用
run()
, run_one()
, poll()
或poll_one()
来传播。
To resolve this, consider either: 要解决此问题,请考虑:
Invoking the non-throwing version of basic_stream_socket::remote_endpoint()
, and handle the error appropriately: 调用
basic_stream_socket::remote_endpoint()
- basic_stream_socket::remote_endpoint()
的非抛出版本,并适当地处理错误:
boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint(ec); if (ec) { // An error occurred. Stop the asynchronous call chain for // this connection. }
Invoke run()
from within a try
/ catch
block. 从
try
/ catch
块中调用run()
。 The following code is mentioned in the documentation: 文档中提到了以下代码:
boost::asio::io_service io_service; ... for (;;) { try { io_service.run(); break; // run() exited normally } catch (my_exception& e) { // Deal with exception as appropriate. } }
With this approach, the thread may re-invoke run()
without the need of invoking reset()
on the io_service
. 使用这种方法,线程可以重新调用
run()
而无需在io_service
上调用reset()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.