ApiListener#NewClientHandlerInternal(): shut down TLS stream

This commit is contained in:
Alexander A. Klimov 2019-02-19 18:06:14 +01:00
parent c46157d552
commit 2d16b02520
1 changed files with 13 additions and 0 deletions

View File

@ -7,6 +7,7 @@
#include "remote/jsonrpc.hpp" #include "remote/jsonrpc.hpp"
#include "remote/apifunction.hpp" #include "remote/apifunction.hpp"
#include "base/convert.hpp" #include "base/convert.hpp"
#include "base/defer.hpp"
#include "base/io-engine.hpp" #include "base/io-engine.hpp"
#include "base/netstring.hpp" #include "base/netstring.hpp"
#include "base/json.hpp" #include "base/json.hpp"
@ -570,6 +571,14 @@ void ApiListener::NewClientHandlerInternal(boost::asio::yield_context yc, const
return; return;
} }
bool willBeShutDown = false;
Defer shutDownIfNeeded ([&sslConn, &willBeShutDown, &yc]() {
if (!willBeShutDown) {
sslConn.async_shutdown(yc);
}
});
std::shared_ptr<X509> cert (SSL_get_peer_certificate(sslConn.native_handle()), X509_free); std::shared_ptr<X509> cert (SSL_get_peer_certificate(sslConn.native_handle()), X509_free);
String identity; String identity;
Endpoint::Ptr endpoint; Endpoint::Ptr endpoint;
@ -684,6 +693,8 @@ void ApiListener::NewClientHandlerInternal(boost::asio::yield_context yc, const
if (aclient) { if (aclient) {
aclient->Start(); aclient->Start();
willBeShutDown = true;
} }
} else { } else {
Log(LogNotice, "ApiListener", "New HTTP client"); Log(LogNotice, "ApiListener", "New HTTP client");
@ -691,6 +702,8 @@ void ApiListener::NewClientHandlerInternal(boost::asio::yield_context yc, const
HttpServerConnection::Ptr aclient = new HttpServerConnection(identity, verify_ok, client); HttpServerConnection::Ptr aclient = new HttpServerConnection(identity, verify_ok, client);
AddHttpClient(aclient); AddHttpClient(aclient);
aclient->Start(); aclient->Start();
willBeShutDown = true;
} }
} }