Zephyr API Documentation 4.0.0-rc3
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
36#define WEBSOCKET_FLAG_FINAL 0x00000001
37#define WEBSOCKET_FLAG_TEXT 0x00000002
38#define WEBSOCKET_FLAG_BINARY 0x00000004
39#define WEBSOCKET_FLAG_CLOSE 0x00000008
40#define WEBSOCKET_FLAG_PING 0x00000010
41#define WEBSOCKET_FLAG_PONG 0x00000020
52
63typedef int (*websocket_connect_cb_t)(int ws_sock, struct http_request *req,
64 void *user_data);
65
110
129int websocket_connect(int http_sock, struct websocket_request *req,
130 int32_t timeout, void *user_data);
131
153int websocket_send_msg(int ws_sock, const uint8_t *payload, size_t payload_len,
154 enum websocket_opcode opcode, bool mask, bool final,
155 int32_t timeout);
156
177int websocket_recv_msg(int ws_sock, uint8_t *buf, size_t buf_len,
178 uint32_t *message_type, uint64_t *remaining,
179 int32_t timeout);
180
191int websocket_disconnect(int ws_sock);
192
205int websocket_register(int http_sock, uint8_t *recv_buf, size_t recv_buf_len);
206
216int websocket_unregister(int ws_sock);
217
220#if defined(CONFIG_WEBSOCKET_CLIENT)
221void websocket_init(void);
222#else
223static inline void websocket_init(void)
224{
225}
226#endif
227
230#ifdef __cplusplus
231}
232#endif
233
238#endif /* ZEPHYR_INCLUDE_NET_WEBSOCKET_H_ */
HTTP client API.
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:44
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_connect_cb_t)(int ws_sock, struct http_request *req, void *user_data)
Callback called after Websocket connection is established.
Definition websocket.h:63
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:50
@ WEBSOCKET_OPCODE_DATA_TEXT
Textual data.
Definition websocket.h:46
@ WEBSOCKET_OPCODE_CLOSE
Closing connection.
Definition websocket.h:48
@ WEBSOCKET_OPCODE_CONTINUE
Message continues.
Definition websocket.h:45
@ WEBSOCKET_OPCODE_DATA_BINARY
Binary data.
Definition websocket.h:47
@ WEBSOCKET_OPCODE_PING
Ping message.
Definition websocket.h:49
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:70
size_t tmp_buf_len
Length of the user supplied temp buffer.
Definition websocket.h:108
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:102
const char * url
URL of the Websocket.
Definition websocket.h:75
const char ** optional_headers
A NULL terminated list of any optional headers that should be added to the HTTP request.
Definition websocket.h:89
const char * host
Host of the Websocket server when doing HTTP handshakes.
Definition websocket.h:72
uint8_t * tmp_buf
User supplied buffer where HTTP connection data is stored.
Definition websocket.h:105
websocket_connect_cb_t cb
User supplied callback function to call when a connection is established.
Definition websocket.h:94
http_header_cb_t optional_headers_cb
User supplied callback function to call when optional headers need to be sent.
Definition websocket.h:83