diff options
author | Robert Pösel <robyer@seznam.cz> | 2015-03-06 10:23:10 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2015-03-06 10:23:10 +0000 |
commit | 224d0671bfbfccb2883313183a51f86fdf967745 (patch) | |
tree | 5820558020988df3604f4783e1e8541560807fb5 /protocols/Steam/src/steam_queue.cpp | |
parent | 16316a39e4efcf00cb98fd078377a78ee9e267a8 (diff) |
Steam: Rework PushRequests and related methods (more improvements for commit r12325)
To properly free arguments and also requests and QueueItems itself and also do small other fixes
git-svn-id: http://svn.miranda-ng.org/main/trunk@12349 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Steam/src/steam_queue.cpp')
-rw-r--r-- | protocols/Steam/src/steam_queue.cpp | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/protocols/Steam/src/steam_queue.cpp b/protocols/Steam/src/steam_queue.cpp index 54cb2de4fc..ff61da24a7 100644 --- a/protocols/Steam/src/steam_queue.cpp +++ b/protocols/Steam/src/steam_queue.cpp @@ -28,10 +28,13 @@ void CSteamProto::StartQueue() }
else
{
- ptrA username(mir_urlEncode(ptrA(mir_utf8encodeW(getWStringA("Username")))));
+ ptrA username(mir_urlEncode(ptrA(mir_utf8encodeT(getTStringA("Username")))));
if (username == NULL || username[0] == '\0')
return;
- PushRequest(new SteamWebApi::RsaKeyRequest(username), (RESPONSE)&CSteamProto::OnGotRsaKey);
+
+ PushRequest(
+ new SteamWebApi::RsaKeyRequest(username),
+ &CSteamProto::OnGotRsaKey);
}
m_hQueueThread = ForkThreadEx(&CSteamProto::QueueThread, 0, NULL);
@@ -50,9 +53,8 @@ void CSteamProto::StopQueue() QueueItem *item = requestsQueue[0];
requestsQueue.remove(0);
- // We call ExecuteRequest() but as we have set isTerminated=true it will only run callback to behave correctly (free arguments, raise errors, etc.)
- if (item != NULL)
- ExecuteRequest(item);
+ // QueueItem's destructor properly free request and arg
+ delete item;
}
}
@@ -72,29 +74,30 @@ void CSteamProto::StopQueue() void CSteamProto::PushRequest(SteamWebApi::HttpRequest *request)
{
- PushRequest(request, NULL, NULL);
+ PushRequest(request, NULL, NULL, ARG_NO_FREE);
}
void CSteamProto::PushRequest(SteamWebApi::HttpRequest *request, RESPONSE response)
{
- PushRequest(request, response, NULL);
+ PushRequest(request, response, NULL, ARG_NO_FREE);
}
-void CSteamProto::PushRequest(SteamWebApi::HttpRequest *request, RESPONSE response, void *arg)
+void CSteamProto::PushRequest(SteamWebApi::HttpRequest *request, RESPONSE response, void *arg, ARG_FREE_TYPE arg_free_type)
{
+ // Always prepare QueueItem so we can use it's destructor to free request and arg
+ QueueItem *item = new QueueItem(request, response);
+ item->arg = arg;
+ item->arg_free_type = arg_free_type;
+
if (isTerminated)
{
- // Call response callback so it can react properly (free arguments, raise errors, etc.)
- if (response != NULL)
- (this->*(response))(NULL, arg);
-
+ // QueueItem's destructor properly free request and arg
+ delete item;
return;
}
{
mir_cslock lock(requests_queue_lock);
- QueueItem *item = new QueueItem(request, response);
- item->arg = arg;
requestsQueue.insert(item);
}
@@ -105,10 +108,8 @@ void CSteamProto::ExecuteRequest(QueueItem *item) {
if (isTerminated)
{
- // Call response callback so it can react properly (free arguments, raise errors, etc.)
- if (item->responseCallback != NULL)
- (this->*(item->responseCallback))(NULL, item->arg);
-
+ // QueueItem's destructor properly free request and arg
+ delete item;
return;
}
|