1*6236dae4SAndroid Build Coastguard Worker--- 2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al. 3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl 4*6236dae4SAndroid Build Coastguard WorkerTitle: curl_multi_assign 5*6236dae4SAndroid Build Coastguard WorkerSection: 3 6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl 7*6236dae4SAndroid Build Coastguard WorkerSee-also: 8*6236dae4SAndroid Build Coastguard Worker - curl_multi_setopt (3) 9*6236dae4SAndroid Build Coastguard Worker - curl_multi_socket_action (3) 10*6236dae4SAndroid Build Coastguard WorkerProtocol: 11*6236dae4SAndroid Build Coastguard Worker - All 12*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.15.5 13*6236dae4SAndroid Build Coastguard Worker--- 14*6236dae4SAndroid Build Coastguard Worker 15*6236dae4SAndroid Build Coastguard Worker# NAME 16*6236dae4SAndroid Build Coastguard Worker 17*6236dae4SAndroid Build Coastguard Workercurl_multi_assign - set data to associate with an internal socket 18*6236dae4SAndroid Build Coastguard Worker 19*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS 20*6236dae4SAndroid Build Coastguard Worker 21*6236dae4SAndroid Build Coastguard Worker~~~c 22*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h> 23*6236dae4SAndroid Build Coastguard Worker 24*6236dae4SAndroid Build Coastguard WorkerCURLMcode curl_multi_assign(CURLM *multi_handle, curl_socket_t sockfd, 25*6236dae4SAndroid Build Coastguard Worker void *sockptr); 26*6236dae4SAndroid Build Coastguard Worker~~~ 27*6236dae4SAndroid Build Coastguard Worker 28*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION 29*6236dae4SAndroid Build Coastguard Worker 30*6236dae4SAndroid Build Coastguard WorkerThis function creates an association in the multi handle between the given 31*6236dae4SAndroid Build Coastguard Workersocket and a private pointer of the application. This is designed for 32*6236dae4SAndroid Build Coastguard Workercurl_multi_socket_action(3) uses. 33*6236dae4SAndroid Build Coastguard Worker 34*6236dae4SAndroid Build Coastguard WorkerWhen set, the *sockptr* pointer is passed to all future socket callbacks 35*6236dae4SAndroid Build Coastguard Workerfor the specific *sockfd* socket. 36*6236dae4SAndroid Build Coastguard Worker 37*6236dae4SAndroid Build Coastguard WorkerIf the given *sockfd* is not already in use by libcurl, this function 38*6236dae4SAndroid Build Coastguard Workerreturns an error. 39*6236dae4SAndroid Build Coastguard Worker 40*6236dae4SAndroid Build Coastguard Workerlibcurl only keeps one single pointer associated with a socket, so calling 41*6236dae4SAndroid Build Coastguard Workerthis function several times for the same socket makes the last set pointer get 42*6236dae4SAndroid Build Coastguard Workerused. 43*6236dae4SAndroid Build Coastguard Worker 44*6236dae4SAndroid Build Coastguard WorkerThe idea here being that this association (socket to private pointer) is 45*6236dae4SAndroid Build Coastguard Workersomething that just about every application that uses this API needs and then 46*6236dae4SAndroid Build Coastguard Workerlibcurl can just as well do it since it already has the necessary 47*6236dae4SAndroid Build Coastguard Workerfunctionality. 48*6236dae4SAndroid Build Coastguard Worker 49*6236dae4SAndroid Build Coastguard WorkerIt is acceptable to call this function from your multi callback functions. 50*6236dae4SAndroid Build Coastguard Worker 51*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 52*6236dae4SAndroid Build Coastguard Worker 53*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 54*6236dae4SAndroid Build Coastguard Worker 55*6236dae4SAndroid Build Coastguard Worker~~~c 56*6236dae4SAndroid Build Coastguard Workerint main(void) 57*6236dae4SAndroid Build Coastguard Worker{ 58*6236dae4SAndroid Build Coastguard Worker CURLM *multi = curl_multi_init(); 59*6236dae4SAndroid Build Coastguard Worker void *ourstructp; /* pointer to our data */ 60*6236dae4SAndroid Build Coastguard Worker curl_socket_t fd; /* file descriptor to associate our data with */ 61*6236dae4SAndroid Build Coastguard Worker 62*6236dae4SAndroid Build Coastguard Worker /* make our struct pointer associated with socket fd */ 63*6236dae4SAndroid Build Coastguard Worker CURLMcode mc = curl_multi_assign(multi, fd, ourstructp); 64*6236dae4SAndroid Build Coastguard Worker if(mc) 65*6236dae4SAndroid Build Coastguard Worker printf("error: %s\n", curl_multi_strerror(mc)); 66*6236dae4SAndroid Build Coastguard Worker} 67*6236dae4SAndroid Build Coastguard Worker~~~ 68*6236dae4SAndroid Build Coastguard Worker 69*6236dae4SAndroid Build Coastguard Worker# TYPICAL USAGE 70*6236dae4SAndroid Build Coastguard Worker 71*6236dae4SAndroid Build Coastguard WorkerIn a typical application you allocate a struct or at least use some kind of 72*6236dae4SAndroid Build Coastguard Workersemi-dynamic data for each socket that we must wait for action on when using 73*6236dae4SAndroid Build Coastguard Workerthe curl_multi_socket_action(3) approach. 74*6236dae4SAndroid Build Coastguard Worker 75*6236dae4SAndroid Build Coastguard WorkerWhen our socket-callback gets called by libcurl and we get to know about yet 76*6236dae4SAndroid Build Coastguard Workeranother socket to wait for, we can use curl_multi_assign(3) to point out the 77*6236dae4SAndroid Build Coastguard Workerparticular data so that when we get updates about this same socket again, we 78*6236dae4SAndroid Build Coastguard Workerdo not have to find the struct associated with this socket by ourselves. 79*6236dae4SAndroid Build Coastguard Worker 80*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 81*6236dae4SAndroid Build Coastguard Worker 82*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 83*6236dae4SAndroid Build Coastguard Worker 84*6236dae4SAndroid Build Coastguard WorkerThe standard CURLMcode for multi interface error codes. 85