From 2b83e134f9811e7a951bb18e8ecc82705b88c6e6 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 15 Dec 2015 11:58:32 +0100 Subject: [PATCH] explicitly set closed flag --- lib/SimpleHttpClient/ClientConnection.cpp | 5 +++++ lib/SimpleHttpClient/ConnectionManager.cpp | 4 ---- lib/SimpleHttpClient/GeneralClientConnection.cpp | 2 +- lib/SimpleHttpClient/SslClientConnection.cpp | 11 +++++++++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/SimpleHttpClient/ClientConnection.cpp b/lib/SimpleHttpClient/ClientConnection.cpp index 40fc497465..fe1d055a12 100644 --- a/lib/SimpleHttpClient/ClientConnection.cpp +++ b/lib/SimpleHttpClient/ClientConnection.cpp @@ -135,15 +135,20 @@ bool ClientConnection::connectSocket () { if (_endpoint->isConnected()) { _endpoint->disconnect(); + _isConnected = false; } _socket = _endpoint->connect(_connectTimeout, _requestTimeout); if (! TRI_isvalidsocket(_socket)) { _errorDetails = _endpoint->_errorMessage; + _isConnected = false; return false; } + + _isConnected = true; + // note: checkSocket will disconnect the socket if the check fails if (checkSocket()) { return _endpoint->isConnected(); } diff --git a/lib/SimpleHttpClient/ConnectionManager.cpp b/lib/SimpleHttpClient/ConnectionManager.cpp index 9d11ed347c..a6db708c3b 100644 --- a/lib/SimpleHttpClient/ConnectionManager.cpp +++ b/lib/SimpleHttpClient/ConnectionManager.cpp @@ -297,10 +297,6 @@ ConnectionManager::SingleServerConnection* ConnectionManager::leaseConnection (s // finally create the SingleServerConnection std::unique_ptr c(new SingleServerConnection(s, cn.get(), ep.get(), endpoint)); - if (c == nullptr) { - return nullptr; - } - // Now put it into our administration: s->addConnection(c.get()); diff --git a/lib/SimpleHttpClient/GeneralClientConnection.cpp b/lib/SimpleHttpClient/GeneralClientConnection.cpp index 041ed78b35..e35f280d4c 100644 --- a/lib/SimpleHttpClient/GeneralClientConnection.cpp +++ b/lib/SimpleHttpClient/GeneralClientConnection.cpp @@ -103,7 +103,7 @@ bool GeneralClientConnection::connect () { return false; } - _isConnected = connectSocket(); + connectSocket(); if (! _isConnected) { return false; diff --git a/lib/SimpleHttpClient/SslClientConnection.cpp b/lib/SimpleHttpClient/SslClientConnection.cpp index e4134ddd3b..52477cae13 100644 --- a/lib/SimpleHttpClient/SslClientConnection.cpp +++ b/lib/SimpleHttpClient/SslClientConnection.cpp @@ -163,31 +163,37 @@ bool SslClientConnection::connectSocket () { if (_endpoint->isConnected()) { disconnectSocket(); + _isConnected = false; } _socket = _endpoint->connect(_connectTimeout, _requestTimeout); if (! TRI_isvalidsocket(_socket) || _ctx == nullptr) { _errorDetails = _endpoint->_errorMessage; + _isConnected = false; return false; } + + _isConnected = true; _ssl = SSL_new(_ctx); if (_ssl == nullptr) { _errorDetails = std::string("failed to create ssl context"); disconnectSocket(); + _isConnected = false; return false; } if (SSL_set_fd(_ssl, (int) TRI_get_fd_or_handle_of_socket(_socket)) != 1) { _errorDetails = std::string("SSL: failed to create context ") + - ERR_error_string(ERR_get_error(), NULL); + ERR_error_string(ERR_get_error(), nullptr); disconnectSocket(); + _isConnected = false; return false; } - SSL_set_verify(_ssl, SSL_VERIFY_NONE, NULL); + SSL_set_verify(_ssl, SSL_VERIFY_NONE, nullptr); ERR_clear_error(); @@ -242,6 +248,7 @@ bool SslClientConnection::connectSocket () { } } disconnectSocket(); + _isConnected = false; return false; }