Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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 <kernel.h>
17
18#include <net/net_ip.h>
19#include <net/http_parser.h>
20#include <net/http_client.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
48};
49
60typedef int (*websocket_connect_cb_t)(int ws_sock, struct http_request *req,
61 void *user_data);
62
69 const char *host;
70
72 const char *url;
73
81
86 const char **optional_headers;
87
92
100
103
106};
107
126int websocket_connect(int http_sock, struct websocket_request *req,
127 int32_t timeout, void *user_data);
128
150int websocket_send_msg(int ws_sock, const uint8_t *payload, size_t payload_len,
151 enum websocket_opcode opcode, bool mask, bool final,
153
171int websocket_recv_msg(int ws_sock, uint8_t *buf, size_t buf_len,
172 uint32_t *message_type, uint64_t *remaining,
174
183int websocket_disconnect(int ws_sock);
184
185#if defined(CONFIG_WEBSOCKET_CLIENT)
186void websocket_init(void);
187#else
188static inline void websocket_init(void)
189{
190}
191#endif
192
193#ifdef __cplusplus
194}
195#endif
196
201#endif /* ZEPHYR_INCLUDE_NET_WEBSOCKET_H_ */
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: http_client.h:79
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
Definition: websocket.h:41
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:60
int websocket_connect(int http_sock, struct websocket_request *req, int32_t timeout, void *user_data)
Connect to a server that provides Websocket service. The callback is called after connection is estab...
static void websocket_init(void)
Definition: websocket.h:188
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
Definition: websocket.h:47
@ WEBSOCKET_OPCODE_DATA_TEXT
Definition: websocket.h:43
@ WEBSOCKET_OPCODE_CLOSE
Definition: websocket.h:45
@ WEBSOCKET_OPCODE_CONTINUE
Definition: websocket.h:42
@ WEBSOCKET_OPCODE_DATA_BINARY
Definition: websocket.h:44
@ WEBSOCKET_OPCODE_PING
Definition: websocket.h:46
HTTP client API.
IPv6 and IPv4 definitions.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__INT32_TYPE__ int32_t
Definition: stdint.h:44
__UINT64_TYPE__ uint64_t
Definition: stdint.h:61
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
Definition: http_parser.h:225
Definition: http_client.h:190
Definition: websocket.h:67
size_t tmp_buf_len
Definition: websocket.h:105
const struct http_parser_settings * http_cb
Definition: websocket.h:99
const char * url
Definition: websocket.h:72
const char ** optional_headers
Definition: websocket.h:86
const char * host
Definition: websocket.h:69
uint8_t * tmp_buf
Definition: websocket.h:102
websocket_connect_cb_t cb
Definition: websocket.h:91
http_header_cb_t optional_headers_cb
Definition: websocket.h:80
static const intptr_t user_data[5]
Definition: main.c:590