multi: fix curl_multi_waitfds reporting of fd_count

- Make curl_multi_waitfds consistent with the documentation.

Issue Addressed:

 - The documentation of curl_multi_waitfds indicates that users should
   be able to call curl_multi_waitfds with a NULL ufds. However, before
   this change, the function would return CURLM_BAD_FUNCTION_ARGUMENT.
 - Additionally, the documentation suggests that users can use this
   function to determine the number of file descriptors (fds) needed.
   However, the function would stop counting fds if the supplied fds
   were exhausted.

Changes Made:

 - NULL ufds Handling: curl_multi_waitfds can now accept a NULL ufds if
   size is also zero.
 - Counting File Descriptors: If curl_multi_waitfds is passed a NULL
   ufds, or the size of ufds is insufficient, the output parameter
   fd_count will return the number of fds needed. This value may be
   higher than actually needed but never lower.

Testing:

 - Test 2405 has been updated to cover the usage scenarios described
   above.

Fixes https://github.com/curl/curl/issues/15146
Closes https://github.com/curl/curl/pull/15155
This commit is contained in:
Christopher Dannemiller 2024-10-04 09:31:59 -07:00 committed by Jay Satiro
parent 7d6edf1d8d
commit c78044c07e
7 changed files with 120 additions and 43 deletions

View file

@ -926,10 +926,10 @@ CURLcode Curl_cpool_add_pollfds(struct cpool *cpool,
return result;
}
CURLcode Curl_cpool_add_waitfds(struct cpool *cpool,
struct curl_waitfds *cwfds)
unsigned int Curl_cpool_add_waitfds(struct cpool *cpool,
struct curl_waitfds *cwfds)
{
CURLcode result = CURLE_OK;
unsigned int need = 0;
CPOOL_LOCK(cpool);
if(Curl_llist_head(&cpool->shutdowns)) {
@ -945,14 +945,11 @@ CURLcode Curl_cpool_add_waitfds(struct cpool *cpool,
Curl_conn_adjust_pollset(cpool->idata, &ps);
Curl_detach_connection(cpool->idata);
result = Curl_waitfds_add_ps(cwfds, &ps);
if(result)
goto out;
need += Curl_waitfds_add_ps(cwfds, &ps);
}
}
out:
CPOOL_UNLOCK(cpool);
return result;
return need;
}
static void cpool_perform(struct cpool *cpool)