Skip to content

Commit

Permalink
Recreate socket on failed connection #154
Browse files Browse the repository at this point in the history
  • Loading branch information
yse committed Mar 26, 2019
1 parent 0ccb564 commit 3be797b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 6 additions & 1 deletion easy_profiler_core/easy_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ void EasySocket::flush()
if (m_socket)
closeSocket(m_socket);

if (m_replySocket != m_socket)
if (m_replySocket != m_socket && m_replySocket != 0) {
// we do not need to close uninitialized reply socket
closeSocket(m_replySocket);
}

#if defined(_WIN32)
m_socket = 0;
Expand Down Expand Up @@ -157,6 +159,9 @@ void EasySocket::checkResult(int result)
#if !defined(_WIN32)
case SOCK_BROKEN_PIPE:
case SOCK_ENOENT:
#endif
#if defined (__APPLE__)
case ECONNREFUSED:
#endif
m_state = ConnectionState::Disconnected;
break;
Expand Down
8 changes: 3 additions & 5 deletions profiler_gui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2536,11 +2536,9 @@ void MainWindow::onConnectClicked(bool)
if (!m_listener.connect(address.toStdString().c_str(), port, reply))
{
Dialog::warning(this, "Warning", QString("Cannot connect to %1").arg(address), QMessageBox::Close);
if (EASY_GLOBALS.connected)
{
m_listener.closeSocket();
setDisconnected(false);
}
// we need to close socket everytime on failed connection
m_listener.closeSocket();
setDisconnected(false);

if (!isSameAddress)
{
Expand Down

0 comments on commit 3be797b

Please sign in to comment.