quickjs-tart

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

CURLOPT_CLOSESOCKETDATA.md (1741B)


      1 ---
      2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
      3 SPDX-License-Identifier: curl
      4 Title: CURLOPT_CLOSESOCKETDATA
      5 Section: 3
      6 Source: libcurl
      7 See-also:
      8   - CURLOPT_CLOSESOCKETFUNCTION (3)
      9   - CURLOPT_OPENSOCKETFUNCTION (3)
     10 Protocol:
     11   - All
     12 Added-in: 7.21.7
     13 ---
     14 
     15 # NAME
     16 
     17 CURLOPT_CLOSESOCKETDATA - pointer passed to the socket close callback
     18 
     19 # SYNOPSIS
     20 
     21 ~~~c
     22 #include <curl/curl.h>
     23 
     24 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CLOSESOCKETDATA,
     25                           void *pointer);
     26 ~~~
     27 
     28 # DESCRIPTION
     29 
     30 Pass a *pointer* that remains untouched by libcurl and passed as the first
     31 argument in the closesocket callback set with
     32 CURLOPT_CLOSESOCKETFUNCTION(3).
     33 
     34 Note that when using multi/share handles, your callback may get invoked even
     35 after the easy handle has been cleaned up. The callback and data is
     36 inherited by a new connection and that connection may live longer
     37 than the transfer itself in the multi/share handle's connection cache.
     38 
     39 # DEFAULT
     40 
     41 NULL
     42 
     43 # %PROTOCOLS%
     44 
     45 # EXAMPLE
     46 
     47 ~~~c
     48 struct priv {
     49   void *custom;
     50 };
     51 
     52 static int closesocket(void *clientp, curl_socket_t item)
     53 {
     54   struct priv *my = clientp;
     55   printf("our ptr: %p\n", my->custom);
     56 
     57   printf("libcurl wants to close %d now\n", (int)item);
     58   return 0;
     59 }
     60 
     61 int main(void)
     62 {
     63   struct priv myown;
     64   CURL *curl = curl_easy_init();
     65 
     66   /* call this function to close sockets */
     67   curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket);
     68   curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &myown);
     69 
     70   curl_easy_perform(curl);
     71   curl_easy_cleanup(curl);
     72 }
     73 ~~~
     74 
     75 # %AVAILABILITY%
     76 
     77 # RETURN VALUE
     78 
     79 curl_easy_setopt(3) returns a CURLcode indicating success or error.
     80 
     81 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see
     82 libcurl-errors(3).