aboutsummaryrefslogtreecommitdiff
path: root/lib/multi.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2015-10-05 20:39:10 +0200
committerDaniel Stenberg <daniel@haxx.se>2015-10-15 23:32:19 +0200
commitc6aedf680f6923ffbe4dd4fd4e68e7dadcd5fb19 (patch)
tree4f681e394e33c436ea94fd40db2ec126afdc0977 /lib/multi.c
parent854976ad7b049e3a758d3d0ec33d5c998e36e5af (diff)
fread_func: move callback pointer from set to state struct
... and assign it from the set.fread_func_set pointer in the Curl_init_CONNECT function. This A) avoids that we have code that assigns fields in the 'set' struct (which we always knew was bad) and more importantly B) it makes it impossibly to accidentally leave the wrong value for when the handle is re-used etc. Introducing a state-init functionality in multi.c, so that we can set a specific function to get called when we enter a state. The Curl_init_CONNECT is thus called when switching to the CONNECT state. Bug: https://github.com/bagder/curl/issues/346 Closes #346
Diffstat (limited to 'lib/multi.c')
-rw-r--r--lib/multi.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/multi.c b/lib/multi.c
index 00520873c..12e84b9e5 100644
--- a/lib/multi.c
+++ b/lib/multi.c
@@ -99,6 +99,9 @@ static const char * const statename[]={
static void multi_freetimeout(void *a, void *b);
+/* function pointer called once when switching TO a state */
+typedef void (*init_multistate_func)(struct SessionHandle *data);
+
/* always use this function to change state, to make debugging easier */
static void mstate(struct SessionHandle *data, CURLMstate state
#ifdef DEBUGBUILD
@@ -107,6 +110,12 @@ static void mstate(struct SessionHandle *data, CURLMstate state
)
{
CURLMstate oldstate = data->mstate;
+ static const init_multistate_func finit[CURLM_STATE_LAST-1] = {
+ NULL,
+ NULL,
+ Curl_init_CONNECT, /* CONNECT */
+ /* the rest is NULL too */
+ };
#if defined(DEBUGBUILD) && defined(CURL_DISABLE_VERBOSE_STRINGS)
(void) lineno;
@@ -136,6 +145,10 @@ static void mstate(struct SessionHandle *data, CURLMstate state
if(state == CURLM_STATE_COMPLETED)
/* changing to COMPLETED means there's one less easy handle 'alive' */
data->multi->num_alive--;
+
+ /* if this state has an init-function, run it */
+ if(finit[state])
+ finit[state](data);
}
#ifndef DEBUGBUILD