curl_easy_send.3 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. .\" generated by cd2nroff 0.1 from curl_easy_send.md
  2. .TH curl_easy_send 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_easy_send \- sends raw data over an "easy" connection
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_send(CURL *curl, const void *buffer,
  9. size_t buflen, size_t *n);
  10. .fi
  11. .SH DESCRIPTION
  12. This function sends arbitrary data over the established connection. You may
  13. use it together with \fIcurl_easy_recv(3)\fP to implement custom protocols
  14. using libcurl. This functionality can be particularly useful if you use
  15. proxies and/or SSL encryption: libcurl takes care of proxy negotiation and
  16. connection setup.
  17. \fBbuffer\fP is a pointer to the data of length \fBbuflen\fP that you want
  18. sent. The variable \fBn\fP points to receives the number of sent bytes.
  19. To establish the connection, set \fICURLOPT_CONNECT_ONLY(3)\fP option before
  20. calling \fIcurl_easy_perform(3)\fP or \fIcurl_multi_perform(3)\fP. Note that
  21. \fIcurl_easy_send(3)\fP does not work on connections that were created without
  22. this option.
  23. The call returns \fBCURLE_AGAIN\fP if it is not possible to send data right now
  24. - the socket is used in non\-blocking mode internally. When \fBCURLE_AGAIN\fP
  25. is returned, use your operating system facilities like \fIselect(2)\fP to wait
  26. until the socket is writable. The socket may be obtained using
  27. \fIcurl_easy_getinfo(3)\fP with \fICURLINFO_ACTIVESOCKET(3)\fP.
  28. Furthermore if you wait on the socket and it tells you it is writable,
  29. \fIcurl_easy_send(3)\fP may return \fBCURLE_AGAIN\fP if the only data that was sent
  30. was for internal SSL processing, and no other data could be sent.
  31. .SH PROTOCOLS
  32. This functionality affects all supported protocols
  33. .SH EXAMPLE
  34. .nf
  35. int main(void)
  36. {
  37. CURL *curl = curl_easy_init();
  38. if(curl) {
  39. CURLcode res;
  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. if(res == CURLE_OK) {
  45. long sockfd;
  46. size_t sent;
  47. /* Extract the socket from the curl handle - we need it for waiting. */
  48. res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
  49. /* send data */
  50. res = curl_easy_send(curl, "hello", 5, &sent);
  51. }
  52. }
  53. }
  54. .fi
  55. .SH AVAILABILITY
  56. Added in curl 7.18.2
  57. .SH RETURN VALUE
  58. On success, returns \fBCURLE_OK\fP and stores the number of bytes actually
  59. sent into \fB*n\fP. Note that this may be less than the amount you wanted to
  60. send.
  61. On failure, returns the appropriate error code.
  62. This function may return \fBCURLE_AGAIN\fP. In this case, use your operating
  63. system facilities to wait until the socket is writable, and retry.
  64. If there is no socket available to use from the previous transfer, this function
  65. returns \fBCURLE_UNSUPPORTED_PROTOCOL\fP.
  66. .SH SEE ALSO
  67. .BR curl_easy_getinfo (3),
  68. .BR curl_easy_perform (3),
  69. .BR curl_easy_recv (3),
  70. .BR curl_easy_setopt (3)