简体   繁体   English

remote_endpoint:未连接传输端点

[英]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.

相关问题 从远程客户端获取IP地址:remote_endpoint:传输端点未连接 - get the ip address from a remote client: remote_endpoint: Transport endpoint is not connected 发送数据包给客户端给定的remote_endpoint对象和套接字? - sending packets to a client given the remote_endpoint object and the socket? 套接字已接受,但m_socket.remote_endpoint提高传输端点未连接 - socket accepted but m_socket.remote_endpoint raise Transport endpoint is not connected 带有errno = 107的recv():(连接传输端点) - recv() with errno=107:(transport endpoint connected) 客户端通过套接字未收到数据[传输端点已连接] - Data not received back by client via socket [Transport endpoint is already connected] lsetfilecon 失败:传输端点不支持操作 - lsetfilecon failed: Operation not supported on transport endpoint 如何使用boost asio在未连接的端点上区分繁忙端点 - how to differ a busy endpoint over a not connected one using boost asio 使用 Boost::asio 打开 2 个不同的 sockets 到 1 个通用远程端点 - Open 2 distinct sockets to 1 common remote endpoint using Boost::asio 从单个远程端点读取UDP数据而不会丢失数据 - Read UDP data from a single remote endpoint without data loss 调用socket.remote_endpoint(boost asio库)线程安全 - Call to socket.remote_endpoint(boost asio library) thread safety
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM