gnurl_multi_fdset(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

πŸ’… gnurl_multi_fdset(3) β€” the libgnurl manual, but make it make sense

okay so bestie, you're in the libgnurl manual and today's main character is gnurl_multi_fdset(3). buckle up πŸŽ€


✨ NAME ✨

curl_multi_fdset β€” extracts file descriptor information from a multi handle. yes, the page is called gnurl but the function is curl, that's just how it is, iykyk πŸ¦‹


🌸 SYNOPSIS 🌸

#include <gnurl/curl.h>

CURLMcode curl_multi_fdset(CURLM *multi_handle,
                           fd_set *read_fd_set,
                           fd_set *write_fd_set,
                           fd_set *exc_fd_set,
                           int *max_fd);

πŸ’– DESCRIPTION πŸ’–

so this function pulls file descriptor info out of a given multi_handle. libcurl hands you back its fd_set sets, and your app can then select() on them β€” but bestie, you have to FD_ZERO them yourself first before calling this function, because curl_multi_fdset(3) only adds its own descriptors. it does not zero out or remove anything else that's already chilling in there. πŸ™ˆ and the second one of those descriptors is ready to be read from or written to, you should call curl_multi_perform(3). periodt.

if the read_fd_set argument isn't a null pointer, it points to an object of type fd_set that, on return, specifies the file descriptors to be checked for being ready to read. πŸ‘‘

if the write_fd_set argument isn't a null pointer, it points to an object of type fd_set that on return specifies the file descriptors to be checked for being ready to write. ✍️

if the exc_fd_set argument isn't a null pointer, it points to an object of type fd_set that on return specifies the file descriptors to be checked for error conditions pending. πŸ’€

if libcurl sets no file descriptors, max_fd will contain -1 when this function returns. otherwise it'll contain the highest descriptor number libcurl set. and when libcurl returns -1 in max_fd, it's because libcurl is currently doing something your application literally can't monitor with a socket β€” and unfortunately that means you can't know exactly when the current action is completed using select(). 😭 so you gotta wait a while before you proceed and call curl_multi_perform(3) anyway.

how long to wait tho? unless curl_multi_timeout(3) gives you a lower number, we suggest 100 milliseconds or so β€” but honestly you might wanna test it out in your own particular conditions to find a suitable value. πŸ”₯

when you're doing select(), you should use curl_multi_timeout(3) to figure out how long to wait for action. and call curl_multi_perform(3) even if no activity has been seen on the fd_sets after the timeout expires β€” otherwise internal retries and timeouts may not work as you'd think and want. no cap. ⭐

🚨 ok this next bit is important so pay attention 🚨 if one of the sockets used by libcurl happens to be larger than what can be set in an fd_set β€” which on POSIX systems means the file descriptor is larger than FD_SETSIZE β€” then libcurl will try to not set it. setting a too-large file descriptor in an fd_set implies an out of bounds write which can cause crashes, or worse. πŸ’€ the effect of NOT storing it will possibly save you from the crash, but will make your program NOT wait for sockets it should wait for... 🫠

🌈 RETURN VALUE 🌈

CURLMcode type, the general libcurl multi interface error code. check libcurl-errors(3) for the deets. πŸ’œ


πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole page, bestie!! go forth and select() responsibly 🧚✨

mwah πŸ’‹ β€” this came to you from libcurl 7.16.0, dated 2 Jan 2006, and it's page gnurl_multi_fdset(3) out of the libgnurl Manual. slay πŸŽ€

πŸ“¦ where this page comes from