diff --git a/network.c b/network.c index 5405e91..91c2c0f 100644 --- a/network.c +++ b/network.c @@ -11,6 +11,8 @@ #define HTTP_PARTIAL_CONTENT 206 LinkTable *ROOT_LINK_TBL; +CURLM *curl_multi; +CURLMsg *curl_msg; /* ------------------------ Static variable ------------------------------ */ /** \brief curl shared interface - not actually being used. */ @@ -33,7 +35,6 @@ static Link *path_to_Link_recursive(char *path, LinkTable *linktbl); static char *url_append(const char *url, const char *sublink); static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp); - static void do_transfer(CURL *curl); /** @@ -66,9 +67,11 @@ static void pthread_unlock_cb(CURL *handle, curl_lock_data data, void network_init(const char *url) { + /* Global related */ curl_global_init(CURL_GLOBAL_ALL); ROOT_LINK_TBL = LinkTable_new(url); + /* Share related */ curl_share = curl_share_init(); curl_share_setopt(curl_share, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE); curl_share_setopt(curl_share, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS); @@ -77,6 +80,11 @@ void network_init(const char *url) pthread_mutex_init(&pthread_curl_lock, NULL); curl_share_setopt(curl_share, CURLSHOPT_LOCKFUNC, pthread_lock_cb); curl_share_setopt(curl_share, CURLSHOPT_UNLOCKFUNC, pthread_unlock_cb); + + /* Multi related */ + curl_multi = curl_multi_init(); + curl_multi_setopt(curl_multi, CURLMOPT_MAXCONNECTS, + CURL_MULTI_MAX_CONNECTION); } static CURL *Link_to_curl(Link *link) diff --git a/network.h b/network.h index cb85a7d..69ad95f 100644 --- a/network.h +++ b/network.h @@ -8,6 +8,7 @@ #define URL_LEN_MAX 2048 #define LINK_LEN_MAX 255 +#define CURL_MULTI_MAX_CONNECTION 10 /** \brief the link type */ typedef enum { @@ -43,6 +44,12 @@ struct LinkTable { /** \brief root link table */ extern LinkTable *ROOT_LINK_TBL; +/** \brief curl multi interface handle */ +extern CURLM *curl_multi; + +/** \brief curl message struct */ +extern CURLMsg *curl_msg; + /** \brief Initialise the network module */ void network_init(const char *url); diff --git a/network_multi.c b/network_multi.c new file mode 100644 index 0000000..95c848e --- /dev/null +++ b/network_multi.c @@ -0,0 +1 @@ +#include "network_multi.h" diff --git a/network_multi.h b/network_multi.h new file mode 100644 index 0000000..69b27cd --- /dev/null +++ b/network_multi.h @@ -0,0 +1,6 @@ +#ifdef NETWORK_MULTI_H +#define NETWORK_MULTI_H + +#include "network.h" + +#endif