quickjs-tart

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

curl_easy_send.md (2898B)


      1 ---
      2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
      3 SPDX-License-Identifier: curl
      4 Title: curl_easy_send
      5 Section: 3
      6 Source: libcurl
      7 See-also:
      8   - curl_easy_getinfo (3)
      9   - curl_easy_perform (3)
     10   - curl_easy_recv (3)
     11   - curl_easy_setopt (3)
     12 Protocol:
     13   - All
     14 Added-in: 7.18.2
     15 ---
     16 
     17 # NAME
     18 
     19 curl_easy_send - sends raw data over an "easy" connection
     20 
     21 # SYNOPSIS
     22 
     23 ~~~c
     24 #include <curl/curl.h>
     25 
     26 CURLcode curl_easy_send(CURL *curl, const void *buffer,
     27                         size_t buflen, size_t *n);
     28 ~~~
     29 
     30 # DESCRIPTION
     31 
     32 This function sends arbitrary data over the established connection. You may
     33 use it together with curl_easy_recv(3) to implement custom protocols
     34 using libcurl. This functionality can be particularly useful if you use
     35 proxies and/or SSL encryption: libcurl takes care of proxy negotiation and
     36 connection setup.
     37 
     38 **buffer** is a pointer to the data of length **buflen** that you want
     39 sent. The variable **n** points to receives the number of sent bytes.
     40 
     41 To establish the connection, set CURLOPT_CONNECT_ONLY(3) option before
     42 calling curl_easy_perform(3) or curl_multi_perform(3). Note that
     43 curl_easy_send(3) does not work on connections that were created without
     44 this option.
     45 
     46 The call returns **CURLE_AGAIN** if it is not possible to send data right now
     47 - the socket is used in non-blocking mode internally. When **CURLE_AGAIN**
     48 is returned, use your operating system facilities like *select(2)* to wait
     49 until the socket is writable. The socket may be obtained using
     50 curl_easy_getinfo(3) with CURLINFO_ACTIVESOCKET(3).
     51 
     52 Furthermore if you wait on the socket and it tells you it is writable,
     53 curl_easy_send(3) may return **CURLE_AGAIN** if the only data that was sent
     54 was for internal SSL processing, and no other data could be sent.
     55 
     56 # %PROTOCOLS%
     57 
     58 # EXAMPLE
     59 
     60 ~~~c
     61 int main(void)
     62 {
     63   CURL *curl = curl_easy_init();
     64   if(curl) {
     65     CURLcode res;
     66     curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
     67     /* Do not do the transfer - only connect to host */
     68     curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
     69     res = curl_easy_perform(curl);
     70 
     71     if(res == CURLE_OK) {
     72       curl_socket_t sockfd;
     73       size_t sent;
     74       /* Extract the socket from the curl handle - we need it for waiting. */
     75       res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
     76 
     77       /* send data */
     78       res = curl_easy_send(curl, "hello", 5, &sent);
     79     }
     80   }
     81 }
     82 ~~~
     83 
     84 # %AVAILABILITY%
     85 
     86 # RETURN VALUE
     87 
     88 On success, returns **CURLE_OK** and stores the number of bytes actually
     89 sent into ***n**. Note that this may be less than the amount you wanted to
     90 send.
     91 
     92 On failure, returns the appropriate error code.
     93 
     94 This function may return **CURLE_AGAIN**. In this case, use your operating
     95 system facilities to wait until the socket is writable, and retry.
     96 
     97 If there is no socket available to use from the previous transfer, this
     98 function returns **CURLE_UNSUPPORTED_PROTOCOL**.