summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-04-17 21:06:29 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-04-17 21:06:29 +0000
commita4135a992461726e155c7be95e4ceaabdb3eceff (patch)
tree4898d01ab8b4663825e2118e6fa88698c8721473 /protocols
parent14593a20b0269456ed0383c95ac26430ea969077 (diff)
SkypeWeb: added ability to async sending of http requests
git-svn-id: http://svn.miranda-ng.org/main/trunk@12897 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/SkypeWeb/src/http_request.h2
-rw-r--r--protocols/SkypeWeb/src/request_queue.cpp32
-rw-r--r--protocols/SkypeWeb/src/request_queue.h4
-rw-r--r--protocols/SkypeWeb/src/skype_proto.h4
-rw-r--r--protocols/SkypeWeb/src/skype_request.cpp17
5 files changed, 49 insertions, 10 deletions
diff --git a/protocols/SkypeWeb/src/http_request.h b/protocols/SkypeWeb/src/http_request.h
index bc58405fb0..ccc4972db1 100644
--- a/protocols/SkypeWeb/src/http_request.h
+++ b/protocols/SkypeWeb/src/http_request.h
@@ -226,7 +226,7 @@ public:
requestType = type;
}
- HttpRequest(int type, HttpRequestUrlFormat format, LPCSTR urlFormat, ...)
+ HttpRequest(int type, HttpRequestUrlFormat, LPCSTR urlFormat, ...)
: Url(*this, urlFormat, (va_start(formatArgs, urlFormat), formatArgs)), Headers(*this)
{
cbSize = sizeof(NETLIBHTTPREQUEST);
diff --git a/protocols/SkypeWeb/src/request_queue.cpp b/protocols/SkypeWeb/src/request_queue.cpp
index 2a7e384a8f..e932dc363d 100644
--- a/protocols/SkypeWeb/src/request_queue.cpp
+++ b/protocols/SkypeWeb/src/request_queue.cpp
@@ -64,6 +64,12 @@ void RequestQueue::Push(HttpRequest *request, HttpResponseCallback response, voi
SetEvent(hRequestQueueEvent);
}
+void RequestQueue::Send(HttpRequest *request, HttpResponseCallback response, void *arg)
+{
+ RequestQueueItem *item = new RequestQueueItem(request, response, arg);
+ mir_forkthreadowner((pThreadFuncOwner)&RequestQueue::AsyncSendThread, this, item, 0);
+}
+
void RequestQueue::Execute(RequestQueueItem *item)
{
NETLIBHTTPREQUEST *response = item->request->Send(hConnection);
@@ -74,27 +80,37 @@ void RequestQueue::Execute(RequestQueueItem *item)
delete item;
}
-unsigned int RequestQueue::WorkerThread(void* owner, void*)
+unsigned int RequestQueue::AsyncSendThread(void *owner, void *arg)
{
RequestQueue *that = (RequestQueue*)owner;
+ RequestQueueItem *item = (RequestQueueItem*)arg;
+
+ that->Execute(item);
+
+ return 0;
+}
+
+unsigned int RequestQueue::WorkerThread(void *arg)
+{
+ RequestQueue *queue = (RequestQueue*)arg;
- while (!that->isTerminated)
+ while (!queue->isTerminated)
{
- WaitForSingleObject(that->hRequestQueueEvent, INFINITE);
+ WaitForSingleObject(queue->hRequestQueueEvent, INFINITE);
while (true)
{
RequestQueueItem *item = NULL;
{
- mir_cslock lock(that->requestQueueLock);
+ mir_cslock lock(queue->requestQueueLock);
- if (that->requests.getCount() == 0)
+ if (queue->requests.getCount() == 0)
break;
- item = that->requests[0];
- that->requests.remove(0);
+ item = queue->requests[0];
+ queue->requests.remove(0);
}
if (item != NULL)
- that->Execute(item);
+ queue->Execute(item);
}
}
diff --git a/protocols/SkypeWeb/src/request_queue.h b/protocols/SkypeWeb/src/request_queue.h
index ffe4f6fddf..23696f2481 100644
--- a/protocols/SkypeWeb/src/request_queue.h
+++ b/protocols/SkypeWeb/src/request_queue.h
@@ -51,7 +51,8 @@ private:
void Execute(RequestQueueItem *item);
- static unsigned int __cdecl WorkerThread(void*, void*);
+ static unsigned int __cdecl AsyncSendThread(void*, void*);
+ static unsigned int __cdecl WorkerThread(void*);
public:
RequestQueue(HANDLE hConnection);
@@ -61,6 +62,7 @@ public:
void Stop();
void Push(HttpRequest *request, HttpResponseCallback response = NULL, void *arg = NULL);
+ void Send(HttpRequest *request, HttpResponseCallback response = NULL, void *arg = NULL);
};
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h
index 3956db072b..3d9d2ad4b4 100644
--- a/protocols/SkypeWeb/src/skype_proto.h
+++ b/protocols/SkypeWeb/src/skype_proto.h
@@ -113,6 +113,10 @@ private:
void PushRequest(HttpRequest *request, SkypeResponseCallback response);
void PushRequest(HttpRequest *request, SkypeResponseWithArgCallback response, void *arg);
+ void SendRequest(HttpRequest *request);
+ void SendRequest(HttpRequest *request, SkypeResponseCallback response);
+ void SendRequest(HttpRequest *request, SkypeResponseWithArgCallback response, void *arg);
+
// icons
static IconInfo Icons[];
static HANDLE GetIconHandle(const char *name);
diff --git a/protocols/SkypeWeb/src/skype_request.cpp b/protocols/SkypeWeb/src/skype_request.cpp
index 6f911d283e..c688906a5f 100644
--- a/protocols/SkypeWeb/src/skype_request.cpp
+++ b/protocols/SkypeWeb/src/skype_request.cpp
@@ -63,4 +63,21 @@ void CSkypeProto::PushRequest(HttpRequest *request, SkypeResponseWithArgCallback
{
SkypeResponseDelegate *delegate = new SkypeResponseDelegate(this, response, arg);
requestQueue->Push(request, SkypeHttpResponse, delegate);
+}
+
+void CSkypeProto::SendRequest(HttpRequest *request)
+{
+ requestQueue->Send(request, NULL, NULL);
+}
+
+void CSkypeProto::SendRequest(HttpRequest *request, SkypeResponseCallback response)
+{
+ SkypeResponseDelegate *delegate = new SkypeResponseDelegate(this, response);
+ requestQueue->Send(request, SkypeHttpResponse, delegate);
+}
+
+void CSkypeProto::SendRequest(HttpRequest *request, SkypeResponseWithArgCallback response, void *arg)
+{
+ SkypeResponseDelegate *delegate = new SkypeResponseDelegate(this, response, arg);
+ requestQueue->Send(request, SkypeHttpResponse, delegate);
} \ No newline at end of file