]> git.stg.codes - stg.git/commitdiff
Limited waiting for response.
authorMaxim Mamontov <faust.madf@gmail.com>
Sun, 6 Sep 2015 10:26:49 +0000 (13:26 +0300)
committerMaxim Mamontov <faust.madf@gmail.com>
Sun, 6 Sep 2015 10:26:49 +0000 (13:26 +0300)
projects/rlm_stg/iface.cpp

index 7394e288bd9be3f79cd5d2d6be563a3a708ec8d2..d99dd393f8037aeadd9482befb4d9d7d5bd5e65c 100644 (file)
@@ -98,10 +98,14 @@ STG_RESULT stgRequest(STG_CLIENT::TYPE type, const char* userName, const char* p
         response.done = false;
         client->request(type, toString(userName), toString(password), fromSTGPairs(pairs));
         pthread_mutex_lock(&response.mutex);
-        while (!response.done)
-            pthread_cond_wait(&response.cond, &response.mutex);
+        timespec ts;
+        clock_gettime(CLOCK_REALTIME, &ts);
+        ts.tv_sec += 5;
+        int res = 0;
+        while (!response.done && res == 0)
+            res = pthread_cond_timedwait(&response.cond, &response.mutex, &ts);
         pthread_mutex_unlock(&response.mutex);
-        if (!response.status)
+        if (res != 0 || !response.status)
             return emptyResult();
         return toResult(response.result);
     } catch (const STG_CLIENT::Error& ex) {