Fixed HTTP proxy race condition.
This commit is contained in:
parent
e06ac66757
commit
898cc961ad
1 changed files with 14 additions and 7 deletions
|
@ -58,6 +58,8 @@ namespace Connector_HTTP {
|
||||||
|
|
||||||
std::map<std::string, ConnConn *> connectorConnections; ///< Connections to connectors
|
std::map<std::string, ConnConn *> connectorConnections; ///< Connections to connectors
|
||||||
tthread::mutex connMutex; ///< Mutex for adding/removing connector connections.
|
tthread::mutex connMutex; ///< Mutex for adding/removing connector connections.
|
||||||
|
bool timeoutThreadStarted = false;
|
||||||
|
tthread::mutex timeoutStartMutex; ///< Mutex for starting timeout thread.
|
||||||
tthread::mutex timeoutMutex; ///< Mutex for timeout thread.
|
tthread::mutex timeoutMutex; ///< Mutex for timeout thread.
|
||||||
tthread::thread * timeouter = 0; ///< Thread that times out connections to connectors.
|
tthread::thread * timeouter = 0; ///< Thread that times out connections to connectors.
|
||||||
JSON::Value capabilities; ///< Holds a list of all HTTP connectors and their properties
|
JSON::Value capabilities; ///< Holds a list of all HTTP connectors and their properties
|
||||||
|
@ -67,6 +69,7 @@ namespace Connector_HTTP {
|
||||||
void proxyTimeoutThread(void * n){
|
void proxyTimeoutThread(void * n){
|
||||||
n = 0; //prevent unused variable warning
|
n = 0; //prevent unused variable warning
|
||||||
tthread::lock_guard<tthread::mutex> guard(timeoutMutex);
|
tthread::lock_guard<tthread::mutex> guard(timeoutMutex);
|
||||||
|
timeoutThreadStarted = true;
|
||||||
while (true){
|
while (true){
|
||||||
{
|
{
|
||||||
tthread::lock_guard<tthread::mutex> guard(connMutex);
|
tthread::lock_guard<tthread::mutex> guard(connMutex);
|
||||||
|
@ -414,14 +417,18 @@ namespace Connector_HTTP {
|
||||||
std::cout << "Re-using connection " << uid << std::endl;
|
std::cout << "Re-using connection " << uid << std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
//start a new timeout thread, if neccesary
|
{//start a new timeout thread, if neccesary
|
||||||
|
tthread::lock_guard<tthread::mutex> guard(timeoutStartMutex);
|
||||||
if (timeoutMutex.try_lock()){
|
if (timeoutMutex.try_lock()){
|
||||||
if (timeouter){
|
if (timeouter){
|
||||||
timeouter->join();
|
timeouter->join();
|
||||||
delete timeouter;
|
delete timeouter;
|
||||||
}
|
}
|
||||||
|
timeoutThreadStarted = false;
|
||||||
timeouter = new tthread::thread(Connector_HTTP::proxyTimeoutThread, 0);
|
timeouter = new tthread::thread(Connector_HTTP::proxyTimeoutThread, 0);
|
||||||
timeoutMutex.unlock();
|
timeoutMutex.unlock();
|
||||||
|
while (!timeoutThreadStarted){Util::sleep(10);}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//lock the mutex for this connection, and handle the request
|
//lock the mutex for this connection, and handle the request
|
||||||
|
|
Loading…
Add table
Reference in a new issue