curl_easy_send.3 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .\"
  25. .TH curl_easy_send 3 "29 April 2008" "libcurl" "libcurl"
  26. .SH NAME
  27. curl_easy_send - sends raw data over an "easy" connection
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. CURLcode curl_easy_send(CURL *curl, const void *buffer,
  32. size_t buflen, size_t *n);
  33. .fi
  34. .SH DESCRIPTION
  35. This function sends arbitrary data over the established connection. You may
  36. use it together with \fIcurl_easy_recv(3)\fP to implement custom protocols
  37. using libcurl. This functionality can be particularly useful if you use
  38. proxies and/or SSL encryption: libcurl takes care of proxy negotiation and
  39. connection setup.
  40. \fBbuffer\fP is a pointer to the data of length \fBbuflen\fP that you want
  41. sent. The variable \fBn\fP points to receives the number of sent bytes.
  42. To establish the connection, set \fICURLOPT_CONNECT_ONLY(3)\fP option before
  43. calling \fIcurl_easy_perform(3)\fP or \fIcurl_multi_perform(3)\fP. Note that
  44. \fIcurl_easy_send(3)\fP does not work on connections that were created without
  45. this option.
  46. The call returns \fBCURLE_AGAIN\fP if it's not possible to send data right now
  47. - the socket is used in non-blocking mode internally. When \fBCURLE_AGAIN\fP
  48. is returned, use your operating system facilities like \fIselect(2)\fP to wait
  49. until the socket is writable. The socket may be obtained using
  50. \fIcurl_easy_getinfo(3)\fP with \fICURLINFO_ACTIVESOCKET(3)\fP.
  51. Furthermore if you wait on the socket and it tells you it's writable,
  52. \fIcurl_easy_send(3)\fP may return \fBCURLE_AGAIN\fP if the only data that was
  53. sent was for internal SSL processing, and no other data could be sent.
  54. .SH EXAMPLE
  55. .nf
  56. int main(void)
  57. {
  58. CURL *curl = curl_easy_init();
  59. if(curl) {
  60. CURLcode res;
  61. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  62. /* Do not do the transfer - only connect to host */
  63. curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
  64. res = curl_easy_perform(curl);
  65. if(res == CURLE_OK) {
  66. long sockfd;
  67. size_t sent;
  68. /* Extract the socket from the curl handle - we need it for waiting. */
  69. res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
  70. /* send data */
  71. res = curl_easy_send(curl, "hello", 5, &sent);
  72. }
  73. }
  74. }
  75. .fi
  76. .SH AVAILABILITY
  77. Added in 7.18.2.
  78. .SH RETURN VALUE
  79. On success, returns \fBCURLE_OK\fP and stores the number of bytes actually
  80. sent into \fB*n\fP. Note that this may be less than the amount you wanted to
  81. send.
  82. On failure, returns the appropriate error code.
  83. This function may return \fBCURLE_AGAIN\fP. In this case, use your operating
  84. system facilities to wait until the socket is writable, and retry.
  85. If there is no socket available to use from the previous transfer, this function
  86. returns \fBCURLE_UNSUPPORTED_PROTOCOL\fP.
  87. .SH "SEE ALSO"
  88. .BR curl_easy_setopt (3),
  89. .BR curl_easy_perform (3),
  90. .BR curl_easy_getinfo (3),
  91. .BR curl_easy_recv (3)