libwebsockets
Lightweight C library for HTML5 websockets
lws-adopt.h
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 
33 
48 LWS_VISIBLE LWS_EXTERN struct lws *
49 lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd);
63 LWS_VISIBLE LWS_EXTERN struct lws *
64 lws_adopt_socket_vhost(struct lws_vhost *vh, lws_sockfd_type accept_fd);
65 
66 typedef enum {
67  LWS_ADOPT_RAW_FILE_DESC = 0, /* convenience constant */
68  LWS_ADOPT_HTTP = 1, /* flag: absent implies RAW */
69  LWS_ADOPT_SOCKET = 2, /* flag: absent implies file descr */
70  LWS_ADOPT_ALLOW_SSL = 4, /* flag: if set requires LWS_ADOPT_SOCKET */
71  LWS_ADOPT_FLAG_UDP = 16, /* flag: socket is UDP */
72  LWS_ADOPT_FLAG_RAW_PROXY = 32, /* flag: raw proxy */
73 
74  LWS_ADOPT_RAW_SOCKET_UDP = LWS_ADOPT_SOCKET | LWS_ADOPT_FLAG_UDP,
75 } lws_adoption_type;
76 
77 typedef union {
78  lws_sockfd_type sockfd;
79  lws_filefd_type filefd;
81 
82 #if defined(LWS_WITH_UDP)
83 struct lws_udp {
84  struct sockaddr sa;
85  socklen_t salen;
86 
87  struct sockaddr sa_pending;
88  socklen_t salen_pending;
89 };
90 #endif
91 
111 LWS_VISIBLE LWS_EXTERN struct lws *
112 lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type,
113  lws_sock_file_fd_type fd, const char *vh_prot_name,
114  struct lws *parent);
115 
116 typedef struct lws_adopt_desc {
117  struct lws_vhost *vh;
118  lws_adoption_type type;
120  const char *vh_prot_name;
121  struct lws *parent;
122  void *opaque;
124 
147 LWS_VISIBLE LWS_EXTERN struct lws *
149 
173 LWS_VISIBLE LWS_EXTERN struct lws *
174 lws_adopt_socket_readbuf(struct lws_context *context, lws_sockfd_type accept_fd,
175  const char *readbuf, size_t len);
198 LWS_VISIBLE LWS_EXTERN struct lws *
199 lws_adopt_socket_vhost_readbuf(struct lws_vhost *vhost,
200  lws_sockfd_type accept_fd, const char *readbuf,
201  size_t len);
202 
203 #define LWS_CAUDP_BIND (1 << 0)
204 #define LWS_CAUDP_BROADCAST (1 << 1)
205 #define LWS_CAUDP_PF_PACKET (1 << 2)
206 
207 #if defined(LWS_WITH_UDP)
208 
224 LWS_VISIBLE LWS_EXTERN struct lws *
225 lws_create_adopt_udp(struct lws_vhost *vhost, const char *ads, int port,
226  int flags, const char *protocol_name, const char *ifname,
227  struct lws *parent_wsi, void *opaque,
228  const lws_retry_bo_t *retry_policy);
229 #endif
230 
231 
232 
lws_adopt_desc::parent
struct lws * parent
Definition: lws-adopt.h:121
lws_adopt_desc::fd
lws_sock_file_fd_type fd
Definition: lws-adopt.h:119
lws_adopt_desc::vh_prot_name
const char * vh_prot_name
Definition: lws-adopt.h:120
lws_adopt_socket_vhost
LWS_VISIBLE LWS_EXTERN struct lws * lws_adopt_socket_vhost(struct lws_vhost *vh, lws_sockfd_type accept_fd)
lws_adopt_socket
LWS_VISIBLE LWS_EXTERN struct lws * lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd)
lws_adopt_desc::vh
struct lws_vhost * vh
Definition: lws-adopt.h:117
lws_adopt_desc::type
lws_adoption_type type
Definition: lws-adopt.h:118
lws_adopt_desc
Definition: lws-adopt.h:116
lws_adopt_socket_readbuf
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_adopt_descriptor_vhost
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_sock_file_fd_type
Definition: lws-adopt.h:77
lws_adopt_socket_vhost_readbuf
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_retry_bo
Definition: lws-retry.h:25
lws_adopt_descriptor_vhost_via_info
LWS_VISIBLE LWS_EXTERN struct lws * lws_adopt_descriptor_vhost_via_info(const lws_adopt_desc_t *info)
lws_adopt_desc::opaque
void * opaque
Definition: lws-adopt.h:122