quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

CURLINFO_ACTIVESOCKET.md (2156B)


      1 ---
      2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
      3 SPDX-License-Identifier: curl
      4 Title: CURLINFO_ACTIVESOCKET
      5 Section: 3
      6 Source: libcurl
      7 See-also:
      8   - CURLINFO_LASTSOCKET (3)
      9   - CURLOPT_CONNECT_ONLY (3)
     10   - curl_easy_getinfo (3)
     11   - curl_easy_setopt (3)
     12 Protocol:
     13   - All
     14 Added-in: 7.45.0
     15 ---
     16 
     17 # NAME
     18 
     19 CURLINFO_ACTIVESOCKET - get the active socket
     20 
     21 # SYNOPSIS
     22 
     23 ~~~c
     24 #include <curl/curl.h>
     25 
     26 CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_ACTIVESOCKET,
     27                            curl_socket_t *socket);
     28 ~~~
     29 
     30 # DESCRIPTION
     31 
     32 Pass a pointer to a curl_socket_t to receive the most recently active socket
     33 used for the transfer connection by this curl session. If the socket is no
     34 longer valid, *CURL_SOCKET_BAD* is returned. When you are finished working
     35 with the socket, you must call curl_easy_cleanup(3) as usual on the easy
     36 handle and let libcurl close the socket and cleanup other resources associated
     37 with the handle. This option returns the active socket only after the transfer
     38 is complete, and is typically used in combination with
     39 CURLOPT_CONNECT_ONLY(3), which skips the transfer phase.
     40 
     41 CURLINFO_ACTIVESOCKET(3) was added as a replacement for
     42 CURLINFO_LASTSOCKET(3) since that one is not working on all platforms.
     43 
     44 # %PROTOCOLS%
     45 
     46 # EXAMPLE
     47 
     48 ~~~c
     49 int main(void)
     50 {
     51   CURL *curl = curl_easy_init();
     52   if(curl) {
     53     CURLcode res;
     54     curl_socket_t sockfd;
     55     curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
     56 
     57     /* Do not do the transfer - only connect to host */
     58     curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
     59     res = curl_easy_perform(curl);
     60     if(res != CURLE_OK) {
     61       printf("Error: %s\n", curl_easy_strerror(res));
     62       curl_easy_cleanup(curl);
     63       return 1;
     64     }
     65 
     66     /* Extract the socket from the curl handle */
     67     res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
     68     if(!res && sockfd != CURL_SOCKET_BAD) {
     69       /* operate on sockfd */
     70     }
     71 
     72     curl_easy_cleanup(curl);
     73   }
     74 }
     75 ~~~
     76 
     77 # %AVAILABILITY%
     78 
     79 # RETURN VALUE
     80 
     81 curl_easy_getinfo(3) returns a CURLcode indicating success or error.
     82 
     83 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see
     84 libcurl-errors(3).