From a0b1b1a8b30baf934de93b88a58a2bb3d1841373 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Sat, 6 Apr 2013 21:38:41 +0200 Subject: [PATCH] Changed overly complicated HTTP proxy thread handling to automatic, more sane, handling. --- src/connectors/conn_http.cpp | 47 +++--------------------------------- 1 file changed, 3 insertions(+), 44 deletions(-) diff --git a/src/connectors/conn_http.cpp b/src/connectors/conn_http.cpp index 01da7950..3994b651 100644 --- a/src/connectors/conn_http.cpp +++ b/src/connectors/conn_http.cpp @@ -56,9 +56,6 @@ namespace Connector_HTTP { }; std::map connectorConnections; ///< Connections to connectors - std::set activeThreads; ///< Holds currently active threads - std::set doneThreads; ///< Holds threads that are done and ready to be joined. - tthread::mutex threadMutex; ///< Mutex for adding/removing threads. tthread::mutex connMutex; ///< Mutex for adding/removing connector connections. tthread::mutex timeoutMutex; ///< Mutex for timeout thread. tthread::thread * timeouter = 0; ///< Thread that times out connections to connectors. @@ -539,17 +536,6 @@ namespace Connector_HTTP { //close and remove the connection conn->close(); delete conn; - //remove this thread from activeThreads and add it to doneThreads. - threadMutex.lock(); - for (std::set::iterator it = activeThreads.begin(); it != activeThreads.end(); it++){ - if (( *it)->get_id() == tthread::this_thread::get_id()){ - tthread::thread * T = ( *it); - activeThreads.erase(T); - doneThreads.insert(T); - break; - } - } - threadMutex.unlock(); } } //Connector_HTTP namespace @@ -567,41 +553,14 @@ int main(int argc, char ** argv){ while (server_socket.connected() && conf.is_active){ Socket::Connection S = server_socket.accept(); if (S.connected()){ //check if the new connection is valid - //lock the thread mutex and spawn a new thread for this connection - Connector_HTTP::threadMutex.lock(); + //spawn a new thread for this connection tthread::thread * T = new tthread::thread(Connector_HTTP::proxyHandleHTTPConnection, (void *)(new Socket::Connection(S))); - Connector_HTTP::activeThreads.insert(T); - //clean up any threads that may have finished - while ( !Connector_HTTP::doneThreads.empty()){ - T = *Connector_HTTP::doneThreads.begin(); - T->join(); - Connector_HTTP::doneThreads.erase(T); - delete T; - } - Connector_HTTP::threadMutex.unlock(); + //detach it, no need to keep track of it anymore + T->detach(); }else{ Util::sleep(10); //sleep 10ms } } //while connected and not requested to stop server_socket.close(); - - //wait for existing connections to drop - bool repeat = true; - while (repeat){ - Connector_HTTP::threadMutex.lock(); - repeat = !Connector_HTTP::activeThreads.empty(); - //clean up any threads that may have finished - while ( !Connector_HTTP::doneThreads.empty()){ - tthread::thread * T = *Connector_HTTP::doneThreads.begin(); - T->join(); - Connector_HTTP::doneThreads.erase(T); - delete T; - } - Connector_HTTP::threadMutex.unlock(); - if (repeat){ - Util::sleep(100); //sleep 100ms - } - } - return 0; } //main