![]() |
libwebsockets
Lightweight C library for HTML5 websockets
|
Data Structures | |
struct | lws_dll |
struct | lws_dll_lws |
Functions | |
LWS_VISIBLE LWS_EXTERN void | lws_dll_add_front (struct lws_dll *d, struct lws_dll *phead) |
LWS_VISIBLE LWS_EXTERN void | lws_dll_remove (struct lws_dll *d) |
LWS_VISIBLE LWS_EXTERN int | lws_buflist_append_segment (struct lws_buflist **head, const uint8_t *buf, size_t len) |
LWS_VISIBLE LWS_EXTERN size_t | lws_buflist_next_segment_len (struct lws_buflist **head, uint8_t **buf) |
LWS_VISIBLE LWS_EXTERN int | lws_buflist_use_segment (struct lws_buflist **head, size_t len) |
LWS_VISIBLE LWS_EXTERN void | lws_buflist_destroy_all_segments (struct lws_buflist **head) |
void | lws_buflist_describe (struct lws_buflist **head, void *id) |
LWS_VISIBLE LWS_EXTERN int | lws_snprintf (char *str, size_t size, const char *format,...) LWS_FORMAT(3) |
LWS_VISIBLE LWS_EXTERN char * | lws_strncpy (char *dest, const char *src, size_t size) |
LWS_VISIBLE LWS_EXTERN int | lws_get_random (struct lws_context *context, void *buf, int len) |
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT | lws_daemonize (const char *_lock_path) |
LWS_VISIBLE LWS_EXTERN const char *LWS_WARN_UNUSED_RESULT | lws_get_library_version (void) |
LWS_VISIBLE LWS_EXTERN void * | lws_wsi_user (struct lws *wsi) |
LWS_VISIBLE LWS_EXTERN void | lws_set_wsi_user (struct lws *wsi, void *user) |
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT | lws_parse_uri (char *p, const char **prot, const char **ads, int *port, const char **path) |
LWS_VISIBLE LWS_EXTERN const char * | lws_cmdline_option (int argc, const char **argv, const char *val) |
LWS_VISIBLE LWS_EXTERN unsigned long | lws_now_secs (void) |
LWS_VISIBLE LWS_EXTERN int | lws_compare_time_t (struct lws_context *context, time_t t1, time_t t2) |
LWS_VISIBLE LWS_EXTERN struct lws_context *LWS_WARN_UNUSED_RESULT | lws_get_context (const struct lws *wsi) |
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT | lws_get_vhost_listen_port (struct lws_vhost *vhost) |
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT | lws_get_count_threads (struct lws_context *context) |
LWS_VISIBLE LWS_EXTERN struct lws *LWS_WARN_UNUSED_RESULT | lws_get_parent (const struct lws *wsi) |
LWS_VISIBLE LWS_EXTERN struct lws *LWS_WARN_UNUSED_RESULT | lws_get_child (const struct lws *wsi) |
LWS_VISIBLE LWS_EXTERN const struct lws_udp *LWS_WARN_UNUSED_RESULT | lws_get_udp (const struct lws *wsi) |
LWS_VISIBLE LWS_EXTERN void | lws_set_parent_carries_io (struct lws *wsi) |
LWS_VISIBLE LWS_EXTERN void * | lws_get_opaque_parent_data (const struct lws *wsi) |
LWS_VISIBLE LWS_EXTERN void | lws_set_opaque_parent_data (struct lws *wsi, void *data) |
LWS_VISIBLE LWS_EXTERN int | lws_get_child_pending_on_writable (const struct lws *wsi) |
LWS_VISIBLE LWS_EXTERN void | lws_clear_child_pending_on_writable (struct lws *wsi) |
LWS_VISIBLE LWS_EXTERN int | lws_get_close_length (struct lws *wsi) |
LWS_VISIBLE LWS_EXTERN unsigned char * | lws_get_close_payload (struct lws *wsi) |
LWS_VISIBLE LWS_EXTERN struct lws * | lws_get_network_wsi (struct lws *wsi) |
LWS_VISIBLE LWS_EXTERN void | lws_set_allocator (void *(*realloc)(void *ptr, size_t size, const char *reason)) |
Various APIs outside of other categories
LWS_VISIBLE LWS_EXTERN int lws_buflist_append_segment | ( | struct lws_buflist ** | head, |
const uint8_t * | buf, | ||
size_t | len | ||
) |
#include <lib/libwebsockets.h>
lws_buflist_append_segment(): add buffer to buflist at head
head | list head |
buf | buffer to stash |
len | length of buffer to stash |
Returns -1 on OOM, 1 if this was the first segment on the list, and 0 if it was a subsequent segment.
LWS_VISIBLE LWS_EXTERN void lws_buflist_destroy_all_segments | ( | struct lws_buflist ** | head | ) |
#include <lib/libwebsockets.h>
lws_buflist_destroy_all_segments(): free all segments on the list
head | list head |
This frees everything on the list unconditionally. *head is always NULL after this.
LWS_VISIBLE LWS_EXTERN size_t lws_buflist_next_segment_len | ( | struct lws_buflist ** | head, |
uint8_t ** | buf | ||
) |
#include <lib/libwebsockets.h>
lws_buflist_next_segment_len(): number of bytes left in current segment
head | list head |
buf | if non-NULL, *buf is written with the address of the start of the remaining data in the segment |
Returns the number of bytes left in the current segment. 0 indicates that the buflist is empty (there are no segments on the buflist).
LWS_VISIBLE LWS_EXTERN int lws_buflist_use_segment | ( | struct lws_buflist ** | head, |
size_t | len | ||
) |
#include <lib/libwebsockets.h>
lws_buflist_use_segment(): remove len bytes from the current segment
head | list head |
len | number of bytes to mark as used |
If len is less than the remaining length of the current segment, the position in the current segment is simply advanced and it returns.
If len uses up the remaining length of the current segment, then the segment is deleted and the list head moves to the next segment if any.
Returns the number of bytes left in the current segment. 0 indicates that the buflist is empty (there are no segments on the buflist).
LWS_VISIBLE LWS_EXTERN const char* lws_cmdline_option | ( | int | argc, |
const char ** | argv, | ||
const char * | val | ||
) |
#include <lib/libwebsockets.h>
lws_cmdline_option(): simple commandline parser
argc | count of argument strings |
argv | argument strings |
val | string to find |
Returns NULL if the string val
is not found in the arguments.
If it is found, then it returns a pointer to the next character after val
. So if val
is "-d", then for the commandlines "myapp -d15" and "myapp -d 15", in both cases the return will point to the "15".
In the case there is no argument, like "myapp -d", the return will either point to the '\0' at the end of -d, or to the start of the next argument, ie, will be non-NULL.
LWS_VISIBLE LWS_EXTERN int lws_compare_time_t | ( | struct lws_context * | context, |
time_t | t1, | ||
time_t | t2 | ||
) |
#include <lib/libwebsockets.h>
lws_compare_time_t(): return relationship between two time_t
context | struct lws_context |
t1 | time_t 1 |
t2 | time_t 2 |
returns <0 if t2 > t1; >0 if t1 > t2; or == 0 if t1 == t2.
This is aware of clock discontiguities that may have affected either t1 or t2 and adapts the comparison for them.
For the discontiguity detection to work, you must avoid any arithmetic on the times being compared. For example to have a timeout that triggers 15s from when it was set, store the time it was set and compare like if (lws_compare_time_t(context, now, set_time) > 15)
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_daemonize | ( | const char * | _lock_path | ) |
#include <lib/libwebsockets.h>
lws_daemonize(): make current process run in the background
_lock_path | the filepath to write the lock file |
Spawn lws as a background process, taking care of various things
LWS_VISIBLE LWS_EXTERN struct lws* LWS_WARN_UNUSED_RESULT lws_get_child | ( | const struct lws * | wsi | ) |
#include <lib/libwebsockets.h>
lws_get_child() - get child wsi or NULL
wsi | lws connection |
Allows you to find a related wsi from the parent wsi.
LWS_VISIBLE LWS_EXTERN struct lws_context* LWS_WARN_UNUSED_RESULT lws_get_context | ( | const struct lws * | wsi | ) |
#include <lib/libwebsockets.h>
lws_get_context - Allow getting lws_context from a Websocket connection instance
With this function, users can access context in the callback function. Otherwise users may have to declare context as a global variable.
wsi | Websocket connection instance |
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_get_count_threads | ( | struct lws_context * | context | ) |
#include <lib/libwebsockets.h>
lws_get_count_threads(): how many service threads the context uses
context | the lws context |
By default this is always 1, if you asked for more than lws can handle it will clip the number of threads. So you can use this to find out how many threads are actually in use.
LWS_VISIBLE LWS_EXTERN const char* LWS_WARN_UNUSED_RESULT lws_get_library_version | ( | void | ) |
#include <lib/libwebsockets.h>
lws_get_library_version(): return string describing the version of lws
On unix, also includes the git describe
LWS_VISIBLE LWS_EXTERN struct lws* lws_get_network_wsi | ( | struct lws * | wsi | ) |
#include <lib/libwebsockets.h>
lws_get_network_wsi() - Returns wsi that has the tcp connection for this wsi
wsi | wsi you have |
Returns wsi that has the tcp connection (which may be the incoming wsi)
HTTP/1 connections will always return the incoming wsi HTTP/2 connections may return a different wsi that has the tcp connection
LWS_VISIBLE LWS_EXTERN struct lws* LWS_WARN_UNUSED_RESULT lws_get_parent | ( | const struct lws * | wsi | ) |
#include <lib/libwebsockets.h>
lws_get_parent() - get parent wsi or NULL
wsi | lws connection |
Specialized wsi like cgi stdin/out/err are associated to a parent wsi, this allows you to get their parent.
LWS_VISIBLE LWS_EXTERN int lws_get_random | ( | struct lws_context * | context, |
void * | buf, | ||
int | len | ||
) |
#include <lib/libwebsockets.h>
lws_get_random(): fill a buffer with platform random data
context | the lws context |
buf | buffer to fill |
len | how much to fill |
This is intended to be called from the LWS_CALLBACK_RECEIVE callback if it's interested to see if the frame it's dealing with was sent in binary mode.
LWS_VISIBLE LWS_EXTERN const struct lws_udp* LWS_WARN_UNUSED_RESULT lws_get_udp | ( | const struct lws * | wsi | ) |
#include <lib/libwebsockets.h>
lws_get_udp() - get wsi's udp struct
wsi | lws connection |
Returns NULL or pointer to the wsi's UDP-specific information
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_get_vhost_listen_port | ( | struct lws_vhost * | vhost | ) |
#include <lib/libwebsockets.h>
lws_get_vhost_listen_port - Find out the port number a vhost is listening on
In the case you passed 0 for the port number at context creation time, you can discover the port number that was actually chosen for the vhost using this api.
vhost | Vhost to get listen port from |
LWS_VISIBLE LWS_EXTERN unsigned long lws_now_secs | ( | void | ) |
#include <lib/libwebsockets.h>
lws_now_secs(): return seconds since 1970-1-1
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_parse_uri | ( | char * | p, |
const char ** | prot, | ||
const char ** | ads, | ||
int * | port, | ||
const char ** | path | ||
) |
#include <lib/libwebsockets.h>
lws_parse_uri: cut up prot:/ads:port/path into pieces Notice it does so by dropping '\0' into input string and the leading / on the path is consequently lost
p | incoming uri string.. will get written to |
prot | result pointer for protocol part (https://) |
ads | result pointer for address part |
port | result pointer for port part |
path | result pointer for path part |
LWS_VISIBLE LWS_EXTERN void lws_set_allocator | ( | void *(*)(void *ptr, size_t size, const char *reason) | realloc | ) |
#include <lib/libwebsockets.h>
lws_set_allocator() - custom allocator support
realloc | Allows you to replace the allocator (and deallocator) used by lws |
LWS_VISIBLE LWS_EXTERN void lws_set_parent_carries_io | ( | struct lws * | wsi | ) |
#include <lib/libwebsockets.h>
lws_parent_carries_io() - mark wsi as needing to send messages via parent
wsi | child lws connection |
LWS_VISIBLE LWS_EXTERN void lws_set_wsi_user | ( | struct lws * | wsi, |
void * | user | ||
) |
#include <lib/libwebsockets.h>
lws_wsi_set_user() - set the user data associated with the client connection
wsi | lws connection |
user | user data |
By default lws allocates this and it's not legal to externally set it yourself. However client connections may have it set externally when the connection is created... if so, this api can be used to modify it at runtime additionally.
LWS_VISIBLE LWS_EXTERN int lws_snprintf | ( | char * | str, |
size_t | size, | ||
const char * | format, | ||
... | |||
) |
#include <lib/libwebsockets.h>
lws_snprintf(): snprintf that truncates the returned length too
str | destination buffer |
size | bytes left in destination buffer |
format | format string |
... | args for format |
This lets you correctly truncate buffers by concatenating lengths, if you reach the limit the reported length doesn't exceed the limit.
LWS_VISIBLE LWS_EXTERN char* lws_strncpy | ( | char * | dest, |
const char * | src, | ||
size_t | size | ||
) |
#include <lib/libwebsockets.h>
lws_strncpy(): strncpy that guarantees NUL on truncated copy
dest | destination buffer |
src | source buffer |
size | bytes left in destination buffer |
This lets you correctly truncate buffers by concatenating lengths, if you reach the limit the reported length doesn't exceed the limit.
LWS_VISIBLE LWS_EXTERN void* lws_wsi_user | ( | struct lws * | wsi | ) |
#include <lib/libwebsockets.h>
lws_wsi_user() - get the user data associated with the connection
wsi | lws connection |
Not normally needed since it's passed into the callback