Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
websocket.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2019 Intel Corporation
9 *
10 * SPDX-License-Identifier: Apache-2.0
11 */
12
13#ifndef ZEPHYR_INCLUDE_NET_WEBSOCKET_H_
14#define ZEPHYR_INCLUDE_NET_WEBSOCKET_H_
15
16#include <zephyr/kernel.h>
17
18#include <zephyr/net/net_ip.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
34#define WEBSOCKET_FLAG_FINAL 0x00000001
35#define WEBSOCKET_FLAG_TEXT 0x00000002
36#define WEBSOCKET_FLAG_BINARY 0x00000004
37#define WEBSOCKET_FLAG_CLOSE 0x00000008
38#define WEBSOCKET_FLAG_PING 0x00000010
39#define WEBSOCKET_FLAG_PONG 0x00000020
50
61typedef int (*websocket_connect_cb_t)(int ws_sock, struct http_request *req,
62 void *user_data);
63
108
127int websocket_connect(int http_sock, struct websocket_request *req,
128 int32_t timeout, void *user_data);
129
151int websocket_send_msg(int ws_sock, const uint8_t *payload, size_t payload_len,
152 enum websocket_opcode opcode, bool mask, bool final,
154
175int websocket_recv_msg(int ws_sock, uint8_t *buf, size_t buf_len,
176 uint32_t *message_type, uint64_t *remaining,
178
189int websocket_disconnect(int ws_sock);
190
203int websocket_register(int http_sock, uint8_t *recv_buf, size_t recv_buf_len);
204
214int websocket_unregister(int ws_sock);
215
218#if defined(CONFIG_WEBSOCKET_CLIENT)
219void websocket_init(void);
220#else
221static inline void websocket_init(void)
222{
223}
224#endif
225
228#ifdef __cplusplus
229}
230#endif
231
236#endif /* ZEPHYR_INCLUDE_NET_WEBSOCKET_H_ */
HTTP client API.
ZTEST_BMEM int timeout
Definition main.c:31
int(* http_header_cb_t)(int sock, struct http_request *req, void *user_data)
Callback can be used if application wants to construct additional HTTP headers when the HTTP request ...
Definition client.h:85
int websocket_recv_msg(int ws_sock, uint8_t *buf, size_t buf_len, uint32_t *message_type, uint64_t *remaining, int32_t timeout)
Receive websocket msg from peer.
websocket_opcode
Websocket option codes.
Definition websocket.h:42
int(* websocket_connect_cb_t)(int ws_sock, struct http_request *req, void *user_data)
Callback called after Websocket connection is established.
Definition websocket.h:61
int websocket_connect(int http_sock, struct websocket_request *req, int32_t timeout, void *user_data)
Connect to a server that provides Websocket service.
int websocket_unregister(int ws_sock)
Unregister a websocket.
int websocket_register(int http_sock, uint8_t *recv_buf, size_t recv_buf_len)
Register a socket as websocket.
int websocket_send_msg(int ws_sock, const uint8_t *payload, size_t payload_len, enum websocket_opcode opcode, bool mask, bool final, int32_t timeout)
Send websocket msg to peer.
int websocket_disconnect(int ws_sock)
Close websocket.
@ WEBSOCKET_OPCODE_PONG
Pong message.
Definition websocket.h:48
@ WEBSOCKET_OPCODE_DATA_TEXT
Textual data.
Definition websocket.h:44
@ WEBSOCKET_OPCODE_CLOSE
Closing connection.
Definition websocket.h:46
@ WEBSOCKET_OPCODE_CONTINUE
Message continues.
Definition websocket.h:43
@ WEBSOCKET_OPCODE_DATA_BINARY
Binary data.
Definition websocket.h:45
@ WEBSOCKET_OPCODE_PING
Ping message.
Definition websocket.h:47
Public kernel APIs.
IPv6 and IPv4 definitions.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Definition parser.h:190
HTTP client request.
Definition client.h:230
Websocket client connection request.
Definition websocket.h:68
size_t tmp_buf_len
Length of the user supplied temp buffer.
Definition websocket.h:106
const struct http_parser_settings * http_cb
User supplied list of callback functions if the calling application wants to know the parsing status ...
Definition websocket.h:100
const char * url
URL of the Websocket.
Definition websocket.h:73
const char ** optional_headers
A NULL terminated list of any optional headers that should be added to the HTTP request.
Definition websocket.h:87
const char * host
Host of the Websocket server when doing HTTP handshakes.
Definition websocket.h:70
uint8_t * tmp_buf
User supplied buffer where HTTP connection data is stored.
Definition websocket.h:103
websocket_connect_cb_t cb
User supplied callback function to call when a connection is established.
Definition websocket.h:92
http_header_cb_t optional_headers_cb
User supplied callback function to call when optional headers need to be sent.
Definition websocket.h:81
static const intptr_t user_data[5]
Definition main.c:588