diff options
author | Marcello Stanisci <stanisci.m@gmail.com> | 2018-09-20 15:22:33 +0200 |
---|---|---|
committer | Marcello Stanisci <stanisci.m@gmail.com> | 2018-09-20 15:22:33 +0200 |
commit | 2f69f626b0e47a7affa206038c217cc0bb09e49c (patch) | |
tree | eb8e1869ffaf3c90f5172f22c5981d02907f9cb7 | |
parent | 3af28f777be32de53c85044c41f285332791005d (diff) | |
download | twister-2f69f626b0e47a7affa206038c217cc0bb09e49c.tar.gz twister-2f69f626b0e47a7affa206038c217cc0bb09e49c.tar.bz2 twister-2f69f626b0e47a7affa206038c217cc0bb09e49c.zip |
3557.
Unpausing the download callback as soon as a Connection: close
header is received.
-rw-r--r-- | src/twister/taler-twister-service.c | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/src/twister/taler-twister-service.c b/src/twister/taler-twister-service.c index 6fde9a3..d12bc67 100644 --- a/src/twister/taler-twister-service.c +++ b/src/twister/taler-twister-service.c @@ -41,6 +41,12 @@ #include <taler/taler_util.h> +/** + * We allow X runs of the progress callback before + * declaring the upload callback dead. + */ +#define DOWNLOAD_PAUSED_TIMES_MAX 10 + /** * Log curl error. * @@ -118,12 +124,12 @@ struct HttpRequest /** * Client socket read task */ - struct GNUNET_SCHEDULER_Task * rtask; + struct GNUNET_SCHEDULER_Task *rtask; /** * Client socket write task */ - struct GNUNET_SCHEDULER_Task * wtask; + struct GNUNET_SCHEDULER_Task *wtask; /** * Buffer we use for moving data between MHD and @@ -190,6 +196,17 @@ struct HttpRequest * Request processing state machine. */ enum RequestState state; + + /** + * Indicates that the download callback is sleeping. + */ + int download_paused; + + /** + * Indicates that the Web server returned a "Connection: close" + * header line. + */ + int connection_closed; }; @@ -334,6 +351,9 @@ curl_check_hdr (void *buffer, char *hdr_val; char *tok; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Checking headers..\n"); + ndup = GNUNET_strndup (buffer, bytes); hdr_type = strtok (ndup, ":"); if (NULL == hdr_type) @@ -375,6 +395,18 @@ curl_check_hdr (void *buffer, *tok = '\0'; if (NULL != (tok = strchr (hdr_val, '\t'))) *tok = '\0'; + + if (0 == strcasecmp (hdr_type, + MHD_HTTP_HEADER_CONNECTION) + && (0 == strcasecmp (hdr_val, + "close"))) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Server wants to close the TCP connection\n"); + hr->connection_closed = GNUNET_YES; + } + + if (0 != strlen (hdr_val)) /* Rely in MHD to set those */ { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -458,7 +490,12 @@ curl_download_cb (void *ptr, "Curl download proceeding\n"); if (REQUEST_STATE_DOWNLOAD_STARTED != hr->state) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Download callback goes to sleep\n"); + hr->download_paused = GNUNET_YES; return CURL_WRITEFUNC_PAUSE; + } GNUNET_assert (REQUEST_STATE_DOWNLOAD_STARTED == hr->state); @@ -735,8 +772,22 @@ curl_progress_cb (void *clientp, double ultotal, double ulnow) { + struct HttpRequest *hr = clientp; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "I'm the progress callback\n"); + "Progress callback..\n"); + + if ((GNUNET_YES == hr->download_paused) + && (GNUNET_YES == hr->connection_closed)) + { + hr->state = REQUEST_STATE_DOWNLOAD_STARTED; + hr->download_paused = GNUNET_NO; + hr->connection_closed = GNUNET_NO; + curl_easy_pause (hr->curl, CURLPAUSE_CONT); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Unpausing the download callback\n"); + } + return CURLE_OK; } |