tPut curl global info in CurlConnection - vaccinewars - be a doctor and try to … | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 99345e2ca196e3a190dc0d404a45bba4650ed33e | |
parent 7eb8e03609503bebc2e8364c8a69d975ea92d8e1 | |
Author: Ben Webb <[email protected]> | |
Date: Thu, 5 Nov 2020 22:50:34 -0800 | |
Put curl global info in CurlConnection | |
Get rid of the CurlGlobalData struct. We already | |
have CurlConnection in the same scope, so use that | |
tto keep track of these data. | |
Diffstat: | |
M src/gui_client/newgamedia.c | 16 ++++++++-------- | |
M src/network.c | 36 +++++++++++------------------… | |
M src/network.h | 17 ++++++----------- | |
3 files changed, 27 insertions(+), 42 deletions(-) | |
--- | |
diff --git a/src/gui_client/newgamedia.c b/src/gui_client/newgamedia.c | |
t@@ -83,23 +83,22 @@ static void SetStartGameStatus(gchar *msg) | |
#ifdef NETWORKING | |
-CurlGlobalData global_data; | |
- | |
/* Called by glib when we get action on a multi socket */ | |
static gboolean glib_socket(GIOChannel *ch, GIOCondition condition, | |
gpointer data) | |
{ | |
- CurlGlobalData *g = (CurlGlobalData*) data; | |
+ CurlConnection *g = (CurlConnection*) data; | |
CURLMcode rc; | |
+ int still_running; | |
int fd = g_io_channel_unix_get_fd(ch); | |
fprintf(stderr, "bw> glib socket\n"); | |
int action = | |
((condition & G_IO_IN) ? CURL_CSELECT_IN : 0) | | |
((condition & G_IO_OUT) ? CURL_CSELECT_OUT : 0); | |
- rc = curl_multi_socket_action(g->multi, fd, action, &g->still_running); | |
+ rc = curl_multi_socket_action(g->multi, fd, action, &still_running); | |
if (rc != CURLM_OK) fprintf(stderr, "action %d %s\n", rc, curl_multi_strerro… | |
- if (g->still_running) { | |
+ if (still_running) { | |
return TRUE; | |
} else { | |
GError *tmp_error = NULL; | |
t@@ -127,10 +126,11 @@ static gboolean glib_socket(GIOChannel *ch, GIOCondition… | |
static gboolean glib_timeout(gpointer userp) | |
{ | |
- CurlGlobalData *g = userp; | |
+ CurlConnection *g = userp; | |
+ int still_running; | |
CURLMcode rc; | |
fprintf(stderr, "bw> glib_timeout\n"); | |
- rc = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0, &g->still_ru… | |
+ rc = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0, &still_runni… | |
if (rc != CURLM_OK) fprintf(stderr, "action %d %s\n", rc, curl_multi_strerro… | |
g->timer_event = 0; | |
return G_SOURCE_REMOVE; | |
t@@ -434,7 +434,7 @@ void NewGameDialog(Player *play) | |
GtkWidget *clist, *scrollwin, *table, *hbbox; | |
gchar *server_titles[5], *ServerEntry, *text; | |
gboolean UpdateMeta = FALSE; | |
- SetCurlCallback(MetaConn, &global_data, glib_timeout, glib_socket); | |
+ SetCurlCallback(MetaConn, glib_timeout, glib_socket); | |
/* Column titles of metaserver information */ | |
server_titles[0] = _("Server"); | |
diff --git a/src/network.c b/src/network.c | |
t@@ -1372,18 +1372,13 @@ char *CurlNextLine(CurlConnection *conn, char *ch) | |
/* Information associated with a specific socket */ | |
typedef struct _SockData { | |
- curl_socket_t sockfd; | |
- CURL *easy; | |
- int action; | |
- long timeout; | |
GIOChannel *ch; | |
guint ev; | |
- CurlGlobalData *global; | |
} SockData; | |
static int timer_function(CURLM *multi, long timeout_ms, void *userp) | |
{ | |
- CurlGlobalData *g = userp; | |
+ CurlConnection *g = userp; | |
if (g->timer_event) { | |
g_source_remove(g->timer_event); | |
t@@ -1411,15 +1406,12 @@ static void remsock(SockData *f) | |
/* Assign information to a SockData structure */ | |
static void setsock(SockData *f, curl_socket_t s, CURL *e, int act, | |
- CurlGlobalData *g) | |
+ CurlConnection *g) | |
{ | |
GIOCondition kind = | |
((act & CURL_POLL_IN) ? G_IO_IN : 0) | | |
((act & CURL_POLL_OUT) ? G_IO_OUT : 0); | |
- f->sockfd = s; | |
- f->action = act; | |
- f->easy = e; | |
if (f->ev) { | |
g_source_remove(f->ev); | |
} | |
t@@ -1427,11 +1419,10 @@ static void setsock(SockData *f, curl_socket_t s, CURL… | |
} | |
/* Initialize a new SockData structure */ | |
-static void addsock(curl_socket_t s, CURL *easy, int action, CurlGlobalData *g) | |
+static void addsock(curl_socket_t s, CURL *easy, int action, CurlConnection *g) | |
{ | |
SockData *fdp = g_malloc0(sizeof(SockData)); | |
- fdp->global = g; | |
fdp->ch = g_io_channel_unix_new(s); | |
setsock(fdp, s, easy, action, g); | |
curl_multi_assign(g->multi, s, fdp); | |
t@@ -1440,7 +1431,7 @@ static void addsock(curl_socket_t s, CURL *easy, int act… | |
static int socket_function(CURL *easy, curl_socket_t s, int what, void *userp, | |
void *socketp) | |
{ | |
- CurlGlobalData *g = userp; | |
+ CurlConnection *g = userp; | |
SockData *fdp = socketp; | |
if (what == CURL_POLL_REMOVE) { | |
remsock(fdp); | |
t@@ -1452,18 +1443,17 @@ static int socket_function(CURL *easy, curl_socket_t s… | |
return 0; | |
} | |
-void SetCurlCallback(CurlConnection *conn, CurlGlobalData *g, | |
- GSourceFunc timer_cb, GIOFunc socket_cb) | |
+void SetCurlCallback(CurlConnection *conn, GSourceFunc timer_cb, | |
+ GIOFunc socket_cb) | |
{ | |
- g->multi = conn->multi; | |
- g->timer_event = 0; | |
- g->timer_cb = timer_cb; | |
- g->socket_cb = socket_cb; | |
+ conn->timer_event = 0; | |
+ conn->timer_cb = timer_cb; | |
+ conn->socket_cb = socket_cb; | |
- curl_multi_setopt(g->multi, CURLMOPT_TIMERFUNCTION, timer_function); | |
- curl_multi_setopt(g->multi, CURLMOPT_TIMERDATA, g); | |
- curl_multi_setopt(g->multi, CURLMOPT_SOCKETFUNCTION, socket_function); | |
- curl_multi_setopt(g->multi, CURLMOPT_SOCKETDATA, g); | |
+ curl_multi_setopt(conn->multi, CURLMOPT_TIMERFUNCTION, timer_function); | |
+ curl_multi_setopt(conn->multi, CURLMOPT_TIMERDATA, conn); | |
+ curl_multi_setopt(conn->multi, CURLMOPT_SOCKETFUNCTION, socket_function); | |
+ curl_multi_setopt(conn->multi, CURLMOPT_SOCKETDATA, conn); | |
} | |
gboolean OpenHttpConnection(HttpConnection **connpt, gchar *HostName, | |
diff --git a/src/network.h b/src/network.h | |
t@@ -71,6 +71,10 @@ typedef struct _CurlConnection { | |
char StripChar; /* Char that should be removed | |
* from messages */ | |
GPtrArray *headers; | |
+ | |
+ guint timer_event; | |
+ GSourceFunc timer_cb; | |
+ GIOFunc socket_cb; | |
} CurlConnection; | |
typedef struct _ConnBuf { | |
t@@ -232,15 +236,6 @@ GQuark dope_curl_error_quark(void); | |
#define DOPE_CURLM_ERROR dope_curlm_error_quark() | |
GQuark dope_curlm_error_quark(void); | |
-/* Global information, common to all connections */ | |
-typedef struct _CurlGlobalData { | |
- CURLM *multi; | |
- guint timer_event; | |
- int still_running; | |
- GSourceFunc timer_cb; | |
- GIOFunc socket_cb; | |
-} CurlGlobalData; | |
- | |
void CurlInit(CurlConnection *conn); | |
void CurlCleanup(CurlConnection *conn); | |
gboolean OpenCurlConnection(CurlConnection *conn, char *URL, char *body, | |
t@@ -249,8 +244,8 @@ void CloseCurlConnection(CurlConnection *conn); | |
gboolean CurlConnectionPerform(CurlConnection *conn, int *still_running, | |
GError **err); | |
char *CurlNextLine(CurlConnection *conn, char *ch); | |
-void SetCurlCallback(CurlConnection *conn, CurlGlobalData *g, | |
- GSourceFunc timer_cb, GIOFunc socket_cb); | |
+void SetCurlCallback(CurlConnection *conn, GSourceFunc timer_cb, | |
+ GIOFunc socket_cb); | |
gboolean OpenHttpConnection(HttpConnection **conn, gchar *HostName, | |
unsigned Port, gchar *Proxy, |