maph 1.0.0 High-Performance Memory-Mapped Key-Value Database with O(1) Lookups

Loading...
Searching...
No Matches
libusockets.h
Go to the documentation of this file.
1/*
2 * Authored by Alex Hultman, 2018-2019.
3 * Intellectual property of third-party.
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef LIBUSOCKETS_H
19#define LIBUSOCKETS_H
20
21/* 512kb shared receive buffer */
22#define LIBUS_RECV_BUFFER_LENGTH 524288
23/* A timeout granularity of 4 seconds means give or take 4 seconds from set timeout */
24#define LIBUS_TIMEOUT_GRANULARITY 4
25/* 32 byte padding of receive buffer ends */
26#define LIBUS_RECV_BUFFER_PADDING 32
27/* Guaranteed alignment of extension memory */
28#define LIBUS_EXT_ALIGNMENT 16
29
30/* Define what a socket descriptor is based on platform */
31#ifdef _WIN32
32#ifndef NOMINMAX
33#define NOMINMAX
34#endif
35#include <winsock2.h>
36#define LIBUS_SOCKET_DESCRIPTOR SOCKET
37#else
38#define LIBUS_SOCKET_DESCRIPTOR int
39#endif
40
41#ifdef __cplusplus
42 extern "C" {
43#endif
44
45 enum {
46 /* No meaning, default listen option */
47 LIBUS_LISTEN_DEFAULT,
48 /* We exclusively own this port, do not share it */
49 LIBUS_LISTEN_EXCLUSIVE_PORT
50};
51
52/* Library types publicly available */
53 struct us_socket_t;
54 struct us_timer_t;
55 struct us_socket_context_t;
56 struct us_loop_t;
57 struct us_poll_t;
58 struct us_udp_socket_t;
59 struct us_udp_packet_buffer_t;
60
61/* Public interface for UDP sockets */
62
63/* Peeks data and length of UDP payload */
64 char *us_udp_packet_buffer_payload(struct us_udp_packet_buffer_t *buf, int index);
65 int us_udp_packet_buffer_payload_length(struct us_udp_packet_buffer_t *buf, int index);
66
67/* Copies out local (received destination) ip (4 or 16 bytes) of received packet */
68 int us_udp_packet_buffer_local_ip(struct us_udp_packet_buffer_t *buf, int index, char *ip);
69
70/* Get the bound port in host byte order */
71 int us_udp_socket_bound_port(struct us_udp_socket_t *s);
72
73/* Peeks peer addr (sockaddr) of received packet */
74 char *us_udp_packet_buffer_peer(struct us_udp_packet_buffer_t *buf, int index);
75
76/* Peeks ECN of received packet */
77 int us_udp_packet_buffer_ecn(struct us_udp_packet_buffer_t *buf, int index);
78
79/* Receives a set of packets into specified packet buffer */
80 int us_udp_socket_receive(struct us_udp_socket_t *s, struct us_udp_packet_buffer_t *buf);
81
82 void us_udp_buffer_set_packet_payload(struct us_udp_packet_buffer_t *send_buf, int index, int offset, void *payload, int length, void *peer_addr);
83
84 int us_udp_socket_send(struct us_udp_socket_t *s, struct us_udp_packet_buffer_t *buf, int num);
85
86/* Allocates a packet buffer that is reuable per thread. Mutated by us_udp_socket_receive. */
87 struct us_udp_packet_buffer_t *us_create_udp_packet_buffer();
88
89/* Creates a (heavy-weight) UDP socket with a user space ring buffer. Again, this one is heavy weight and
90 * shoud be reused. One entire QUIC server can be implemented using only one single UDP socket so weight
91 * is not a concern as is the case for TCP sockets which are 1-to-1 with TCP connections. */
92//struct us_udp_socket_t *us_create_udp_socket(struct us_loop_t *loop, void (*read_cb)(struct us_udp_socket_t *), unsigned short port);
93
94//struct us_udp_socket_t *us_create_udp_socket(struct us_loop_t *loop, void (*data_cb)(struct us_udp_socket_t *, struct us_udp_packet_buffer_t *, int), void (*drain_cb)(struct us_udp_socket_t *), char *host, unsigned short port);
95
96 struct us_udp_socket_t *us_create_udp_socket(struct us_loop_t *loop, struct us_udp_packet_buffer_t *buf, void (*data_cb)(struct us_udp_socket_t *, struct us_udp_packet_buffer_t *, int), void (*drain_cb)(struct us_udp_socket_t *), const char *host, unsigned short port, void *user);
97
98/* This one is ugly, should be ext! not user */
99 void *us_udp_socket_user(struct us_udp_socket_t *s);
100
101/* Binds the UDP socket to an interface and port */
102 int us_udp_socket_bind(struct us_udp_socket_t *s, const char *hostname, unsigned int port);
103
104/* Public interfaces for timers */
105
106/* Create a new high precision, low performance timer. May fail and return null */
107 struct us_timer_t *us_create_timer(struct us_loop_t *loop, int fallthrough, unsigned int ext_size);
108
109/* Returns user data extension for this timer */
110 void *us_timer_ext(struct us_timer_t *timer);
111
112/* */
113 void us_timer_close(struct us_timer_t *timer);
114
115/* Arm a timer with a delay from now and eventually a repeat delay.
116 * Specify 0 as repeat delay to disable repeating. Specify both 0 to disarm. */
117 void us_timer_set(struct us_timer_t *timer, void (*cb)(struct us_timer_t *t), int ms, int repeat_ms);
118
119/* Returns the loop for this timer */
120 struct us_loop_t *us_timer_loop(struct us_timer_t *t);
121
122/* Public interfaces for contexts */
123
124 struct us_socket_context_options_t {
125 const char *key_file_name;
126 const char *cert_file_name;
127 const char *passphrase;
128 const char *dh_params_file_name;
129 const char *ca_file_name;
130 const char *ssl_ciphers;
131 int ssl_prefer_low_memory_usage; /* Todo: rename to prefer_low_memory_usage and apply for TCP as well */
132};
133
134/* Return 15-bit timestamp for this context */
135 unsigned short us_socket_context_timestamp(int ssl, struct us_socket_context_t *context);
136
137/* Adds SNI domain and cert in asn1 format */
138 void us_socket_context_add_server_name(int ssl, struct us_socket_context_t *context, const char *hostname_pattern, struct us_socket_context_options_t options, void *user);
139 void us_socket_context_remove_server_name(int ssl, struct us_socket_context_t *context, const char *hostname_pattern);
140 void us_socket_context_on_server_name(int ssl, struct us_socket_context_t *context, void (*cb)(struct us_socket_context_t *, const char *hostname));
141 void *us_socket_server_name_userdata(int ssl, struct us_socket_t *s);
142 void *us_socket_context_find_server_name_userdata(int ssl, struct us_socket_context_t *context, const char *hostname_pattern);
143
144/* Returns the underlying SSL native handle, such as SSL_CTX or nullptr */
145 void *us_socket_context_get_native_handle(int ssl, struct us_socket_context_t *context);
146
147/* A socket context holds shared callbacks and user data extension for associated sockets */
148 struct us_socket_context_t *us_create_socket_context(int ssl, struct us_loop_t *loop,
149 int ext_size, struct us_socket_context_options_t options);
150
151/* Delete resources allocated at creation time. */
152 void us_socket_context_free(int ssl, struct us_socket_context_t *context);
153
154/* Setters of various async callbacks */
155 void us_socket_context_on_open(int ssl, struct us_socket_context_t *context,
156 struct us_socket_t *(*on_open)(struct us_socket_t *s, int is_client, char *ip, int ip_length));
157 void us_socket_context_on_close(int ssl, struct us_socket_context_t *context,
158 struct us_socket_t *(*on_close)(struct us_socket_t *s, int code, void *reason));
159 void us_socket_context_on_data(int ssl, struct us_socket_context_t *context,
160 struct us_socket_t *(*on_data)(struct us_socket_t *s, char *data, int length));
161 void us_socket_context_on_writable(int ssl, struct us_socket_context_t *context,
162 struct us_socket_t *(*on_writable)(struct us_socket_t *s));
163 void us_socket_context_on_timeout(int ssl, struct us_socket_context_t *context,
164 struct us_socket_t *(*on_timeout)(struct us_socket_t *s));
165 void us_socket_context_on_long_timeout(int ssl, struct us_socket_context_t *context,
166 struct us_socket_t *(*on_timeout)(struct us_socket_t *s));
167/* This one is only used for when a connecting socket fails in a late stage. */
168 void us_socket_context_on_connect_error(int ssl, struct us_socket_context_t *context,
169 struct us_socket_t *(*on_connect_error)(struct us_socket_t *s, int code));
170
171/* Emitted when a socket has been half-closed */
172 void us_socket_context_on_end(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_end)(struct us_socket_t *s));
173
174/* Returns user data extension for this socket context */
175 void *us_socket_context_ext(int ssl, struct us_socket_context_t *context);
176
177/* Closes all open sockets, including listen sockets. Does not invalidate the socket context. */
178 void us_socket_context_close(int ssl, struct us_socket_context_t *context);
179
180/* Listen for connections. Acts as the main driving cog in a server. Will call set async callbacks. */
181 struct us_listen_socket_t *us_socket_context_listen(int ssl, struct us_socket_context_t *context,
182 const char *host, int port, int options, int socket_ext_size);
183
184 struct us_listen_socket_t *us_socket_context_listen_unix(int ssl, struct us_socket_context_t *context,
185 const char *path, int options, int socket_ext_size);
186
187/* listen_socket.c/.h */
188 void us_listen_socket_close(int ssl, struct us_listen_socket_t *ls);
189
190/* Land in on_open or on_connection_error or return null or return socket */
191 struct us_socket_t *us_socket_context_connect(int ssl, struct us_socket_context_t *context,
192 const char *host, int port, const char *source_host, int options, int socket_ext_size);
193
194 struct us_socket_t *us_socket_context_connect_unix(int ssl, struct us_socket_context_t *context,
195 const char *server_path, int options, int socket_ext_size);
196
197/* Is this socket established? Can be used to check if a connecting socket has fired the on_open event yet.
198 * Can also be used to determine if a socket is a listen_socket or not, but you probably know that already. */
199 int us_socket_is_established(int ssl, struct us_socket_t *s);
200
201/* Cancel a connecting socket. Can be used together with us_socket_timeout to limit connection times.
202 * Entirely destroys the socket - this function works like us_socket_close but does not trigger on_close event since
203 * you never got the on_open event first. */
204 struct us_socket_t *us_socket_close_connecting(int ssl, struct us_socket_t *s);
205
206/* Returns the loop for this socket context. */
207 struct us_loop_t *us_socket_context_loop(int ssl, struct us_socket_context_t *context);
208
209/* Invalidates passed socket, returning a new resized socket which belongs to a different socket context.
210 * Used mainly for "socket upgrades" such as when transitioning from HTTP to WebSocket. */
211 struct us_socket_t *us_socket_context_adopt_socket(int ssl, struct us_socket_context_t *context, struct us_socket_t *s, int ext_size);
212
213/* Create a child socket context which acts much like its own socket context with its own callbacks yet still relies on the
214 * parent socket context for some shared resources. Child socket contexts should be used together with socket adoptions and nothing else. */
215 struct us_socket_context_t *us_create_child_socket_context(int ssl, struct us_socket_context_t *context, int context_ext_size);
216
217/* Public interfaces for loops */
218
219/* Returns a new event loop with user data extension */
220 struct us_loop_t *us_create_loop(void *hint, void (*wakeup_cb)(struct us_loop_t *loop),
221 void (*pre_cb)(struct us_loop_t *loop), void (*post_cb)(struct us_loop_t *loop), unsigned int ext_size);
222
223/* Frees the loop immediately */
224 void us_loop_free(struct us_loop_t *loop);
225
226/* Returns the loop user data extension */
227 void *us_loop_ext(struct us_loop_t *loop);
228
229/* Blocks the calling thread and drives the event loop until no more non-fallthrough polls are scheduled */
230 void us_loop_run(struct us_loop_t *loop);
231
232/* Signals the loop from any thread to wake up and execute its wakeup handler from the loop's own running thread.
233 * This is the only fully thread-safe function and serves as the basis for thread safety */
234 void us_wakeup_loop(struct us_loop_t *loop);
235
236/* Hook up timers in existing loop */
237 void us_loop_integrate(struct us_loop_t *loop);
238
239/* Returns the loop iteration number */
240 long long us_loop_iteration_number(struct us_loop_t *loop);
241
242/* Public interfaces for polls */
243
244/* A fallthrough poll does not keep the loop running, it falls through */
245 struct us_poll_t *us_create_poll(struct us_loop_t *loop, int fallthrough, unsigned int ext_size);
246
247/* After stopping a poll you must manually free the memory */
248 void us_poll_free(struct us_poll_t *p, struct us_loop_t *loop);
249
250/* Associate this poll with a socket descriptor and poll type */
251 void us_poll_init(struct us_poll_t *p, LIBUS_SOCKET_DESCRIPTOR fd, int poll_type);
252
253/* Start, change and stop polling for events */
254 void us_poll_start(struct us_poll_t *p, struct us_loop_t *loop, int events);
255 void us_poll_change(struct us_poll_t *p, struct us_loop_t *loop, int events);
256 void us_poll_stop(struct us_poll_t *p, struct us_loop_t *loop);
257
258/* Return what events we are polling for */
259 int us_poll_events(struct us_poll_t *p);
260
261/* Returns the user data extension of this poll */
262 void *us_poll_ext(struct us_poll_t *p);
263
264/* Get associated socket descriptor from a poll */
265 LIBUS_SOCKET_DESCRIPTOR us_poll_fd(struct us_poll_t *p);
266
267/* Resize an active poll */
268 struct us_poll_t *us_poll_resize(struct us_poll_t *p, struct us_loop_t *loop, unsigned int ext_size);
269
270/* Public interfaces for sockets */
271
272/* Returns the underlying native handle for a socket, such as SSL or file descriptor.
273 * In the case of file descriptor, the value of pointer is fd. */
274 void *us_socket_get_native_handle(int ssl, struct us_socket_t *s);
275
276/* Write up to length bytes of data. Returns actual bytes written.
277 * Will call the on_writable callback of active socket context on failure to write everything off in one go.
278 * Set hint msg_more if you have more immediate data to write. */
279 int us_socket_write(int ssl, struct us_socket_t *s, const char *data, int length, int msg_more);
280
281/* Set a low precision, high performance timer on a socket. A socket can only have one single active timer
282 * at any given point in time. Will remove any such pre set timer */
283 void us_socket_timeout(int ssl, struct us_socket_t *s, unsigned int seconds);
284
285/* Set a low precision, high performance timer on a socket. Suitable for per-minute precision. */
286 void us_socket_long_timeout(int ssl, struct us_socket_t *s, unsigned int minutes);
287
288/* Return the user data extension of this socket */
289 void *us_socket_ext(int ssl, struct us_socket_t *s);
290
291/* Return the socket context of this socket */
292 struct us_socket_context_t *us_socket_context(int ssl, struct us_socket_t *s);
293
294/* Withdraw any msg_more status and flush any pending data */
295 void us_socket_flush(int ssl, struct us_socket_t *s);
296
297/* Shuts down the connection by sending FIN and/or close_notify */
298 void us_socket_shutdown(int ssl, struct us_socket_t *s);
299
300/* Shuts down the connection in terms of read, meaning next event loop
301 * iteration will catch the socket being closed. Can be used to defer closing
302 * to next event loop iteration. */
303 void us_socket_shutdown_read(int ssl, struct us_socket_t *s);
304
305/* Returns whether the socket has been shut down or not */
306 int us_socket_is_shut_down(int ssl, struct us_socket_t *s);
307
308/* Returns whether this socket has been closed. Only valid if memory has not yet been released. */
309 int us_socket_is_closed(int ssl, struct us_socket_t *s);
310
311/* Immediately closes the socket */
312 struct us_socket_t *us_socket_close(int ssl, struct us_socket_t *s, int code, void *reason);
313
314/* Returns local port or -1 on failure. */
315 int us_socket_local_port(int ssl, struct us_socket_t *s);
316
317/* Copy remote (IP) address of socket, or fail with zero length. */
318 void us_socket_remote_address(int ssl, struct us_socket_t *s, char *buf, int *length);
319
320#ifdef __cplusplus
321}
322#endif
323
324/* Decide what eventing system to use by default */
325#if !defined(LIBUS_USE_EPOLL) && !defined(LIBUS_USE_LIBUV) && !defined(LIBUS_USE_GCD) && !defined(LIBUS_USE_KQUEUE) && !defined(LIBUS_USE_ASIO)
326#if defined(_WIN32)
327#define LIBUS_USE_LIBUV
328#elif defined(__APPLE__) || defined(__FreeBSD__)
329#define LIBUS_USE_KQUEUE
330#else
331#define LIBUS_USE_EPOLL
332#endif
333#endif
334
335#endif // LIBUSOCKETS_H
us_socket_t::context
struct us_socket_context_t * context
Definition internal.h:94
us_listen_socket_t::socket_ext_size
unsigned int socket_ext_size
Definition internal.h:110
us_listen_socket_t
Definition internal.h:108
us_socket_t
Definition internal.h:89
us_loop_iteration_number
long long us_loop_iteration_number(struct us_loop_t *loop)
Definition loop.c:179
us_create_timer
struct us_timer_t * us_create_timer(struct us_loop_t *loop, int fallthrough, unsigned int ext_size)
us_socket_context_listen
struct us_listen_socket_t * us_socket_context_listen(int ssl, struct us_socket_context_t *context, const char *host, int port, int options, int socket_ext_size)
Definition context.c:248
us_create_udp_packet_buffer
struct us_udp_packet_buffer_t * us_create_udp_packet_buffer()
Definition udp.c:63
us_socket_context_remove_server_name
void us_socket_context_remove_server_name(int ssl, struct us_socket_context_t *context, const char *hostname_pattern)
Definition context.c:167
us_socket_is_established
int us_socket_is_established(int ssl, struct us_socket_t *s)
Definition socket.c:80
us_socket_remote_address
void us_socket_remote_address(int ssl, struct us_socket_t *s, char *buf, int *length)
Definition socket.c:40
us_socket_context_listen_unix
struct us_listen_socket_t * us_socket_context_listen_unix(int ssl, struct us_socket_context_t *context, const char *path, int options, int socket_ext_size)
Definition context.c:279
us_socket_context_on_server_name
void us_socket_context_on_server_name(int ssl, struct us_socket_context_t *context, void(*cb)(struct us_socket_context_t *, const char *hostname))
Definition context.c:180
us_socket_write
int us_socket_write(int ssl, struct us_socket_t *s, const char *data, int length, int msg_more)
Definition socket.c:147
us_wakeup_loop
void us_wakeup_loop(struct us_loop_t *loop)
Definition loop.c:53
us_poll_init
void us_poll_init(struct us_poll_t *p, int fd, int poll_type)
us_udp_socket_user
void * us_udp_socket_user(struct us_udp_socket_t *s)
Definition udp.c:98
LIBUS_SOCKET_DESCRIPTOR
#define LIBUS_SOCKET_DESCRIPTOR
Definition libusockets.h:38
us_socket_context_on_timeout
void us_socket_context_on_timeout(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_timeout)(struct us_socket_t *s))
us_create_poll
struct us_poll_t * us_create_poll(struct us_loop_t *loop, int fallthrough, unsigned int ext_size)
us_socket_close_connecting
struct us_socket_t * us_socket_close_connecting(int ssl, struct us_socket_t *s)
Definition socket.c:86
us_poll_change
void us_poll_change(struct us_poll_t *p, struct us_loop_t *loop, int events)
us_socket_context_options_t::ssl_prefer_low_memory_usage
int ssl_prefer_low_memory_usage
Definition libusockets.h:131
us_udp_socket_receive
int us_udp_socket_receive(struct us_udp_socket_t *s, struct us_udp_packet_buffer_t *buf)
Definition udp.c:54
us_poll_resize
struct us_poll_t * us_poll_resize(struct us_poll_t *p, struct us_loop_t *loop, unsigned int ext_size)
us_socket_context_connect
struct us_socket_t * us_socket_context_connect(int ssl, struct us_socket_context_t *context, const char *host, int port, const char *source_host, int options, int socket_ext_size)
Definition context.c:310
us_udp_packet_buffer_peer
char * us_udp_packet_buffer_peer(struct us_udp_packet_buffer_t *buf, int index)
Definition udp.c:33
us_socket_context_close
void us_socket_context_close(int ssl, struct us_socket_context_t *context)
Definition context.c:51
us_poll_fd
int us_poll_fd(struct us_poll_t *p)
us_socket_context_on_data
void us_socket_context_on_data(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_data)(struct us_socket_t *s, char *data, int length))
Definition context.c:437
us_socket_is_shut_down
int us_socket_is_shut_down(int ssl, struct us_socket_t *s)
Definition socket.c:177
us_socket_shutdown_read
void us_socket_shutdown_read(int ssl, struct us_socket_t *s)
Definition socket.c:35
us_udp_socket_bound_port
int us_udp_socket_bound_port(struct us_udp_socket_t *s)
Definition udp.c:79
us_poll_events
int us_poll_events(struct us_poll_t *p)
us_socket_context_timestamp
unsigned short us_socket_context_timestamp(int ssl, struct us_socket_context_t *context)
Definition context.c:29
us_udp_packet_buffer_local_ip
int us_udp_packet_buffer_local_ip(struct us_udp_packet_buffer_t *buf, int index, char *ip)
Definition udp.c:29
us_socket_server_name_userdata
void * us_socket_server_name_userdata(int ssl, struct us_socket_t *s)
Definition context.c:148
us_create_child_socket_context
struct us_socket_context_t * us_create_child_socket_context(int ssl, struct us_socket_context_t *context, int context_ext_size)
Definition context.c:368
us_socket_context_on_writable
void us_socket_context_on_writable(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_writable)(struct us_socket_t *s))
Definition context.c:448
us_create_socket_context
struct us_socket_context_t * us_create_socket_context(int ssl, struct us_loop_t *loop, int ext_size, struct us_socket_context_options_t options)
Definition context.c:202
us_poll_stop
void us_poll_stop(struct us_poll_t *p, struct us_loop_t *loop)
us_loop_run
void us_loop_run(struct us_loop_t *loop)
us_udp_buffer_set_packet_payload
void us_udp_buffer_set_packet_payload(struct us_udp_packet_buffer_t *send_buf, int index, int offset, void *payload, int length, void *peer_addr)
Definition udp.c:59
us_socket_context_loop
struct us_loop_t * us_socket_context_loop(int ssl, struct us_socket_context_t *context)
Definition context.c:131
us_socket_local_port
int us_socket_local_port(int ssl, struct us_socket_t *s)
Definition socket.c:26
us_socket_context_add_server_name
void us_socket_context_add_server_name(int ssl, struct us_socket_context_t *context, const char *hostname_pattern, struct us_socket_context_options_t options, void *user)
Definition context.c:158
us_socket_context_options_t::ssl_ciphers
const char * ssl_ciphers
Definition libusockets.h:130
us_socket_context_options_t::ca_file_name
const char * ca_file_name
Definition libusockets.h:129
us_listen_socket_close
void us_listen_socket_close(int ssl, struct us_listen_socket_t *ls)
Definition context.c:33
us_socket_flush
void us_socket_flush(int ssl, struct us_socket_t *s)
Definition socket.c:70
us_timer_loop
struct us_loop_t * us_timer_loop(struct us_timer_t *t)
us_udp_packet_buffer_payload_length
int us_udp_packet_buffer_payload_length(struct us_udp_packet_buffer_t *buf, int index)
Definition udp.c:41
us_socket_context_options_t::cert_file_name
const char * cert_file_name
Definition libusockets.h:126
us_socket_get_native_handle
void * us_socket_get_native_handle(int ssl, struct us_socket_t *s)
Definition socket.c:137
us_udp_packet_buffer_ecn
int us_udp_packet_buffer_ecn(struct us_udp_packet_buffer_t *buf, int index)
Definition udp.c:25
us_socket_shutdown
void us_socket_shutdown(int ssl, struct us_socket_t *s)
Definition socket.c:187
LIBUS_LISTEN_EXCLUSIVE_PORT
@ LIBUS_LISTEN_EXCLUSIVE_PORT
Definition libusockets.h:49
LIBUS_LISTEN_DEFAULT
@ LIBUS_LISTEN_DEFAULT
Definition libusockets.h:47
us_timer_close
void us_timer_close(struct us_timer_t *timer)
us_poll_ext
void * us_poll_ext(struct us_poll_t *p)
us_socket_long_timeout
void us_socket_long_timeout(int ssl, struct us_socket_t *s, unsigned int minutes)
Definition socket.c:62
us_socket_context_adopt_socket
struct us_socket_t * us_socket_context_adopt_socket(int ssl, struct us_socket_context_t *context, struct us_socket_t *s, int ext_size)
Definition context.c:381
us_socket_context_on_close
void us_socket_context_on_close(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_close)(struct us_socket_t *s, int code, void *reason))
Definition context.c:426
us_socket_context_options_t::passphrase
const char * passphrase
Definition libusockets.h:127
us_socket_context_options_t::dh_params_file_name
const char * dh_params_file_name
Definition libusockets.h:128
us_socket_context
struct us_socket_context_t * us_socket_context(int ssl, struct us_socket_t *s)
Definition socket.c:50
us_socket_close
struct us_socket_t * us_socket_close(int ssl, struct us_socket_t *s, int code, void *reason)
Definition socket.c:105
us_loop_ext
void * us_loop_ext(struct us_loop_t *loop)
Definition loop.c:360
us_poll_free
void us_poll_free(struct us_poll_t *p, struct us_loop_t *loop)
us_socket_context_get_native_handle
void * us_socket_context_get_native_handle(int ssl, struct us_socket_context_t *context)
Definition context.c:190
us_socket_context_connect_unix
struct us_socket_t * us_socket_context_connect_unix(int ssl, struct us_socket_context_t *context, const char *server_path, int options, int socket_ext_size)
Definition context.c:339
us_socket_context_ext
void * us_socket_context_ext(int ssl, struct us_socket_context_t *context)
Definition context.c:503
us_create_loop
struct us_loop_t * us_create_loop(void *hint, void(*wakeup_cb)(struct us_loop_t *loop), void(*pre_cb)(struct us_loop_t *loop), void(*post_cb)(struct us_loop_t *loop), unsigned int ext_size)
us_socket_context_options_t::key_file_name
const char * key_file_name
Definition libusockets.h:125
us_loop_free
void us_loop_free(struct us_loop_t *loop)
us_udp_packet_buffer_payload
char * us_udp_packet_buffer_payload(struct us_udp_packet_buffer_t *buf, int index)
Definition udp.c:37
us_socket_context_on_end
void us_socket_context_on_end(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_end)(struct us_socket_t *s))
us_udp_socket_bind
int us_udp_socket_bind(struct us_udp_socket_t *s, const char *hostname, unsigned int port)
us_timer_ext
void * us_timer_ext(struct us_timer_t *timer)
us_socket_timeout
void us_socket_timeout(int ssl, struct us_socket_t *s, unsigned int seconds)
Definition socket.c:54
us_udp_socket_send
int us_udp_socket_send(struct us_udp_socket_t *s, struct us_udp_packet_buffer_t *buf, int num)
Definition udp.c:46
us_poll_start
void us_poll_start(struct us_poll_t *p, struct us_loop_t *loop, int events)
us_create_udp_socket
struct us_udp_socket_t * us_create_udp_socket(struct us_loop_t *loop, struct us_udp_packet_buffer_t *buf, void(*data_cb)(struct us_udp_socket_t *, struct us_udp_packet_buffer_t *, int), void(*drain_cb)(struct us_udp_socket_t *), const char *host, unsigned short port, void *user)
Definition udp.c:104
us_socket_context_on_connect_error
void us_socket_context_on_connect_error(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_connect_error)(struct us_socket_t *s, int code))
Definition context.c:492
us_timer_set
void us_timer_set(struct us_timer_t *timer, void(*cb)(struct us_timer_t *t), int ms, int repeat_ms)
us_loop_integrate
void us_loop_integrate(struct us_loop_t *loop)
Definition loop.c:356
us_socket_context_on_long_timeout
void us_socket_context_on_long_timeout(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_timeout)(struct us_socket_t *s))
us_socket_ext
void * us_socket_ext(int ssl, struct us_socket_t *s)
Definition socket.c:167
us_socket_context_find_server_name_userdata
void * us_socket_context_find_server_name_userdata(int ssl, struct us_socket_context_t *context, const char *hostname_pattern)
Definition context.c:138
us_socket_is_closed
int us_socket_is_closed(int ssl, struct us_socket_t *s)
Definition socket.c:76
us_socket_context_on_open
void us_socket_context_on_open(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_open)(struct us_socket_t *s, int is_client, char *ip, int ip_length))
Definition context.c:415
us_socket_context_free
void us_socket_context_free(int ssl, struct us_socket_context_t *context)
Definition context.c:232
us_socket_context_options_t
Definition libusockets.h:124
us_poll_t::fd
LIBUS_SOCKET_DESCRIPTOR fd
Definition asio.h:40
us_poll_t::events
int events
Definition asio.h:42
us_poll_t::poll_type
unsigned char poll_type
Definition asio.h:41
us_poll_t
Definition asio.h:37
us_loop_t
Definition asio.h:26
us_socket_context_t
Definition internal.h:117
us_socket_context_t::on_end
struct us_socket_t *(* on_end)(struct us_socket_t *)
Definition internal.h:134
us_socket_context_t::on_close
struct us_socket_t *(* on_close)(struct us_socket_t *, int code, void *reason)
Definition internal.h:130
us_socket_context_t::loop
struct us_loop_t * loop
Definition internal.h:118
us_socket_context_t::on_data
struct us_socket_t *(* on_data)(struct us_socket_t *, char *data, int length)
Definition internal.h:128
us_socket_context_t::on_writable
struct us_socket_t *(* on_writable)(struct us_socket_t *)
Definition internal.h:129
us_socket_context_t::on_open
struct us_socket_t *(* on_open)(struct us_socket_t *, int is_client, char *ip, int ip_length)
Definition internal.h:127
us_socket_context_t::on_connect_error
struct us_socket_t *(* on_connect_error)(struct us_socket_t *, int code)
Definition internal.h:135