X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/70f8adff2c970496bdc45717cad49ddec0405ae7..3a9bc658f505e423b3be181948f1870a09915ea9:/projects/rlm_stg/iface.cpp diff --git a/projects/rlm_stg/iface.cpp b/projects/rlm_stg/iface.cpp index 485e9ef7..caa44386 100644 --- a/projects/rlm_stg/iface.cpp +++ b/projects/rlm_stg/iface.cpp @@ -9,6 +9,25 @@ namespace { +struct Response +{ + bool done; + pthread_mutex_t mutex; + pthread_cond_t cond; + RESULT result; + + static bool callback(void* data, const RESULT& res) + { + Response& resp = *static_cast(data); + pthread_mutex_lock(&resp.mutex); + resp.result = res; + resp.done = true; + pthread_cond_signal(&resp.cond); + pthread_mutex_unlock(&resp.mutex); + return true; + } +} response; + STG_PAIR* toSTGPairs(const PAIRS& source) { STG_PAIR * pairs = new STG_PAIR[source.size() + 1]; @@ -68,7 +87,12 @@ STG_RESULT stgRequest(STG_CLIENT::TYPE type, const char* userName, const char* p return emptyResult(); } try { - return toResult(client->request(type, toString(userName), toString(password), fromSTGPairs(pairs))); + client->request(type, toString(userName), toString(password), fromSTGPairs(pairs)); + pthread_mutex_lock(&response.mutex); + while (!response.done) + pthread_cond_wait(&response.cond, &response.mutex); + pthread_mutex_unlock(&response.mutex); + return toResult(response.result); } catch (const STG_CLIENT::Error& ex) { // TODO: log error return emptyResult(); @@ -79,7 +103,11 @@ STG_RESULT stgRequest(STG_CLIENT::TYPE type, const char* userName, const char* p int stgInstantiateImpl(const char* address) { - if (STG_CLIENT::configure(toString(address))) + pthread_mutex_init(&response.mutex, NULL); + pthread_cond_init(&response.cond, NULL); + response.done = false; + + if (STG_CLIENT::configure(toString(address), &Response::callback, &response)) return 1; return 0;