Skip to content

Commit

Permalink
Close sockets when server responds with HTTP/1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrrx committed Dec 30, 2017
1 parent bc33f0c commit 0de5a73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion clients/roscpp/src/libros/xmlrpc_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
19 changes: 18 additions & 1 deletion utilities/xmlrpcpp/src/XmlRpcClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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::parseResponse: 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();
}

0 comments on commit 0de5a73

Please sign in to comment.