websockets.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef CURLINC_WEBSOCKETS_H
  2. #define CURLINC_WEBSOCKETS_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. * SPDX-License-Identifier: curl
  24. *
  25. ***************************************************************************/
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. struct curl_ws_frame {
  30. int age; /* zero */
  31. int flags; /* See the CURLWS_* defines */
  32. curl_off_t offset; /* the offset of this data into the frame */
  33. curl_off_t bytesleft; /* number of pending bytes left of the payload */
  34. size_t len; /* size of the current data chunk */
  35. };
  36. /* flag bits */
  37. #define CURLWS_TEXT (1<<0)
  38. #define CURLWS_BINARY (1<<1)
  39. #define CURLWS_CONT (1<<2)
  40. #define CURLWS_CLOSE (1<<3)
  41. #define CURLWS_PING (1<<4)
  42. #define CURLWS_OFFSET (1<<5)
  43. /*
  44. * NAME curl_ws_recv()
  45. *
  46. * DESCRIPTION
  47. *
  48. * Receives data from the websocket connection. Use after successful
  49. * curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
  50. */
  51. CURL_EXTERN CURLcode curl_ws_recv(CURL *curl, void *buffer, size_t buflen,
  52. size_t *recv,
  53. const struct curl_ws_frame **metap);
  54. /* flags for curl_ws_send() */
  55. #define CURLWS_PONG (1<<6)
  56. /*
  57. * NAME curl_ws_send()
  58. *
  59. * DESCRIPTION
  60. *
  61. * Sends data over the websocket connection. Use after successful
  62. * curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
  63. */
  64. CURL_EXTERN CURLcode curl_ws_send(CURL *curl, const void *buffer,
  65. size_t buflen, size_t *sent,
  66. curl_off_t fragsize,
  67. unsigned int flags);
  68. /*
  69. * NAME curl_ws_start_frame()
  70. *
  71. * DESCRIPTION
  72. *
  73. * Buffers a websocket frame header with the given flags and length.
  74. * Errors when a previous frame is not complete, e.g. not all its
  75. * payload has been added.
  76. */
  77. CURL_EXTERN CURLcode curl_ws_start_frame(CURL *curl,
  78. unsigned int flags,
  79. curl_off_t frame_len);
  80. /* bits for the CURLOPT_WS_OPTIONS bitmask: */
  81. #define CURLWS_RAW_MODE (1L<<0)
  82. #define CURLWS_NOAUTOPONG (1L<<1)
  83. CURL_EXTERN const struct curl_ws_frame *curl_ws_meta(CURL *curl);
  84. #ifdef __cplusplus
  85. }
  86. #endif
  87. #endif /* CURLINC_WEBSOCKETS_H */