curl_ws_meta.3 4.2 KB

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