curl_multi_assign(3)
π curl_multi_assign(3)
okay so this is a page from the Library Functions Manual β it's curl_multi_assign, and bestie, it's literally the glow-up your socket bookkeeping has been waiting for π«Ά
β¨ NAME β¨
curl_multi_assign β set data to associate with an internal socket π
πΈ SYNOPSIS πΈ
#include <curl/curl.h>
CURLMcode curl_multi_assign(CURLM *multi_handle, curl_socket_t sockfd,
void *sockptr);
π¦ DESCRIPTION π¦
So what this does: it creates an association inside the multi handle between a given socket and a private pointer that belongs to you, the application. It's designed specifically for curl_multi_socket_action(3) situations β iykyk π
Once you set it, that sockptr pointer gets passed to all future socket callbacks for that specific sockfd socket. Like, every single time. No cap.
β οΈ heads up: if the sockfd you hand over isn't already in use by libcurl, this function returns an error. Not a vibe, but them's the rules π
Also important: libcurl only keeps one single pointer associated with a socket. So if you call this function several times for the same socket, the last set pointer is the one that gets used. Last write wins, periodt. π
The whole idea here? This association (socket β private pointer) is something that basically every application using this API needs anyway, so libcurl can just as well do it for you β it already has all the necessary functionality. Iconic efficiency honestly. β¨
And yes β it is acceptable to call this function from your multi callback functions. Go off. π
π§ PROTOCOLS π§
This functionality affects all supported protocols π
π EXAMPLE π
int main(void)
{
CURLM *multi = curl_multi_init();
int private = 123;
curl_socket_t fd = 0; /* file descriptor to associate our data with */
/* make our struct pointer associated with socket fd */
CURLMcode mresult = curl_multi_assign(multi, fd, &private);
if(mresult)
printf("error: %s\n", curl_multi_strerror(mresult));
}
π TYPICAL USAGE π
In a typical application, you allocate a struct β or at minimum some kind of semi-dynamic data β for each socket that you have to wait for action on when you're using the curl_multi_socket_action(3) approach. That's just the setup, bestie. π«Ά
Then: when your socket callback gets called by libcurl and you learn about yet another socket to wait for, you can use curl_multi_assign(3) to point out that particular data. The payoff? When you get updates about this same socket again, you don't have to go find the struct associated with it yourself. You already know. Main character energy. πβ¨
π AVAILABILITY π
Added in curl 7.15.5 π
π₯ RETURN VALUE π₯
This function returns a CURLMcode indicating success or error.
CURLM_OK (0) means everything was OK π β a non-zero value means an error occurred, see libcurl-errors(3) π
β SEE ALSO β
okay that's the whole page, you're so welcome π this was libcurl, dated 2026-10-12 β go forth and associate your sockets, bestie, slay π¦πΈπ
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms