Fixed HTTP proxy threading problems.

This commit is contained in:
Thulinma 2013-04-04 01:58:00 +02:00
parent 58c17a6374
commit cb90d6da2e

View file

@ -76,11 +76,12 @@ namespace Connector_HTTP {
} }
std::map<std::string, ConnConn*>::iterator it; std::map<std::string, ConnConn*>::iterator it;
for (it = connectorConnections.begin(); it != connectorConnections.end(); it++){ for (it = connectorConnections.begin(); it != connectorConnections.end(); it++){
if ( !it->second->conn->connected() || it->second->lastUse++ > 15){ ConnConn* ccPointer = it->second;
if (it->second->inUse.try_lock()){ if ( !ccPointer->conn->connected() || ccPointer->lastUse++ > 15){
it->second->inUse.unlock(); if (ccPointer->inUse.try_lock()){
delete it->second;
connectorConnections.erase(it); connectorConnections.erase(it);
ccPointer->inUse.unlock();
delete ccPointer;
it = connectorConnections.begin(); //get a valid iterator it = connectorConnections.begin(); //get a valid iterator
if (it == connectorConnections.end()){ if (it == connectorConnections.end()){
return; return;
@ -328,12 +329,12 @@ namespace Connector_HTTP {
timeouter = new tthread::thread(Connector_HTTP::proxyTimeoutThread, 0); timeouter = new tthread::thread(Connector_HTTP::proxyTimeoutThread, 0);
timeoutMutex.unlock(); timeoutMutex.unlock();
} }
connMutex.unlock();
//lock the mutex for this connection, and handle the request //lock the mutex for this connection, and handle the request
tthread::lock_guard<tthread::mutex> guard(connectorConnections[uid]->inUse); tthread::lock_guard<tthread::mutex> guard(connectorConnections[uid]->inUse);
connMutex.unlock();
//if the server connection is dead, handle as timeout. //if the server connection is dead, handle as timeout.
if ( !connectorConnections.count(uid) || !connectorConnections[uid]->conn->connected()){ if ( !connectorConnections[uid]->conn->connected()){
connectorConnections[uid]->conn->close(); connectorConnections[uid]->conn->close();
return proxyHandleTimeout(H, conn); return proxyHandleTimeout(H, conn);
} }