curl_ws_meta.3 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. .\" generated by cd2nroff 0.1 from curl_ws_meta.md
  2. .TH curl_ws_meta 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_ws_meta \- meta data WebSocket information
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. const struct curl_ws_frame *curl_ws_meta(CURL *curl);
  9. .fi
  10. .SH DESCRIPTION
  11. This function call is EXPERIMENTAL.
  12. When the write callback (\fICURLOPT_WRITEFUNCTION(3)\fP) is invoked on
  13. received WebSocket traffic, \fIcurl_ws_meta(3)\fP can be called from within
  14. the callback to provide additional information about the current frame.
  15. This function only works from within the callback, and only when receiving
  16. WebSocket data.
  17. This function requires an easy handle as input argument for libcurl to know
  18. what transfer the question is about, but as there is no such pointer provided
  19. to the callback by libcurl itself, applications that want to use
  20. \fIcurl_ws_meta(3)\fP need to pass it on to the callback on its own.
  21. .SH struct curl_ws_frame
  22. .nf
  23. struct curl_ws_frame {
  24. int age;
  25. int flags;
  26. curl_off_t offset;
  27. curl_off_t bytesleft;
  28. };
  29. .fi
  30. .IP age
  31. This field specify the age of this struct. It is always zero for now.
  32. .IP flags
  33. This is a bitmask with individual bits set that describes the WebSocket data.
  34. See the list below.
  35. .IP offset
  36. When this frame is a continuation of fragment data already delivered, this is
  37. the offset into the final fragment where this piece belongs.
  38. .IP bytesleft
  39. If this is not a complete fragment, the \fIbytesleft\fP field informs about how
  40. many additional bytes are expected to arrive before this fragment is complete.
  41. .SH FLAGS
  42. .IP CURLWS_TEXT
  43. The buffer contains text data. Note that this makes a difference to WebSocket
  44. but libcurl itself does not make any verification of the content or
  45. precautions that you actually receive valid UTF\-8 content.
  46. .IP CURLWS_BINARY
  47. This is binary data.
  48. .IP CURLWS_CONT
  49. This is not the final fragment of the message, it implies that there is
  50. another fragment coming as part of the same message.
  51. .IP CURLWS_CLOSE
  52. This transfer is now closed.
  53. .IP CURLWS_PING
  54. This as an incoming ping message, that expects a pong response.
  55. .SH PROTOCOLS
  56. This functionality affects ws only
  57. .SH EXAMPLE
  58. .nf
  59. /* we pass a pointer to this struct to the callback */
  60. struct customdata {
  61. CURL *easy;
  62. void *ptr;
  63. };
  64. static size_t writecb(unsigned char *buffer,
  65. size_t size, size_t nitems, void *p)
  66. {
  67. struct customdata *c = (struct customdata *)p;
  68. const struct curl_ws_frame *m = curl_ws_meta(c->easy);
  69. printf("flags: %x\\n", m->flags);
  70. }
  71. int main(void)
  72. {
  73. CURL *curl = curl_easy_init();
  74. if(curl) {
  75. struct customdata custom;
  76. custom.easy = curl;
  77. custom.ptr = NULL;
  78. curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb);
  79. curl_easy_setopt(curl, CURLOPT_WRITEDATA, &custom);
  80. curl_easy_perform(curl);
  81. }
  82. }
  83. .fi
  84. .SH AVAILABILITY
  85. Added in curl 7.86.0
  86. .SH RETURN VALUE
  87. This function returns a pointer to a \fIcurl_ws_frame\fP struct with read\-only
  88. information that is valid for this specific callback invocation. If it cannot
  89. return this information, or if the function is called in the wrong context, it
  90. returns NULL.
  91. .SH SEE ALSO
  92. .BR curl_easy_getinfo (3),
  93. .BR curl_easy_setopt (3),
  94. .BR curl_ws_recv (3),
  95. .BR curl_ws_send (3),
  96. .BR libcurl-ws (3)