From 7ae55fd8e45028df4691578612ad44e64859358a Mon Sep 17 00:00:00 2001 From: Markus Grimm Date: Fri, 29 Dec 2017 23:45:10 +0100 Subject: [PATCH] Close sockets when server responds with HTTP/1.0 --- clients/roscpp/src/libros/xmlrpc_manager.cpp | 2 +- utilities/xmlrpcpp/src/XmlRpcClient.cpp | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/clients/roscpp/src/libros/xmlrpc_manager.cpp b/clients/roscpp/src/libros/xmlrpc_manager.cpp index 1aee46b1a5..14413e23a5 100644 --- a/clients/roscpp/src/libros/xmlrpc_manager.cpp +++ b/clients/roscpp/src/libros/xmlrpc_manager.cpp @@ -380,7 +380,7 @@ void XMLRPCManager::releaseXMLRPCClient(XmlRpcClient *c) { if (c == i->client_) { - if (shutting_down_) + if (shutting_down_ || !c->getKeepOpen()) { // if we are shutting down we won't be re-using the client i->client_->close(); diff --git a/utilities/xmlrpcpp/src/XmlRpcClient.cpp b/utilities/xmlrpcpp/src/XmlRpcClient.cpp index 2d42bb8a5c..3aa54047bd 100644 --- a/utilities/xmlrpcpp/src/XmlRpcClient.cpp +++ b/utilities/xmlrpcpp/src/XmlRpcClient.cpp @@ -130,6 +130,7 @@ XmlRpcClient::execute(const char* method, XmlRpcValue const& params, XmlRpcValue return false; XmlRpcUtil::log(1, "XmlRpcClient::execute: method %s completed.", method); + _header = ""; _response = ""; return true; } @@ -443,7 +444,6 @@ XmlRpcClient::readHeader() // Otherwise copy non-header data to response buffer and set state to read response. _response = bp; - _header = ""; // should parse out any interesting bits from the header (connection, etc)... _connectionState = READ_RESPONSE; return true; // Continue monitoring this source } @@ -495,6 +495,7 @@ XmlRpcClient::parseResponse(XmlRpcValue& result) int offset = 0; if ( ! XmlRpcUtil::findTag(METHODRESPONSE_TAG,_response,&offset)) { XmlRpcUtil::error("Error in XmlRpcClient::parseResponse: Invalid response - no methodResponse. Response:\n%s", _response.c_str()); + _header = ""; return false; } @@ -506,15 +507,31 @@ XmlRpcClient::parseResponse(XmlRpcValue& result) if ( ! result.fromXml(_response, &offset)) { XmlRpcUtil::error("Error in XmlRpcClient::parseResponse: Invalid response value. Response:\n%s", _response.c_str()); _response = ""; + _header = ""; return false; } } else { XmlRpcUtil::error("Error in XmlRpcClient::parseResponse: Invalid response - no param or fault tag. Response:\n%s", _response.c_str()); _response = ""; + _header = ""; return false; } _response = ""; + + if (_header.size() < 8 || _header.find("HTTP/") != 0) + XmlRpcUtil::error("Error XmlRpcClient::readHeader: Header does not start with protocol"); + else + { + const unsigned protocolVersion = atoi(&_header[5]) * 10 + atoi(&_header[7]); + if (protocolVersion == 10) + { + setKeepOpen(false); + close(); + } + } + + _header = ""; return result.valid(); }