From af2fa698220f5a88372752f6dd76c5691dd2236e Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Wed, 26 Oct 2011 16:47:20 -0500 Subject: [PATCH] catches socket exception when other end closes the connection right as we are about to --- src/websocket_session.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/websocket_session.cpp b/src/websocket_session.cpp index aa09d23aed..b7cc8fd836 100644 --- a/src/websocket_session.cpp +++ b/src/websocket_session.cpp @@ -711,9 +711,18 @@ bool session::validate_app_close_status(uint16_t status) { void session::drop_tcp(bool dropped_by_me) { m_timer.cancel(); - if (m_socket.is_open()) { - m_socket.shutdown(tcp::socket::shutdown_both); - m_socket.close(); + try { + if (m_socket.is_open()) { + m_socket.shutdown(tcp::socket::shutdown_both); + m_socket.close(); + } + } catch (boost::system::system_error& e) { + if (e.code() == boost::asio::error::not_connected) { + // this means the socket was disconnected by the other side before + // we had a chance to. Ignore and continue. + } else { + throw e; + } } m_dropped_by_me = dropped_by_me; m_state = STATE_CLOSED;