summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2014-06-19 08:23:17 -0700
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2014-06-19 08:23:17 -0700
commit6850a909557b488c624a50324d1b806d8d013380 (patch)
tree7f031f4d1d46078c0ea7d880f2ad5cb049e5ad2d /src
parent83120f42019feb5ff4947e9bfb22650a2339d583 (diff)
More work on integrating cURL in Balau.
Diffstat (limited to 'src')
-rw-r--r--src/CurlTask.cc4
-rw-r--r--src/TaskMan.cc35
2 files changed, 30 insertions, 9 deletions
diff --git a/src/CurlTask.cc b/src/CurlTask.cc
index 3dce322..5ff8b97 100644
--- a/src/CurlTask.cc
+++ b/src/CurlTask.cc
@@ -25,3 +25,7 @@ int Balau::CurlTask::debugFunctionStatic(CURL * easy, curl_infotype info, char *
IAssert(easy == curlTask->m_curlHandle, "Got a debug callback for a handle that isn't our own.");
return curlTask->debugFunction(info, str, str_len);
}
+
+void Balau::CurlTask::curlDone(CURLcode result) {
+
+}
diff --git a/src/TaskMan.cc b/src/TaskMan.cc
index 5f028ae..00ce0f2 100644
--- a/src/TaskMan.cc
+++ b/src/TaskMan.cc
@@ -14,7 +14,7 @@
#include <curl/curl.h>
static Balau::AsyncManager s_async;
-static CURLSH * s_curlshared = NULL;
+static CURLSH * s_curlShared = NULL;
namespace {
@@ -73,16 +73,17 @@ class CurlSharedManager : public Balau::AtStart, Balau::AtExit {
void doStart() {
curl_global_init(CURL_GLOBAL_ALL);
static SharedLocks locks;
- s_curlshared = curl_share_init();
- curl_share_setopt(s_curlshared, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
- curl_share_setopt(s_curlshared, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
- curl_share_setopt(s_curlshared, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
- curl_share_setopt(s_curlshared, CURLSHOPT_USERDATA, &locks);
- curl_share_setopt(s_curlshared, CURLSHOPT_LOCKFUNC, lock_function);
- curl_share_setopt(s_curlshared, CURLSHOPT_UNLOCKFUNC, lock_function);
+ s_curlShared = curl_share_init();
+ curl_share_setopt(s_curlShared, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
+ curl_share_setopt(s_curlShared, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
+ curl_share_setopt(s_curlShared, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
+ curl_share_setopt(s_curlShared, CURLSHOPT_USERDATA, &locks);
+ curl_share_setopt(s_curlShared, CURLSHOPT_LOCKFUNC, lock_function);
+ curl_share_setopt(s_curlShared, CURLSHOPT_UNLOCKFUNC, lock_function);
}
void doExit() {
- curl_share_cleanup(s_curlshared);
+ curl_share_cleanup(s_curlShared);
+ curl_global_cleanup();
}
};
@@ -478,6 +479,8 @@ int Balau::TaskMan::mainLoop() {
CurlTask * curlTask = dynamic_cast<CurlTask *>(t);
if (curlTask) {
curlGotHandle = true;
+ curl_easy_setopt(curlTask->m_curlHandle, CURLOPT_SHARE, s_curlShared);
+ curl_easy_setopt(curlTask->m_curlHandle, CURLOPT_PRIVATE, curlTask);
curl_multi_add_handle(m_curlMulti, curlTask->m_curlHandle);
}
}
@@ -485,6 +488,20 @@ int Balau::TaskMan::mainLoop() {
if (curlGotHandle || curlNeedsSpin)
curl_multi_socket_all(m_curlMulti, &m_curlStillRunning);
+ CURLMsg * curlMsg = NULL;
+ int curlMsgInQueue;
+
+ while ((curlMsg = curl_multi_info_read(m_curlMulti, &curlMsgInQueue))) {
+ if (curlMsg->msg != CURLMSG_DONE)
+ continue;
+ Task * maybeCurlTask = NULL;
+ curl_easy_getinfo(curlMsg->easy_handle, CURLINFO_PRIVATE, &maybeCurlTask);
+ IAssert(maybeCurlTask, "curl easy handle didn't have any private data...");
+ CurlTask * curlTask = dynamic_cast<CurlTask *>(maybeCurlTask);
+ IAssert(curlTask, "curl easy handle had corrupted private data...");
+ curlTask->curlDone(curlMsg->data.result);
+ }
+
// Finally, let's destroy tasks that no longer are necessary.
bool didDelete;
do {