1curl_easy_send(3) libcurl curl_easy_send(3)
2
3
4
6 curl_easy_send - sends raw data over an "easy" connection
7
9 #include <curl/easy.h>
10
11 CURLcode curl_easy_send(CURL *curl, const void *buffer,
12 size_t buflen, size_t *n);
13
15 This function sends arbitrary data over the established connection. You
16 may use it together with curl_easy_recv(3) to implement custom proto‐
17 cols using libcurl. This functionality can be particularly useful if
18 you use proxies and/or SSL encryption: libcurl will take care of proxy
19 negotiation and connection setup.
20
21 buffer is a pointer to the data of length buflen that you want sent.
22 The variable n points to will receive the number of sent bytes.
23
24 To establish the connection, set CURLOPT_CONNECT_ONLY(3) option before
25 calling curl_easy_perform(3) or curl_multi_perform(3). Note that
26 curl_easy_send(3) will not work on connections that were created with‐
27 out this option.
28
29 The call will return CURLE_AGAIN if it's not possible to send data
30 right now - the socket is used in non-blocking mode internally. When
31 CURLE_AGAIN is returned, use your operating system facilities like se‐
32 lect(2) to wait until the socket is writable. The socket may be ob‐
33 tained using curl_easy_getinfo(3) with CURLINFO_ACTIVESOCKET(3).
34
35 Furthermore if you wait on the socket and it tells you it's writable,
36 curl_easy_send(3) may return CURLE_AGAIN if the only data that was sent
37 was for internal SSL processing, and no other data could be sent.
38
40 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
41 /* Do not do the transfer - only connect to host */
42 curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
43 res = curl_easy_perform(curl);
44
45 if(res == CURLE_OK) {
46 /* Extract the socket from the curl handle -
47 we will need it for waiting. */
48 res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
49
50 /* send data */
51 res = curl_easy_send(curl, "hello", 5, &sent);
52 }
53
55 Added in 7.18.2.
56
58 On success, returns CURLE_OK and stores the number of bytes actually
59 sent into *n. Note that this may be less than the amount you wanted to
60 send.
61
62 On failure, returns the appropriate error code.
63
64 This function may return CURLE_AGAIN. In this case, use your operating
65 system facilities to wait until the socket is writable, and retry.
66
67 If there's no socket available to use from the previous transfer, this
68 function returns CURLE_UNSUPPORTED_PROTOCOL.
69
71 curl_easy_setopt(3), curl_easy_perform(3), curl_easy_getinfo(3),
72 curl_easy_recv(3)
73
74
75
76libcurl 8.2.1 April 26, 2023 curl_easy_send(3)