From 52b81295954fc2fbb705beed84ea8131155f3805 Mon Sep 17 00:00:00 2001 From: Pierrick Charron Date: Sun, 9 Sep 2018 11:53:47 -0400 Subject: [PATCH 1/3] Fix 76480: Use curl_multi_wait() so that timeouts are respected --- ext/curl/multi.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ext/curl/multi.c b/ext/curl/multi.c index dd1c436bdd12..be3e40ed3d8c 100644 --- a/ext/curl/multi.c +++ b/ext/curl/multi.c @@ -206,12 +206,16 @@ PHP_FUNCTION(curl_multi_select) { zval *z_mh; php_curlm *mh; + double timeout = 1.0; +#if LIBCURL_VERSION_NUM >= 0x071c00 /* Available since 7.28.0 */ + int numfds = 0; +#else fd_set readfds; fd_set writefds; fd_set exceptfds; int maxfd; - double timeout = 1.0; struct timeval to; +#endif CURLMcode error = CURLM_OK; if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|d", &z_mh, &timeout) == FAILURE) { @@ -222,6 +226,15 @@ PHP_FUNCTION(curl_multi_select) RETURN_FALSE; } +#if LIBCURL_VERSION_NUM >= 0x071c00 /* Available since 7.28.0 */ + error = curl_multi_wait(mh->multi, NULL, 0, (unsigned long) timeout * 1000.0, &numfds); + if (CURLM_OK != error) { + SAVE_CURLM_ERROR(mh, error); + RETURN_LONG(-1); + } + + RETURN_LONG(numfds); +#else _make_timeval_struct(&to, timeout); FD_ZERO(&readfds); @@ -235,6 +248,7 @@ PHP_FUNCTION(curl_multi_select) RETURN_LONG(-1); } RETURN_LONG(select(maxfd + 1, &readfds, &writefds, &exceptfds, &to)); +#endif } /* }}} */ From 10ddc20fbcf7aa054dcffde87126a5ae15fbc160 Mon Sep 17 00:00:00 2001 From: Pierrick Charron Date: Sun, 9 Sep 2018 13:32:33 -0400 Subject: [PATCH 2/3] _make_timeval_struct is not used anymore in curl_multi_select --- ext/curl/multi.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ext/curl/multi.c b/ext/curl/multi.c index be3e40ed3d8c..93f8884b67e1 100644 --- a/ext/curl/multi.c +++ b/ext/curl/multi.c @@ -190,6 +190,7 @@ PHP_FUNCTION(curl_multi_remove_handle) } /* }}} */ +#if LIBCURL_VERSION_NUM < 0x071c00 /* Available since 7.28.0 */ static void _make_timeval_struct(struct timeval *to, double timeout) /* {{{ */ { unsigned long conv; @@ -199,6 +200,7 @@ static void _make_timeval_struct(struct timeval *to, double timeout) /* {{{ */ to->tv_usec = conv % 1000000; } /* }}} */ +#endif /* {{{ proto int curl_multi_select(resource mh[, double timeout]) Get all the sockets associated with the cURL extension, which can then be "selected" */ From c9ccd0aefe34bcf08592e37914f20cc97fbef263 Mon Sep 17 00:00:00 2001 From: Pierrick Charron Date: Sun, 9 Sep 2018 13:33:56 -0400 Subject: [PATCH 3/3] Remove useless comment --- ext/curl/multi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/curl/multi.c b/ext/curl/multi.c index 93f8884b67e1..7a41b22ea2ba 100644 --- a/ext/curl/multi.c +++ b/ext/curl/multi.c @@ -190,7 +190,7 @@ PHP_FUNCTION(curl_multi_remove_handle) } /* }}} */ -#if LIBCURL_VERSION_NUM < 0x071c00 /* Available since 7.28.0 */ +#if LIBCURL_VERSION_NUM < 0x071c00 static void _make_timeval_struct(struct timeval *to, double timeout) /* {{{ */ { unsigned long conv;