curl_ws_recv.3 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. .\" generated by cd2nroff 0.1 from curl_ws_recv.md
  2. .TH curl_ws_recv 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_ws_recv \- receive WebSocket data
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_ws_recv(CURL *curl, void *buffer, size_t buflen,
  9. size_t *recv, const struct curl_ws_frame **meta);
  10. .fi
  11. .SH DESCRIPTION
  12. This function call is EXPERIMENTAL.
  13. Retrieves as much as possible of a received WebSocket data fragment into the
  14. \fBbuffer\fP, but not more than \fBbuflen\fP bytes. \fIrecv\fP is set to the
  15. number of bytes actually stored.
  16. If there is more fragment data to deliver than what fits in the provided
  17. \fIbuffer\fP, libcurl returns a full buffer and the application needs to call
  18. this function again to continue draining the buffer.
  19. The \fImeta\fP pointer gets set to point to a \fIconst struct curl_ws_frame\fP
  20. that contains information about the received data. See the
  21. \fIcurl_ws_meta(3)\fP for details on that struct.
  22. .SH PROTOCOLS
  23. This functionality affects ws only
  24. .SH EXAMPLE
  25. .nf
  26. int main(void)
  27. {
  28. size_t rlen;
  29. const struct curl_ws_frame *meta;
  30. char buffer[256];
  31. CURL *curl = curl_easy_init();
  32. if(curl) {
  33. CURLcode res = curl_ws_recv(curl, buffer, sizeof(buffer), &rlen, &meta);
  34. if(res)
  35. printf("error: %s\\n", curl_easy_strerror(res));
  36. }
  37. }
  38. .fi
  39. .SH AVAILABILITY
  40. Added in curl 7.86.0
  41. .SH RETURN VALUE
  42. Returns \fBCURLE_OK\fP if everything is okay, and a non\-zero number for
  43. errors. Returns \fBCURLE_GOT_NOTHING\fP if the associated connection is
  44. closed.
  45. Instead of blocking, the function returns \fBCURLE_AGAIN\fP. The correct
  46. behavior is then to wait for the socket to signal readability before calling
  47. this function again.
  48. .SH SEE ALSO
  49. .BR curl_easy_getinfo (3),
  50. .BR curl_easy_perform (3),
  51. .BR curl_easy_setopt (3),
  52. .BR curl_ws_send (3),
  53. .BR libcurl-ws (3)