libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-adopt.h
Go to the documentation of this file.
1/*
2 * libwebsockets - small server side websockets and web server implementation
3 *
4 * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
34
48LWS_VISIBLE LWS_EXTERN struct lws *
49lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd);
50
64LWS_VISIBLE LWS_EXTERN struct lws *
65lws_adopt_socket_vhost(struct lws_vhost *vh, lws_sockfd_type accept_fd);
66
67typedef enum {
68 LWS_ADOPT_RAW_FILE_DESC = 0, /* convenience constant */
69 LWS_ADOPT_HTTP = 1, /* flag: absent implies RAW */
70 LWS_ADOPT_SOCKET = 2, /* flag: absent implies file */
71 LWS_ADOPT_ALLOW_SSL = 4, /* flag: use tls */
72 LWS_ADOPT_FLAG_UDP = 16, /* flag: socket is UDP */
73 LWS_ADOPT_FLAG_RAW_PROXY = 32, /* flag: raw proxy */
74 LWS_ADOPT_FLAG_NO_NONBLOCK = 64, /* flag: file fd can't be made
75 * nonblocking, and is never
76 * read in a way that can block,
77 * eg, a Darwin kqueue fd */
78
81
86
87#if defined(LWS_ESP_PLATFORM)
88#include <lwip/sockets.h>
89#endif
90
91typedef union lws_sockaddr46 {
92#if defined(LWS_WITH_IPV6)
93 struct sockaddr_in6 sa6;
94#else
95#if defined(LWS_ESP_PLATFORM)
96 uint8_t _pad_sa6[28];
97#endif
98#endif
101
102#define sa46_sockaddr(_sa46) ((struct sockaddr *)(_sa46))
103
104#if defined(LWS_WITH_IPV6)
105#define sa46_socklen(_sa46) (socklen_t)((_sa46)->sa4.sin_family == AF_INET ? \
106 sizeof(struct sockaddr_in) : \
107 sizeof(struct sockaddr_in6))
108#define sa46_sockport(_sa46, _sp) { if ((_sa46)->sa4.sin_family == AF_INET) \
109 (_sa46)->sa4.sin_port = (_sp); else \
110 (_sa46)->sa6.sin6_port = (_sp); }
111#define sa46_address(_sa46) ((uint8_t *)((_sa46)->sa4.sin_family == AF_INET ? \
112 &_sa46->sa4.sin_addr : &_sa46->sa6.sin6_addr ))
113#else
114#define sa46_socklen(_sa46) (socklen_t)sizeof(struct sockaddr_in)
115#define sa46_sockport(_sa46, _sp) (_sa46)->sa4.sin_port = (_sp)
116#define sa46_address(_sa46) (uint8_t *)&_sa46->sa4.sin_addr
117#endif
118
119#define sa46_address_len(_sa46) ((_sa46)->sa4.sin_family == AF_INET ? 4 : 16)
120
121#if defined(LWS_WITH_UDP)
122struct lws_udp {
123 lws_sockaddr46 sa46;
124 lws_sockaddr46 sa46_pending;
125 uint8_t connected:1;
126};
127#endif
128
148LWS_VISIBLE LWS_EXTERN struct lws *
150 lws_sock_file_fd_type fd, const char *vh_prot_name,
151 struct lws *parent);
152
161lws_get_socket_fd(struct lws *wsi);
162
170LWS_VISIBLE LWS_EXTERN const struct lws_udp * LWS_WARN_UNUSED_RESULT
171lws_get_udp(const struct lws *wsi);
172
173#if defined(LWS_WITH_TLS) && !defined(LWS_WITH_MBEDTLS) && !defined(LWS_WITH_BEARSSL)
181lws_get_ssl(struct lws *wsi);
182#endif
183
184/*
185 * A transport under IO, in place of the socket. IO still owns the wsi's
186 * place in the poll set (the fd is what the loop watches), but the bytes
187 * of a connection with a transport set go through these instead of recv,
188 * send, recvmsg and sendto, below the tls record layer: a connection in
189 * the clear exchanges its protocol bytes with the transport, one with tls
190 * its ciphertext. This is how a test drives the sansIO half with no
191 * network under it (api-test-sansio), and how an embedder carries lws over
192 * something that is not a socket.
193 *
194 * read and write follow lws_ssl_capable_read() / write(): bytes moved, or
195 * LWS_SSL_CAPABLE_MORE_SERVICE_READ / _WRITE when nothing can move now, or
196 * LWS_SSL_CAPABLE_ERROR; a read of 0 is the peer closing. recv_dgram
197 * returns the datagram's length with its peer and ECN bits, or 0 when
198 * there is none; send_dgram as lws_io_send_dgram(). Either datagram op
199 * may be NULL when the transport carries streams only.
200 */
201typedef struct lws_transport_ops {
202 int (*read)(struct lws *wsi, void *opaque, uint8_t *buf, size_t len);
203 int (*write)(struct lws *wsi, void *opaque, const uint8_t *buf,
204 size_t len);
205 int (*recv_dgram)(struct lws *wsi, void *opaque, uint8_t *buf,
206 size_t len, lws_sockaddr46 *peer, uint8_t *ecn);
207 int (*send_dgram)(struct lws *wsi, void *opaque, const uint8_t *buf,
208 size_t len, const lws_sockaddr46 *dest);
210
219lws_set_transport(struct lws *wsi, const lws_transport_ops_t *ops,
220 void *opaque);
221
238
261LWS_VISIBLE LWS_EXTERN struct lws *
263
287LWS_VISIBLE LWS_EXTERN struct lws *
288lws_adopt_socket_readbuf(struct lws_context *context, lws_sockfd_type accept_fd,
289 const char *readbuf, size_t len);
312LWS_VISIBLE LWS_EXTERN struct lws *
313lws_adopt_socket_vhost_readbuf(struct lws_vhost *vhost,
314 lws_sockfd_type accept_fd, const char *readbuf,
315 size_t len);
316
317#define LWS_CAUDP_BIND (1 << 0)
318#define LWS_CAUDP_BROADCAST (1 << 1)
319#define LWS_CAUDP_PF_PACKET (1 << 2)
320
321#if defined(LWS_WITH_UDP)
343LWS_VISIBLE LWS_EXTERN struct lws *
344lws_create_adopt_udp(struct lws_vhost *vhost, const char *ads, int port,
345 int flags, const char *protocol_name, const char *ifname,
346 struct lws *parent_wsi, void *opaque,
347 const lws_retry_bo_t *retry_policy, const char *fi_wsi_name);
348#endif
349
350
351
const char * fi_wsi_name
Definition lws-adopt.h:234
struct lws * parent
Definition lws-adopt.h:230
struct sockaddr_in sa4
Definition lws-adopt.h:99
const char * vh_prot_name
Definition lws-adopt.h:228
lws_sockfd_type sockfd
Definition lws-adopt.h:83
lws_filefd_type filefd
Definition lws-adopt.h:84
lws_sock_file_fd_type fd
Definition lws-adopt.h:226
lws_adoption_type type
Definition lws-adopt.h:224
struct lws_vhost * vh
Definition lws-adopt.h:223
LWS_VISIBLE LWS_EXTERN struct lws * lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type, lws_sock_file_fd_type fd, const char *vh_prot_name, struct lws *parent)
LWS_VISIBLE LWS_EXTERN struct lws * lws_adopt_socket_vhost_readbuf(struct lws_vhost *vhost, lws_sockfd_type accept_fd, const char *readbuf, size_t len)
LWS_VISIBLE LWS_EXTERN const struct lws_udp *LWS_WARN_UNUSED_RESULT lws_get_udp(const struct lws *wsi)
LWS_VISIBLE LWS_EXTERN struct lws * lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd)
struct lws_adopt_desc lws_adopt_desc_t
LWS_VISIBLE LWS_EXTERN struct lws * lws_adopt_socket_readbuf(struct lws_context *context, lws_sockfd_type accept_fd, const char *readbuf, size_t len)
LWS_VISIBLE LWS_EXTERN lws_sockfd_type lws_get_socket_fd(struct lws *wsi)
lws_adoption_type
Definition lws-adopt.h:67
LWS_VISIBLE LWS_EXTERN struct lws * lws_adopt_socket_vhost(struct lws_vhost *vh, lws_sockfd_type accept_fd)
LWS_VISIBLE LWS_EXTERN struct lws * lws_adopt_descriptor_vhost_via_info(const lws_adopt_desc_t *info)
struct lws_transport_ops lws_transport_ops_t
LWS_VISIBLE LWS_EXTERN void lws_set_transport(struct lws *wsi, const lws_transport_ops_t *ops, void *opaque)
@ LWS_ADOPT_HTTP
Definition lws-adopt.h:69
@ LWS_ADOPT_SOCKET
Definition lws-adopt.h:70
@ LWS_ADOPT_FLAG_RAW_PROXY
Definition lws-adopt.h:73
@ LWS_ADOPT_FLAG_NO_NONBLOCK
Definition lws-adopt.h:74
@ LWS_ADOPT_RAW_FILE_DESC
Definition lws-adopt.h:68
@ LWS_ADOPT_ALLOW_SSL
Definition lws-adopt.h:71
@ LWS_ADOPT_FLAG_UDP
Definition lws-adopt.h:72
@ LWS_ADOPT_RAW_SOCKET_UDP
Definition lws-adopt.h:79
#define LWS_EXTERN
unsigned char uint8_t
int lws_sockfd_type
#define LWS_WARN_UNUSED_RESULT
#define LWS_VISIBLE
int lws_filefd_type
struct lws_retry_bo lws_retry_bo_t
int(* read)(struct lws *wsi, void *opaque, uint8_t *buf, size_t len)
Definition lws-adopt.h:202
int(* write)(struct lws *wsi, void *opaque, const uint8_t *buf, size_t len)
Definition lws-adopt.h:203
int(* recv_dgram)(struct lws *wsi, void *opaque, uint8_t *buf, size_t len, lws_sockaddr46 *peer, uint8_t *ecn)
Definition lws-adopt.h:205
int(* send_dgram)(struct lws *wsi, void *opaque, const uint8_t *buf, size_t len, const lws_sockaddr46 *dest)
Definition lws-adopt.h:207