libwebsockets
Lightweight C library for HTML5 websockets
Miscellaneous APIs

Functions

LWS_VISIBLE LWS_EXTERN int lws_snprintf (char *str, size_t size, const char *format,...) LWS_FORMAT(3)
 
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 unsigned long lws_now_secs (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_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_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 int lws_read (struct lws *wsi, unsigned char *buf, lws_filepos_t len)
 
LWS_VISIBLE LWS_EXTERN void lws_set_allocator (void *(*realloc)(void *ptr, size_t size, const char *reason))
 

Detailed Description

Miscellaneous APIs

Various APIs outside of other categories

Function Documentation

◆ lws_daemonize()

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

Parameters
_lock_paththe filepath to write the lock file

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

◆ lws_get_child()

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

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 <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.

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 <lib/libwebsockets.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_library_version()

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_get_network_wsi()

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

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 <lib/libwebsockets.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 <lib/libwebsockets.h>

lws_get_random(): fill a buffer with platform random data

Parameters
contextthe lws context
bufbuffer to fill
lenhow 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_now_secs()

LWS_VISIBLE LWS_EXTERN unsigned long lws_now_secs ( void  )

#include <lib/libwebsockets.h>

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

◆ 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 <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

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

◆ lws_set_allocator()

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

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

◆ lws_set_parent_carries_io()

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

Parameters
wsichild lws connection

◆ lws_set_wsi_user()

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

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 <lib/libwebsockets.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_wsi_user()

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

Parameters
wsilws connection

Not normally needed since it's passed into the callback