summaryrefslogtreecommitdiff
path: root/protocols/Steam/src/steam_request.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Steam/src/steam_request.cpp')
-rw-r--r--protocols/Steam/src/steam_request.cpp107
1 files changed, 56 insertions, 51 deletions
diff --git a/protocols/Steam/src/steam_request.cpp b/protocols/Steam/src/steam_request.cpp
index 363f31a328..51b09ecfc3 100644
--- a/protocols/Steam/src/steam_request.cpp
+++ b/protocols/Steam/src/steam_request.cpp
@@ -1,11 +1,10 @@
#include "stdafx.h"
-HttpResponse* CSteamProto::SendRequest(HttpRequest *request)
+void CSteamProto::SendRequest(HttpRequest *request)
{
NETLIBHTTPREQUEST *pResp = Netlib_HttpTransaction(m_hNetlibUser, (NETLIBHTTPREQUEST*)request);
- HttpResponse *response = new HttpResponse(request, pResp);
+ HttpResponse response(request, pResp);
delete request;
- return response;
}
void CSteamProto::SendRequest(HttpRequest *request, HttpCallback callback, void *param)
@@ -21,8 +20,7 @@ void CSteamProto::SendRequest(HttpRequest *request, JsonCallback callback, void
{
NETLIBHTTPREQUEST *pResp = Netlib_HttpTransaction(m_hNetlibUser, (NETLIBHTTPREQUEST*)request);
HttpResponse response(request, pResp);
- if (callback)
- {
+ if (callback) {
JSONNode root = JSONNode::parse(response.Content);
(this->*callback)(root, param);
}
@@ -31,68 +29,75 @@ void CSteamProto::SendRequest(HttpRequest *request, JsonCallback callback, void
void CSteamProto::PushRequest(HttpRequest *request)
{
- RequestQueueItem *item = new RequestQueueItem();
- item->request = request;
- {
- mir_cslock lock(requestQueueLock);
- requestQueue.insert(item);
- }
- SetEvent(m_hRequestsQueueEvent);
+ RequestQueueItem *item = new RequestQueueItem(request);
+ PushToRequestQueue(item);
}
void CSteamProto::PushRequest(HttpRequest *request, HttpCallback callback, void *param)
{
- RequestQueueItem *item = new RequestQueueItem();
- item->request = request;
- item->httpCallback = callback;
- item->param = param;
- {
- mir_cslock lock(requestQueueLock);
- requestQueue.insert(item);
- }
- SetEvent(m_hRequestsQueueEvent);
+ RequestQueueItem *item = new RequestQueueItem(request, callback, param);
+ PushToRequestQueue(item);
}
void CSteamProto::PushRequest(HttpRequest *request, JsonCallback callback, void *param)
{
- RequestQueueItem *item = new RequestQueueItem();
- item->request = request;
- item->jsonCallback = callback;
- item->param = param;
+ RequestQueueItem *item = new RequestQueueItem(request, callback, param);
+ PushToRequestQueue(item);
+}
+
+/////////////////////////////////////////////////////////////////////////////////
+
+void CSteamProto::PushToRequestQueue(RequestQueueItem *item)
+{
+ if (m_isTerminated)
+ return;
{
- mir_cslock lock(requestQueueLock);
- requestQueue.insert(item);
+ mir_cslock lock(m_requestQueueLock);
+ m_requestQueue.insert(item);
}
SetEvent(m_hRequestsQueueEvent);
}
-void CSteamProto::RequestQueueThread(void*)
+RequestQueueItem *CSteamProto::PopFromRequestQueue()
{
- Login();
+ mir_cslock lock(m_requestQueueLock);
+ if (!m_requestQueue.getCount())
+ return nullptr;
- do
- {
- RequestQueueItem *item;
- while (true)
- {
- {
- mir_cslock lock(requestQueueLock);
- if (!requestQueue.getCount())
- break;
+ RequestQueueItem *item = m_requestQueue[0];
+ m_requestQueue.remove(0);
+ return item;
+}
- item = requestQueue[0];
- requestQueue.remove(0);
- }
- if (item->httpCallback)
- SendRequest(item->request, item->httpCallback, item->param);
- else if (item->jsonCallback)
- SendRequest(item->request, item->jsonCallback, item->param);
- else
- SendRequest(item->request);
- delete item;
- }
+void CSteamProto::ProcessRequestQueue()
+{
+ while (true) {
+ RequestQueueItem *item = PopFromRequestQueue();
+ if (item == nullptr)
+ break;
+ if (item->httpCallback)
+ SendRequest(item->request, item->httpCallback, item->param);
+ else if (item->jsonCallback)
+ SendRequest(item->request, item->jsonCallback, item->param);
+ else
+ SendRequest(item->request);
+ delete item;
+ }
+}
+
+void CSteamProto::RequestQueueThread(void*)
+{
+ do {
+ ProcessRequestQueue();
WaitForSingleObject(m_hRequestsQueueEvent, 1000);
- } while (!isTerminated);
+ } while (!m_isTerminated);
+ {
+ mir_cslock lock(m_requestQueueLock);
+ for (int i = 0; i < m_requestQueue.getCount(); i++) {
+ delete m_requestQueue[i];
+ m_requestQueue.remove(i);
+ }
+ }
+ m_hRequestQueueThread = nullptr;
- m_hRequestQueueThread = NULL;
} \ No newline at end of file