libwebsockets
Lightweight C library for HTML5 websockets
Miscellaneous APIs

Data Structures

struct  lws_wifi_scan
 
struct  lws_humanize_unit
 

Macros

#define lws_ptr_diff(head, tail)   ((int)((char *)(head) - (char *)(tail)))
 

Typedefs

typedef struct lws_humanize_unit lws_humanize_unit_t
 

Enumerations

enum  {
  LWS_RXFLOW_REASON_USER_BOOL = (1 << 0), LWS_RXFLOW_REASON_HTTP_RXBUFFER = (1 << 6), LWS_RXFLOW_REASON_H2_PPS_PENDING = (1 << 7), LWS_RXFLOW_REASON_APPLIES = (1 << 14),
  LWS_RXFLOW_REASON_APPLIES_ENABLE_BIT = (1 << 13), LWS_RXFLOW_REASON_APPLIES_ENABLE, LWS_RXFLOW_REASON_APPLIES_DISABLE = LWS_RXFLOW_REASON_APPLIES, LWS_RXFLOW_REASON_FLAG_PROCESS_NOW = (1 << 12)
}
 

Functions

LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT 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 size_t lws_buflist_total_len (struct lws_buflist **head)
 
LWS_VISIBLE LWS_EXTERN int lws_buflist_linear_copy (struct lws_buflist **head, size_t ofs, uint8_t *buf, size_t len)
 
LWS_VISIBLE LWS_EXTERN void lws_buflist_destroy_all_segments (struct lws_buflist **head)
 
LWS_VISIBLE LWS_EXTERN void lws_buflist_describe (struct lws_buflist **head, void *id, const char *reason)
 
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_hex_to_byte_array (const char *h, uint8_t *dest, int max)
 
LWS_VISIBLE LWS_EXTERN int lws_timingsafe_bcmp (const void *a, const void *b, uint32_t len)
 
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 void lws_cmdline_option_handle_builtin (int argc, const char **argv, struct lws_context_creation_info *info)
 
LWS_VISIBLE LWS_EXTERN unsigned long lws_now_secs (void)
 
LWS_VISIBLE LWS_EXTERN lws_usec_t lws_now_usecs (void)
 
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 void lws_get_effective_uid_gid (struct lws_context *context, int *uid, int *gid)
 
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_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 void * lws_get_opaque_user_data (const struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN void lws_set_opaque_user_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))
 
LWS_VISIBLE LWS_EXTERN int lws_rx_flow_control (struct lws *wsi, int enable)
 
LWS_VISIBLE LWS_EXTERN void lws_rx_flow_allow_all_protocol (const struct lws_context *context, const struct lws_protocols *protocol)
 
LWS_VISIBLE LWS_EXTERN size_t lws_remaining_packet_payload (struct lws *wsi)
 
size_t lws_get_allocated_heap (void)
 
LWS_VISIBLE LWS_EXTERN int lws_is_ssl (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN int lws_is_cgi (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN int lws_open (const char *__file, int __oflag,...)
 
LWS_VISIBLE LWS_EXTERN void lws_explicit_bzero (void *p, size_t len)
 
LWS_VISIBLE LWS_EXTERN int lws_humanize (char *buf, int len, uint64_t value, const lws_humanize_unit_t *schema)
 
LWS_VISIBLE LWS_EXTERN void lws_ser_wu16be (uint8_t *b, uint16_t u)
 
LWS_VISIBLE LWS_EXTERN void lws_ser_wu32be (uint8_t *b, uint32_t u32)
 
LWS_VISIBLE LWS_EXTERN void lws_ser_wu64be (uint8_t *b, uint64_t u64)
 
LWS_VISIBLE LWS_EXTERN uint16_t lws_ser_ru16be (const uint8_t *b)
 
LWS_VISIBLE LWS_EXTERN uint32_t lws_ser_ru32be (const uint8_t *b)
 
LWS_VISIBLE LWS_EXTERN uint64_t lws_ser_ru64be (const uint8_t *b)
 
int lws_vbi_encode (uint64_t value, void *buf)
 
int lws_vbi_decode (const void *buf, uint64_t *value, size_t len)
 

Variables

LWS_VISIBLE LWS_EXTERN const lws_humanize_unit_t humanize_schema_si []
 
LWS_VISIBLE LWS_EXTERN const lws_humanize_unit_t humanize_schema_si_bytes []
 
LWS_VISIBLE LWS_EXTERN const lws_humanize_unit_t humanize_schema_us []
 

Detailed Description

Miscellaneous APIs

Various APIs outside of other categories

Macro Definition Documentation

◆ lws_ptr_diff

#define lws_ptr_diff (   head,
  tail 
)    ((int)((char *)(head) - (char *)(tail)))

#include <include/libwebsockets/lws-misc.h>

lws_ptr_diff(): helper to report distance between pointers as an int

Parameters
headthe pointer with the larger address
tailthe pointer with the smaller address

This helper gives you an int representing the number of bytes further forward the first pointer is compared to the second pointer.

Function Documentation

◆ lws_buflist_append_segment()

LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_buflist_append_segment ( struct lws_buflist **  head,
const uint8_t *  buf,
size_t  len 
)

#include <include/libwebsockets/lws-misc.h>

lws_buflist_append_segment(): add buffer to buflist at head

Parameters
headlist head
bufbuffer to stash
lenlength 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_buflist_describe()

LWS_VISIBLE LWS_EXTERN void lws_buflist_describe ( struct lws_buflist **  head,
void *  id,
const char *  reason 
)

#include <include/libwebsockets/lws-misc.h>

lws_buflist_describe(): debug helper logging buflist status

Parameters
headlist head
idpointer shown in debug list
reasonreason string show in debug list

Iterates through the buflist segments showing position and size. This only exists when lws was built in debug mode

◆ lws_buflist_destroy_all_segments()

LWS_VISIBLE LWS_EXTERN void lws_buflist_destroy_all_segments ( struct lws_buflist **  head)

#include <include/libwebsockets/lws-misc.h>

lws_buflist_destroy_all_segments(): free all segments on the list

Parameters
headlist head

This frees everything on the list unconditionally. *head is always NULL after this.

◆ lws_buflist_linear_copy()

LWS_VISIBLE LWS_EXTERN int lws_buflist_linear_copy ( struct lws_buflist **  head,
size_t  ofs,
uint8_t *  buf,
size_t  len 
)

#include <include/libwebsockets/lws-misc.h>

lws_buflist_linear_copy(): copy everything out as one without consuming

Parameters
headlist head
ofsstart offset into buflist in bytes
bufbuffer to copy linearly into
lenlength of buffer available

Returns -1 if len is too small, or bytes copied. Happy to do partial copies, returns 0 when there are no more bytes to copy.

◆ lws_buflist_next_segment_len()

LWS_VISIBLE LWS_EXTERN size_t lws_buflist_next_segment_len ( struct lws_buflist **  head,
uint8_t **  buf 
)

#include <include/libwebsockets/lws-misc.h>

lws_buflist_next_segment_len(): number of bytes left in current segment

Parameters
headlist head
bufif 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_buflist_total_len()

LWS_VISIBLE LWS_EXTERN size_t lws_buflist_total_len ( struct lws_buflist **  head)

#include <include/libwebsockets/lws-misc.h>

lws_buflist_total_len(): Get the total size of the buflist

Parameters
headlist head

Returns the total number of bytes held on all segments of the buflist

◆ lws_buflist_use_segment()

LWS_VISIBLE LWS_EXTERN int lws_buflist_use_segment ( struct lws_buflist **  head,
size_t  len 
)

#include <include/libwebsockets/lws-misc.h>

lws_buflist_use_segment(): remove len bytes from the current segment

Parameters
headlist head
lennumber 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_cmdline_option()

LWS_VISIBLE LWS_EXTERN const char* lws_cmdline_option ( int  argc,
const char **  argv,
const char *  val 
)

#include <include/libwebsockets/lws-misc.h>

lws_cmdline_option(): simple commandline parser

Parameters
argccount of argument strings
argvargument strings
valstring 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_cmdline_option_handle_builtin()

LWS_VISIBLE LWS_EXTERN void lws_cmdline_option_handle_builtin ( int  argc,
const char **  argv,
struct lws_context_creation_info info 
)

#include <include/libwebsockets/lws-misc.h>

lws_cmdline_option_handle_builtin(): apply standard cmdline options

Parameters
argccount of argument strings
argvargument strings
infocontext creation info

Applies standard options to the context creation info to save them having to be (unevenly) copied into the minimal examples.

Applies default log levels that can be overriden by -d

◆ lws_daemonize()

LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_daemonize ( const char *  _lock_path)

#include <include/libwebsockets/lws-misc.h>

lws_daemonize(): make current process run in the background

Parameters
_lock_paththe filepath to write the lock file

Spawn lws as a background process, taking care of various things

◆ lws_get_allocated_heap()

size_t lws_get_allocated_heap ( void  )

#include <include/libwebsockets/lws-misc.h>

lws_get_allocated_heap() - if the platform supports it, returns amount of heap allocated by lws itself

On glibc currently, this reports the total amount of current logical heap allocation, found by tracking the amount allocated by lws_malloc() and friends and accounting for freed allocations via lws_free().

This is useful for confirming where processwide heap allocations actually come from... this number represents all lws internal allocations, for fd tables, wsi allocations, ah, etc combined. It doesn't include allocations from user code, since lws_malloc() etc are not exported from the library.

On other platforms, it always returns 0.

◆ lws_get_child()

LWS_VISIBLE LWS_EXTERN struct lws* LWS_WARN_UNUSED_RESULT lws_get_child ( const struct lws *  wsi)

#include <include/libwebsockets/lws-misc.h>

lws_get_child() - get child wsi or NULL

Parameters
wsilws connection

Allows you to find a related wsi from the parent wsi.

◆ lws_get_context()

LWS_VISIBLE LWS_EXTERN struct lws_context* LWS_WARN_UNUSED_RESULT lws_get_context ( const struct lws *  wsi)

#include <include/libwebsockets/lws-misc.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.

Parameters
wsiWebsocket connection instance

◆ lws_get_count_threads()

LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_get_count_threads ( struct lws_context *  context)

#include <include/libwebsockets/lws-misc.h>

lws_get_count_threads(): how many service threads the context uses

Parameters
contextthe 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_get_effective_uid_gid()

LWS_VISIBLE LWS_EXTERN void lws_get_effective_uid_gid ( struct lws_context *  context,
int *  uid,
int *  gid 
)

#include <include/libwebsockets/lws-misc.h>

lws_get_effective_uid_gid() - find out eventual uid and gid while still root

Parameters
contextlws context
uidpointer to uid result
gidpointer to gid result

This helper allows you to find out what the uid and gid for the process will be set to after the privileges are dropped, beforehand. So while still root, eg in LWS_CALLBACK_PROTOCOL_INIT, you can arrange things like cache dir and subdir creation / permissions down /var/cache dynamically.

◆ lws_get_library_version()

LWS_VISIBLE LWS_EXTERN const char* LWS_WARN_UNUSED_RESULT lws_get_library_version ( void  )

#include <include/libwebsockets/lws-misc.h>

lws_get_library_version(): return string describing the version of lws

On unix, also includes the git describe

◆ lws_get_network_wsi()

LWS_VISIBLE LWS_EXTERN struct lws* lws_get_network_wsi ( struct lws *  wsi)

#include <include/libwebsockets/lws-misc.h>

lws_get_network_wsi() - Returns wsi that has the tcp connection for this wsi

Parameters
wsiwsi 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_get_parent()

LWS_VISIBLE LWS_EXTERN struct lws* LWS_WARN_UNUSED_RESULT lws_get_parent ( const struct lws *  wsi)

#include <include/libwebsockets/lws-misc.h>

lws_get_parent() - get parent wsi or NULL

Parameters
wsilws connection

Specialized wsi like cgi stdin/out/err are associated to a parent wsi, this allows you to get their parent.

◆ lws_get_random()

LWS_VISIBLE LWS_EXTERN int lws_get_random ( struct lws_context *  context,
void *  buf,
int  len 
)

#include <include/libwebsockets/lws-misc.h>

lws_get_random(): fill a buffer with platform random data

Parameters
contextthe lws context
bufbuffer to fill
lenhow much to fill

Fills buf with len bytes of random. Returns the number of bytes set, if not equal to len, then getting the random failed.

◆ lws_get_udp()

LWS_VISIBLE LWS_EXTERN const struct lws_udp* LWS_WARN_UNUSED_RESULT lws_get_udp ( const struct lws *  wsi)

#include <include/libwebsockets/lws-misc.h>

lws_get_udp() - get wsi's udp struct

Parameters
wsilws connection

Returns NULL or pointer to the wsi's UDP-specific information

◆ lws_get_vhost_listen_port()

LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_get_vhost_listen_port ( struct lws_vhost *  vhost)

#include <include/libwebsockets/lws-misc.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.

Parameters
vhostVhost to get listen port from

◆ lws_hex_to_byte_array()

LWS_VISIBLE LWS_EXTERN int lws_hex_to_byte_array ( const char *  h,
uint8_t *  dest,
int  max 
)

#include <include/libwebsockets/lws-misc.h>

lws_hex_to_byte_array(): convert hex string like 0123456789ab into byte data

Parameters
hincoming NUL-terminated hex string
destarray to fill with binary decodes of hex pairs from h
maxmaximum number of bytes dest can hold, must be at least half the size of strlen(h)

This converts hex strings into an array of 8-bit representations, ie the input "abcd" produces two bytes of value 0xab and 0xcd.

Returns number of bytes produced into dest, or -1 on error.

Errors include non-hex chars and an odd count of hex chars in the input string.

◆ lws_humanize()

LWS_VISIBLE LWS_EXTERN int lws_humanize ( char *  buf,
int  len,
uint64_t  value,
const lws_humanize_unit_t schema 
)

#include <include/libwebsockets/lws-misc.h>

lws_humanize() - Convert possibly large number to himan-readable uints

Parameters
bufresult string buffer
lenremaining length in buf
valuethe uint64_t value to represent
schemaand array of scaling factors and units

This produces a concise string representation of value, referening the schema schema of scaling factors and units to find the smallest way to render it.

Three schema are exported from lws for general use, humanize_schema_si, which represents as, eg, " 22.130Gi" or " 128 "; humanize_schema_si_bytes which is the same but shows, eg, " 22.130GiB", and humanize_schema_us, which represents a count of us as a human-readable time like " 14.350min", or " 1.500d".

You can produce your own schema.

◆ lws_is_cgi()

LWS_VISIBLE LWS_EXTERN int lws_is_cgi ( struct lws *  wsi)

#include <include/libwebsockets/lws-misc.h>

lws_is_cgi() - find out if this wsi is running a cgi process

Parameters
wsilws connection

◆ lws_is_ssl()

LWS_VISIBLE LWS_EXTERN int lws_is_ssl ( struct lws *  wsi)

#include <include/libwebsockets/lws-misc.h>

lws_is_ssl() - Find out if connection is using SSL

Parameters
wsiwebsocket connection to check

Returns nonzero if the wsi is inside a tls tunnel, else zero.

◆ lws_now_secs()

LWS_VISIBLE LWS_EXTERN unsigned long lws_now_secs ( void  )

#include <include/libwebsockets/lws-misc.h>

lws_now_secs(): return seconds since 1970-1-1

◆ lws_now_usecs()

LWS_VISIBLE LWS_EXTERN lws_usec_t lws_now_usecs ( void  )

#include <include/libwebsockets/lws-misc.h>

lws_now_usecs(): return useconds since 1970-1-1

◆ lws_open()

LWS_VISIBLE LWS_EXTERN int lws_open ( const char *  __file,
int  __oflag,
  ... 
)

#include <include/libwebsockets/lws-misc.h>

lws_open() - platform-specific wrapper for open that prepares the fd

Parameters
__filethe filepath to open
__oflagoption flags

This is a wrapper around platform open() that sets options on the fd according to lws policy. Currently that is FD_CLOEXEC to stop the opened fd being available to any child process forked by user code.

◆ lws_parse_uri()

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 <include/libwebsockets/lws-misc.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

Parameters
pincoming uri string.. will get written to
protresult pointer for protocol part (https://)
adsresult pointer for address part
portresult pointer for port part
pathresult pointer for path part

You may also refer to unix socket addresses, using a '+' at the start of the address. In this case, the address should end with ':', which is treated as the separator between the address and path (the normal separator '/' is a valid part of the socket path). Eg,

http://+/var/run/mysocket:/my/path

If the first character after the + is '@', it's interpreted by lws client processing as meaning to use linux abstract namespace sockets, the @ is replaced with a '\0' before use.

◆ lws_remaining_packet_payload()

LWS_VISIBLE LWS_EXTERN size_t lws_remaining_packet_payload ( struct lws *  wsi)

#include <include/libwebsockets/lws-misc.h>

lws_remaining_packet_payload() - Bytes to come before "overall" rx fragment is complete

Parameters
wsiWebsocket instance (available from user callback)

This tracks how many bytes are left in the current ws fragment, according to the ws length given in the fragment header.

If the message was in a single fragment, and there is no compression, this is the same as "how much data is left to read for this message".

However, if the message is being sent in multiple fragments, this will reflect the unread amount of the current fragment, not the message. With ws, it is legal to not know the length of the message before it completes.

Additionally if the message is sent via the negotiated permessage-deflate extension, this number only tells the amount of compressed data left to be read, since that is the only information available at the ws layer.

◆ lws_rx_flow_allow_all_protocol()

LWS_VISIBLE LWS_EXTERN void lws_rx_flow_allow_all_protocol ( const struct lws_context *  context,
const struct lws_protocols protocol 
)

#include <include/libwebsockets/lws-misc.h>

lws_rx_flow_allow_all_protocol() - Allow all connections with this protocol to receive

When the user server code realizes it can accept more input, it can call this to have the RX flow restriction removed from all connections using the given protocol.

Parameters
contextlws_context
protocolall connections using this protocol will be allowed to receive

◆ lws_rx_flow_control()

LWS_VISIBLE LWS_EXTERN int lws_rx_flow_control ( struct lws *  wsi,
int  enable 
)

#include <include/libwebsockets/lws-misc.h>

lws_rx_flow_control() - Enable and disable socket servicing for received packets.

If the output side of a server process becomes choked, this allows flow control for the input side.

Parameters
wsiWebsocket connection instance to get callback for
enable0 = disable read servicing for this connection, 1 = enable

If you need more than one additive reason for rxflow control, you can give iLWS_RXFLOW_REASON_APPLIES_ENABLE or _DISABLE together with one or more of b5..b0 set to idicate which bits to enable or disable. If any bits are enabled, rx on the connection is suppressed.

LWS_RXFLOW_REASON_FLAG_PROCESS_NOW flag may also be given to force any change in rxflowbstatus to benapplied immediately, this should be used when you are changing a wsi flow control state from outside a callback on that wsi.

◆ lws_set_allocator()

LWS_VISIBLE LWS_EXTERN void lws_set_allocator ( void *(*)(void *ptr, size_t size, const char *reason)  realloc)

#include <include/libwebsockets/lws-misc.h>

lws_set_allocator() - custom allocator support

Parameters
reallocAllows you to replace the allocator (and deallocator) used by lws

◆ lws_set_wsi_user()

LWS_VISIBLE LWS_EXTERN void lws_set_wsi_user ( struct lws *  wsi,
void *  user 
)

#include <include/libwebsockets/lws-misc.h>

lws_set_wsi_user() - set the user data associated with the client connection

Parameters
wsilws connection
useruser 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_snprintf()

LWS_VISIBLE LWS_EXTERN int lws_snprintf ( char *  str,
size_t  size,
const char *  format,
  ... 
)

#include <include/libwebsockets/lws-misc.h>

lws_snprintf(): snprintf that truncates the returned length too

Parameters
strdestination buffer
sizebytes left in destination buffer
formatformat 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_strncpy()

LWS_VISIBLE LWS_EXTERN char* lws_strncpy ( char *  dest,
const char *  src,
size_t  size 
)

#include <include/libwebsockets/lws-misc.h>

lws_strncpy(): strncpy that guarantees NUL on truncated copy

Parameters
destdestination buffer
srcsource buffer
sizebytes 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_wsi_user()

LWS_VISIBLE LWS_EXTERN void* lws_wsi_user ( struct lws *  wsi)

#include <include/libwebsockets/lws-misc.h>

lws_wsi_user() - get the user data associated with the connection

Parameters
wsilws connection

Not normally needed since it's passed into the callback