curl_multi_socket.md (2740B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: curl_multi_socket 5 Section: 3 6 Source: libcurl 7 See-also: 8 - curl_multi_cleanup (3) 9 - curl_multi_fdset (3) 10 - curl_multi_info_read (3) 11 - curl_multi_init (3) 12 - the hiperfifo.c example 13 Protocol: 14 - All 15 Added-in: 7.15.4 16 --- 17 18 # NAME 19 20 curl_multi_socket - read/write available data 21 22 # SYNOPSIS 23 24 ~~~c 25 #include <curl/curl.h> 26 CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t sockfd, 27 int *running_handles); 28 ~~~ 29 30 # DESCRIPTION 31 32 This function is deprecated. Use curl_multi_socket_action(3) instead with 33 **ev_bitmask** set to 0. 34 35 At return, the integer **running_handles** points to contains the number of 36 still running easy handles within the multi handle. When this number reaches 37 zero, all transfers are complete/done. Note that when you call 38 curl_multi_socket(3) on a specific socket and the counter decreases by one, it 39 DOES NOT necessarily mean that this exact socket/transfer is the one that 40 completed. Use curl_multi_info_read(3) to figure out which easy handle that 41 completed. 42 43 The curl_multi_socket(3) functions inform the application about updates in the 44 socket (file descriptor) status by doing none, one, or multiple calls to the 45 socket callback function set with the CURLMOPT_SOCKETFUNCTION(3) option to 46 curl_multi_setopt(3). They update the status with changes since the previous 47 time the callback was called. 48 49 Get the timeout time by setting the CURLMOPT_TIMERFUNCTION(3) option with 50 curl_multi_setopt(3). Your application then gets called with information on 51 how long to wait for socket actions at most before doing the timeout action: 52 call the curl_multi_socket_action(3) function with the **sockfd** argument set 53 to CURL_SOCKET_TIMEOUT. You can also use the curl_multi_timeout(3) function to 54 poll the value at any given time, but for an event-based system using the 55 callback is far better than relying on polling the timeout value. 56 57 # %PROTOCOLS% 58 59 # EXAMPLE 60 61 ~~~c 62 int main(void) 63 { 64 /* the event-library gets told when there activity on the socket 'fd', 65 which we translate to a call to curl_multi_socket_action() */ 66 int running; 67 int rc; 68 int fd = 2; 69 CURLM *multi = curl_multi_init(); 70 71 rc = curl_multi_socket(multi, fd, &running); 72 } 73 ~~~ 74 75 # DEPRECATED 76 77 curl_multi_socket(3) is deprecated, use curl_multi_socket_action(3) instead. 78 79 # %AVAILABILITY% 80 81 # RETURN VALUE 82 83 This function returns a CURLMcode indicating success or error. 84 85 CURLM_OK (0) means everything was OK, non-zero means an error occurred, see 86 libcurl-errors(3). 87 88 The return code is for the whole multi stack. Problems still might have 89 occurred on individual transfers even when one of these functions return OK.