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-2018 Andy Green <andy@warmcat.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation:
9  * version 2.1 of the License.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301 USA
20  *
21  * included from libwebsockets.h
22  */
23 
32 
47 LWS_VISIBLE LWS_EXTERN struct lws *
48 lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd);
62 LWS_VISIBLE LWS_EXTERN struct lws *
63 lws_adopt_socket_vhost(struct lws_vhost *vh, lws_sockfd_type accept_fd);
64 
65 typedef enum {
66  LWS_ADOPT_RAW_FILE_DESC = 0, /* convenience constant */
67  LWS_ADOPT_HTTP = 1, /* flag: absent implies RAW */
68  LWS_ADOPT_SOCKET = 2, /* flag: absent implies file descr */
69  LWS_ADOPT_ALLOW_SSL = 4, /* flag: if set requires LWS_ADOPT_SOCKET */
70  LWS_ADOPT_FLAG_UDP = 16, /* flag: socket is UDP */
71 
72  LWS_ADOPT_RAW_SOCKET_UDP = LWS_ADOPT_SOCKET | LWS_ADOPT_FLAG_UDP,
73 } lws_adoption_type;
74 
75 typedef union {
76  lws_sockfd_type sockfd;
77  lws_filefd_type filefd;
79 
80 #if !defined(LWS_WITH_ESP32)
81 struct lws_udp {
82  struct sockaddr sa;
83  socklen_t salen;
84 
85  struct sockaddr sa_pending;
86  socklen_t salen_pending;
87 };
88 #endif
89 
90 /*
91 * lws_adopt_descriptor_vhost() - adopt foreign socket or file descriptor
92 * if socket descriptor, should already have been accepted from listen socket
93 *
94 * \param vhost: lws vhost
95 * \param type: OR-ed combinations of lws_adoption_type flags
96 * \param fd: union with either .sockfd or .filefd set
97 * \param vh_prot_name: NULL or vh protocol name to bind raw connection to
98 * \param parent: NULL or struct lws to attach new_wsi to as a child
99 *
100 * Either returns new wsi bound to accept_fd, or closes accept_fd and
101 * returns NULL, having cleaned up any new wsi pieces.
102 *
103 * If LWS_ADOPT_SOCKET is set, LWS adopts the socket in http serving mode, it's
104 * ready to accept an upgrade to ws or just serve http.
105 *
106 * parent may be NULL, if given it should be an existing wsi that will become the
107 * parent of the new wsi created by this call.
108 */
109 LWS_VISIBLE LWS_EXTERN struct lws *
110 lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type,
111  lws_sock_file_fd_type fd, const char *vh_prot_name,
112  struct lws *parent);
113 
137 LWS_VISIBLE LWS_EXTERN struct lws *
138 lws_adopt_socket_readbuf(struct lws_context *context, lws_sockfd_type accept_fd,
139  const char *readbuf, size_t len);
163 LWS_VISIBLE LWS_EXTERN struct lws *
164 lws_adopt_socket_vhost_readbuf(struct lws_vhost *vhost,
165  lws_sockfd_type accept_fd, const char *readbuf,
166  size_t len);
167 
168 #define LWS_CAUDP_BIND 1
169 
182 LWS_VISIBLE LWS_EXTERN struct lws *
183 lws_create_adopt_udp(struct lws_vhost *vhost, int port, int flags,
184  const char *protocol_name, struct lws *parent_wsi);
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_udp
Definition: lws-adopt.h:81
lws_create_adopt_udp
LWS_VISIBLE LWS_EXTERN struct lws * lws_create_adopt_udp(struct lws_vhost *vhost, int port, int flags, const char *protocol_name, struct lws *parent_wsi)
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_sock_file_fd_type
Definition: lws-adopt.h:75
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)