1curl_multi_assign(3)            libcurl Manual            curl_multi_assign(3)
2
3
4

NAME

6       curl_multi_assign - set data to associate with an internal socket
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLMcode curl_multi_assign(CURLM *multi_handle, curl_socket_t sockfd,
12                                   void *sockptr);
13

DESCRIPTION

15       This  function  creates  an association in the multi handle between the
16       given socket and a private pointer of the application. This is designed
17       for curl_multi_socket_action(3) uses.
18
19       When set, the sockptr pointer will be passed to all future socket call‐
20       backs for the specific sockfd socket.
21
22       If the given sockfd is not already in use  by  libcurl,  this  function
23       will return an error.
24
25       libcurl  only  keeps  one  single  pointer associated with a socket, so
26       calling this function several times for the same socket will  make  the
27       last set pointer get used.
28
29       The  idea  here being that this association (socket to private pointer)
30       is something that just about every application that uses this API  will
31       need  and  then  libcurl can just as well do it since it already has an
32       internal hash table lookup for this.
33
34       It is acceptable to call this function from your multi  callback  func‐
35       tions.
36

EXAMPLE

38        /* make our struct pointer associated with socket fd */
39        mc = curl_multi_assign(multi_handle, fd, ourstructp);
40

AVAILABILITY

42       Added in 7.15.5
43

RETURN VALUE

45       The standard CURLMcode for multi interface error codes.
46

TYPICAL USAGE

48       In  a  typical  application  you allocate a struct or at least use some
49       kind of semi-dynamic data for each socket that we must wait for  action
50       on when using the curl_multi_socket_action(3) approach.
51
52       When  our  socket-callback  gets  called  by libcurl and we get to know
53       about yet another socket to wait for, we can  use  curl_multi_assign(3)
54       to point out the particular data so that when we get updates about this
55       same socket again, we do not have to find the  struct  associated  with
56       this socket by ourselves.
57

SEE ALSO

59       curl_multi_setopt(3), curl_multi_socket_action(3)
60
61
62
63libcurl 8.0.1                  January 02, 2023           curl_multi_assign(3)
Impressum