Skip to content

Fix 76480: Use curl_multi_wait() so that timeouts are respected #3509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion ext/curl/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ PHP_FUNCTION(curl_multi_remove_handle)
}
/* }}} */

#if LIBCURL_VERSION_NUM < 0x071c00
static void _make_timeval_struct(struct timeval *to, double timeout) /* {{{ */
{
unsigned long conv;
Expand All @@ -199,19 +200,24 @@ 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" */
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) {
Expand All @@ -222,6 +228,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);
Expand All @@ -235,6 +250,7 @@ PHP_FUNCTION(curl_multi_select)
RETURN_LONG(-1);
}
RETURN_LONG(select(maxfd + 1, &readfds, &writefds, &exceptfds, &to));
#endif
}
/* }}} */

Expand Down