From fdba503b2282a40c124066503de7cabe6afac7fa Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sat, 17 Sep 2022 10:10:06 +0200 Subject: [PATCH] fix(connection): respect disconnect() requests while connecting --- src/Connection.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Connection.cpp b/src/Connection.cpp index 5285607..07e236a 100644 --- a/src/Connection.cpp +++ b/src/Connection.cpp @@ -198,7 +198,11 @@ void Connection::resolve() return; } - m_state = State::CONNECTING; + // Only change the state if no disconnect() has been requested in the mean time. + if (m_state != State::STOP) + { + m_state = State::CONNECTING; + } } bool Connection::connectToAny() @@ -222,6 +226,11 @@ bool Connection::connectToAny() } int result = select(FD_SETSIZE, nullptr, &write_fds, nullptr, &timeout); + // As we have waiting a bit, check if no disconnect has been requested. + if (m_state == State::STOP) + { + return true; + } // Check if there was an error on select(). This is hard to recover from. if (result < 0) @@ -320,9 +329,13 @@ bool Connection::connectToAny() LOG_WARNING(this, "Could not set socket to non-blocking; expect performance impact"); } - m_socket = socket_connected; - sendConnect(); - m_state = State::AUTHENTICATING; + // Only change the state if no disconnect() has been requested in the mean time. + if (m_state != State::STOP) + { + m_state = State::AUTHENTICATING; + m_socket = socket_connected; + sendConnect(); + } return true; } -- libgit2 0.21.4