diff --git a/clients/roscpp/src/libros/xmlrpc_manager.cpp b/clients/roscpp/src/libros/xmlrpc_manager.cpp index 15175ff5e7..930036d414 100644 --- a/clients/roscpp/src/libros/xmlrpc_manager.cpp +++ b/clients/roscpp/src/libros/xmlrpc_manager.cpp @@ -370,7 +370,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 b53305968b..83f91b1156 100644 --- a/utilities/xmlrpcpp/src/XmlRpcClient.cpp +++ b/utilities/xmlrpcpp/src/XmlRpcClient.cpp @@ -107,6 +107,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; } @@ -403,7 +404,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 } @@ -447,6 +447,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; } @@ -458,15 +459,25 @@ 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 = ""; + + // Close connection if protocol is HTTP/1.0 + if (_header.rfind("HTTP/1.0", 0) == 0) { + setKeepOpen(false); + close(); + } + + _header = ""; return result.valid(); }