Skip to content
Snippets Groups Projects
libwebsockets-api-doc.html 57.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • Andy Green's avatar
    Andy Green committed
    <h2>lws_client_reset - retarget a connected wsi to start over with a new connection (ie, redirect) this only works if still in HTTP, ie, not upgraded yet</h2>
    <i>struct lws *</i>
    <b>lws_client_reset</b>
    
    (<i>struct lws *</i> <b>wsi</b>,
    
    Andy Green's avatar
    Andy Green committed
    <i>int</i> <b>ssl</b>,
    <i>const char *</i> <b>address</b>,
    <i>int</i> <b>port</b>,
    <i>const char *</i> <b>path</b>,
    <i>const char *</i> <b>host</b>)
    
    <h3>Arguments</h3>
    <dl>
    </dl>
    
    Andy Green's avatar
    Andy Green committed
    <h3>wsi</h3>
    
    <blockquote>
    
    Andy Green's avatar
    Andy Green committed
    connection to reset
    
    </blockquote>
    
    Andy Green's avatar
    Andy Green committed
    <h3>address</h3>
    
    <blockquote>
    
    Andy Green's avatar
    Andy Green committed
    network address of the new server
    
    </blockquote>
    
    Andy Green's avatar
    Andy Green committed
    <h3>port</h3>
    
    <blockquote>
    
    Andy Green's avatar
    Andy Green committed
    port to connect to
    
    </blockquote>
    
    Andy Green's avatar
    Andy Green committed
    <h3>path</h3>
    
    Andy Green's avatar
    Andy Green committed
    uri path to connect to on the new server
    </blockquote>
    <h3>host</h3>
    <blockquote>
    host header to send to the new server
    
    Andy Green's avatar
    Andy Green committed
    <h2>lws_client_connect_via_info - Connect to another websocket server</h2>
    
    Andy Green's avatar
    Andy Green committed
    <b>lws_client_connect_via_info</b>
    
    (<i>struct lws_client_connect_info *</i> <b>i</b>)
    
    <h3>Arguments</h3>
    <dl>
    
    Andy Green's avatar
    Andy Green committed
    <dt><b>i</b>
    <dd>pointer to lws_client_connect_info struct
    
    </dl>
    <h3>Description</h3>
    <blockquote>
    
    This function creates a connection to a remote server
    
    </blockquote>
    <hr>
    
    Andy Green's avatar
    Andy Green committed
    <h2>lws_client_connect_extended - Connect to another websocket server DEPRECATED use lws_client_connect_via_info</h2>
    
    <i>struct lws *</i>
    <b>lws_client_connect_extended</b>
    (<i>struct lws_context *</i> <b>context</b>,
    <i>const char *</i> <b>address</b>,
    <i>int</i> <b>port</b>,
    <i>int</i> <b>ssl_connection</b>,
    <i>const char *</i> <b>path</b>,
    <i>const char *</i> <b>host</b>,
    <i>const char *</i> <b>origin</b>,
    <i>const char *</i> <b>protocol</b>,
    <i>int</i> <b>ietf_version_or_minus_one</b>,
    <i>void *</i> <b>userdata</b>)
    
    Andy Green's avatar
    Andy Green committed
    <h3>Arguments</h3>
    <dl>
    
    <dt><b>context</b>
    
    Andy Green's avatar
    Andy Green committed
    <dd>Websocket context
    
    <dt><b>address</b>
    <dd>Remote server address, eg, "myserver.com"
    <dt><b>port</b>
    <dd>Port to connect to on the remote server, eg, 80
    <dt><b>ssl_connection</b>
    <dd>0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
    signed certs
    <dt><b>path</b>
    <dd>Websocket path on server
    <dt><b>host</b>
    <dd>Hostname on server
    <dt><b>origin</b>
    <dd>Socket origin name
    <dt><b>protocol</b>
    <dd>Comma-separated list of protocols being asked for from
    the server, or just one.  The server will pick the one it
    likes best.
    <dt><b>ietf_version_or_minus_one</b>
    <dd>-1 to ask to connect using the default, latest
    protocol supported, or the specific protocol ordinal
    <dt><b>userdata</b>
    <dd>Pre-allocated user data
    
    Andy Green's avatar
    Andy Green committed
    </dl>
    <h3>Description</h3>
    <blockquote>
    
    This function creates a connection to a remote server
    
    Andy Green's avatar
    Andy Green committed
    </blockquote>
    <hr>
    
    Andy Green's avatar
    Andy Green committed
    <h2>lws_client_connect - Connect to another websocket server DEPRECATED use lws_client_connect_via_info</h2>
    <i>struct lws *</i>
    <b>lws_client_connect</b>
    
    (<i>struct lws_context *</i> <b>context</b>,
    
    Andy Green's avatar
    Andy Green committed
    <i>const char *</i> <b>address</b>,
    <i>int</i> <b>port</b>,
    <i>int</i> <b>ssl_connection</b>,
    <i>const char *</i> <b>path</b>,
    <i>const char *</i> <b>host</b>,
    <i>const char *</i> <b>origin</b>,
    <i>const char *</i> <b>protocol</b>,
    <i>int</i> <b>ietf_version_or_minus_one</b>)
    
    <h3>Arguments</h3>
    <dl>
    <dt><b>context</b>
    <dd>Websocket context
    
    Andy Green's avatar
    Andy Green committed
    <dt><b>address</b>
    <dd>Remote server address, eg, "myserver.com"
    <dt><b>port</b>
    <dd>Port to connect to on the remote server, eg, 80
    <dt><b>ssl_connection</b>
    <dd>0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
    signed certs
    <dt><b>path</b>
    <dd>Websocket path on server
    <dt><b>host</b>
    <dd>Hostname on server
    <dt><b>origin</b>
    <dd>Socket origin name
    <dt><b>protocol</b>
    <dd>Comma-separated list of protocols being asked for from
    the server, or just one.  The server will pick the one it
    likes best.  If you don't want to specify a protocol, which is
    legal, use NULL here.
    <dt><b>ietf_version_or_minus_one</b>
    <dd>-1 to ask to connect using the default, latest
    protocol supported, or the specific protocol ordinal
    
    </dl>
    <h3>Description</h3>
    <blockquote>
    
    Andy Green's avatar
    Andy Green committed
    This function creates a connection to a remote server
    
    </blockquote>
    <hr>
    
    Andy Green's avatar
    Andy Green committed
    <h2>lws_get_library_version - </h2>
    <i>const char *</i>
    <b>lws_get_library_version</b>
    (<i></i> <b>void</b>)
    
    Andy Green's avatar
    Andy Green committed
    <h3>Arguments</h3>
    <dl>
    
    Andy Green's avatar
    Andy Green committed
    <dt><b>void</b>
    <dd>no arguments
    
    Andy Green's avatar
    Andy Green committed
    </dl>
    <h3>Description</h3>
    <blockquote>
    <p>
    
    Andy Green's avatar
    Andy Green committed
    returns a const char * to a string like "1.1 178d78c"
    representing the library version followed by the git head hash it
    was built from
    
    </blockquote>
    <hr>
    
    Andy Green's avatar
    Andy Green committed
    <h2>lws_create_context - Create the websocket handler</h2>
    <i>struct lws_context *</i>
    <b>lws_create_context</b>
    (<i>struct lws_context_creation_info *</i> <b>info</b>)
    
    <h3>Arguments</h3>
    <dl>
    
    Andy Green's avatar
    Andy Green committed
    <dt><b>info</b>
    <dd>pointer to struct with parameters
    
    </dl>
    <h3>Description</h3>
    <blockquote>
    
    Andy Green's avatar
    Andy Green committed
    This function creates the listening socket (if serving) and takes care
    of all initialization in one step.
    <p>
    After initialization, it returns a struct lws_context * that
    represents this server.  After calling, user code needs to take care
    of calling <b>lws_service</b> with the context pointer to get the
    server's sockets serviced.  This must be done in the same process
    context as the initialization call.
    <p>
    The protocol callback functions are called for a handful of events
    including http requests coming in, websocket connections becoming
    established, and data arriving; it's also called periodically to allow
    async transmission.
    <p>
    HTTP requests are sent always to the FIRST protocol in <tt><b>protocol</b></tt>, since
    at that time websocket protocol has not been negotiated.  Other
    protocols after the first one never see any HTTP callack activity.
    <p>
    The server created is a simple http server by default; part of the
    websocket standard is upgrading this http connection to a websocket one.
    <p>
    This allows the same server to provide files like scripts and favicon /
    images or whatever over http and dynamic data over websockets all in
    one place; they're all handled in the user callback.
    </blockquote>
    <hr>
    <h2>lws_context_destroy - Destroy the websocket context</h2>
    <i>void</i>
    <b>lws_context_destroy</b>
    (<i>struct lws_context *</i> <b>context</b>)
    
    <h3>Arguments</h3>
    <dl>
    
    Andy Green's avatar
    Andy Green committed
    <dt><b>context</b>
    <dd>Websocket context
    
    </dl>
    <h3>Description</h3>
    <blockquote>
    
    Andy Green's avatar
    Andy Green committed
    This function closes any active connections and then frees the
    context.  After calling this, any further use of the context is
    undefined.
    
    </blockquote>
    <hr>
    
    Andy Green's avatar
    Andy Green committed
    <h2>lws_return_http_status - Return simple http status</h2>
    
    Andy Green's avatar
    Andy Green committed
    <b>lws_return_http_status</b>
    (<i>struct lws *</i> <b>wsi</b>,
    <i>unsigned int</i> <b>code</b>,
    <i>const char *</i> <b>html_body</b>)
    
    <h3>Arguments</h3>
    <dl>
    <dt><b>wsi</b>
    
    Andy Green's avatar
    Andy Green committed
    <dd>Websocket instance (available from user callback)
    <dt><b>code</b>
    <dd>Status index, eg, 404
    <dt><b>html_body</b>
    <dd>User-readable HTML description &lt; 1KB, or NULL
    
    </dl>
    <h3>Description</h3>
    <blockquote>
    
    Andy Green's avatar
    Andy Green committed
    Helper to report HTTP errors back to the client cleanly and
    consistently
    
    Andy Green's avatar
    Andy Green committed
    <h2>lws_set_timeout - marks the wsi as subject to a timeout</h2>
    <i>void</i>
    <b>lws_set_timeout</b>
    (<i>struct lws *</i> <b>wsi</b>,
    <i>enum pending_timeout</i> <b>reason</b>,
    <i>int</i> <b>secs</b>)
    
    <h3>Arguments</h3>
    <dl>
    <dt><b>wsi</b>
    
    Andy Green's avatar
    Andy Green committed
    <dd>Websocket connection instance
    <dt><b>reason</b>
    <dd>timeout reason
    <dt><b>secs</b>
    <dd>how many seconds
    
    </dl>
    <h3>Description</h3>
    <blockquote>
    <p>
    
    Andy Green's avatar
    Andy Green committed
    You will not need this unless you are doing something special
    
    </blockquote>
    <hr>
    <h2>lws_get_peer_addresses - Get client address information</h2>
    <i>void</i>
    <b>lws_get_peer_addresses</b>
    
    Andy Green's avatar
    Andy Green committed
    (<i>struct lws *</i> <b>wsi</b>,
    
    <i>lws_sockfd_type</i> <b>fd</b>,
    <i>char *</i> <b>name</b>,
    <i>int</i> <b>name_len</b>,
    <i>char *</i> <b>rip</b>,
    <i>int</i> <b>rip_len</b>)
    
    <h3>Arguments</h3>
    <dl>
    <dt><b>wsi</b>
    
    <dd>Local struct lws associated with
    <dt><b>fd</b>
    <dd>Connection socket descriptor
    <dt><b>name</b>
    <dd>Buffer to take client address name
    <dt><b>name_len</b>
    <dd>Length of client address name buffer
    <dt><b>rip</b>
    <dd>Buffer to take client address IP dotted quad
    <dt><b>rip_len</b>
    <dd>Length of client address IP buffer
    </dl>
    <h3>Description</h3>
    <blockquote>
    This function fills in <tt><b>name</b></tt> and <tt><b>rip</b></tt> with the name and IP of
    the client connected with socket descriptor <tt><b>fd</b></tt>.  Names may be
    truncated if there is not enough room.  If either cannot be
    determined, they will be returned as valid zero-length strings.
    </blockquote>
    <hr>
    <h2>lws_context_user - get the user data associated with the context</h2>
    <i>LWS_EXTERN void *</i>
    <b>lws_context_user</b>
    (<i>struct lws_context *</i> <b>context</b>)
    <h3>Arguments</h3>
    <dl>
    <dt><b>context</b>
    <dd>Websocket context
    
    <h3>Description</h3>
    <blockquote>
    This returns the optional user allocation that can be attached to
    the context the sockets live in at context_create time.  It's a way
    to let all sockets serviced in the same context share data without
    using globals statics in the user code.
    </blockquote>
    
    <h2>lws_callback_all_protocol - Callback all connections using the given protocol with the given reason</h2>
    
    <b>lws_callback_all_protocol</b>
    
    Andy Green's avatar
    Andy Green committed
    (<i>struct lws_context *</i> <b>context</b>,
    <i>const struct lws_protocols *</i> <b>protocol</b>,
    
    <h3>Arguments</h3>
    <dl>
    <dt><b>protocol</b>
    <dd>Protocol whose connections will get callbacks
    
    <dt><b>reason</b>
    <dd>Callback reason index
    
    <h2>lws_get_socket_fd - returns the socket file descriptor</h2>
    
    <i>int</i>
    
    <b>lws_get_socket_fd</b>
    (<i>struct lws *</i> <b>wsi</b>)
    
    <h3>Arguments</h3>
    <dl>
    <dt><b>wsi</b>
    <dd>Websocket connection instance
    </dl>
    <h3>Description</h3>
    <blockquote>
    <p>
    You will not need this unless you are doing something special
    </blockquote>
    <hr>
    
    <h2>lws_rx_flow_control - Enable and disable socket servicing for received packets.</h2>
    
    <b>lws_rx_flow_control</b>
    (<i>struct lws *</i> <b>wsi</b>,
    
    <i>int</i> <b>enable</b>)
    <h3>Arguments</h3>
    <dl>
    <dt><b>wsi</b>
    <dd>Websocket connection instance to get callback for
    <dt><b>enable</b>
    <dd>0 = disable read servicing for this connection, 1 = enable
    </dl>
    <h3>Description</h3>
    <blockquote>
    <p>
    If the output side of a server process becomes choked, this allows flow
    control for the input side.
    </blockquote>
    <hr>
    
    <h2>lws_rx_flow_allow_all_protocol - Allow all connections with this protocol to receive</h2>
    
    <b>lws_rx_flow_allow_all_protocol</b>
    
    Andy Green's avatar
    Andy Green committed
    (<i>const struct lws_context *</i> <b>context</b>,
    <i>const struct lws_protocols *</i> <b>protocol</b>)
    
    <h3>Arguments</h3>
    <dl>
    <dt><b>protocol</b>
    <dd>all connections using this protocol will be allowed to receive
    </dl>
    <h3>Description</h3>
    <blockquote>
    <p>
    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.
    </blockquote>
    <hr>
    
    <h2>lws_canonical_hostname - returns this host's hostname</h2>
    
    <b>lws_canonical_hostname</b>
    (<i>struct lws_context *</i> <b>context</b>)
    
    <dt><b>context</b>
    
    <dd>Websocket context
    </dl>
    <h3>Description</h3>
    <blockquote>
    <p>
    This is typically used by client code to fill in the host parameter
    when making a client connection.  You can only call it after the context
    has been created.
    </blockquote>
    <hr>
    
    <h2>lws_set_proxy - Setups proxy to lws_context.</h2>
    <i>int</i>
    <b>lws_set_proxy</b>
    (<i>struct lws_context *</i> <b>context</b>,
    <i>const char *</i> <b>proxy</b>)
    
    Andy Green's avatar
    Andy Green committed
    <h3>Arguments</h3>
    <dl>
    
    <dt><b>context</b>
    <dd>pointer to struct lws_context you want set proxy to
    <dt><b>proxy</b>
    <dd>pointer to c string containing proxy in format address:port
    
    Andy Green's avatar
    Andy Green committed
    </dl>
    <h3>Description</h3>
    <blockquote>
    
    Andy Green's avatar
    Andy Green committed
    Returns 0 if proxy string was parsed and proxy was setup.
    
    Returns -1 if <tt><b>proxy</b></tt> is NULL or has incorrect format.
    
    Andy Green's avatar
    Andy Green committed
    <p>
    
    This is only required if your OS does not provide the http_proxy
    environment variable (eg, OSX)
    
    IMPORTANT! You should call this function right after creation of the
    lws_context and before call to connect. If you call this
    function after connect behavior is undefined.
    This function will override proxy settings made on lws_context
    creation with <b>genenv</b> call.
    
    Andy Green's avatar
    Andy Green committed
    </blockquote>
    <hr>
    
    <h2>lws_get_protocol - Returns a protocol pointer from a websocket connection.</h2>
    <i>const struct lws_protocols *</i>
    <b>lws_get_protocol</b>
    (<i>struct lws *</i> <b>wsi</b>)
    
    <h3>Arguments</h3>
    <dl>
    <dt><b>wsi</b>
    <dd>pointer to struct websocket you want to know the protocol of
    </dl>
    <h3>Description</h3>
    <blockquote>
    <p>
    
    Andy Green's avatar
    Andy Green committed
    Some apis can act on all live connections of a given protocol,
    this is how you can get a pointer to the active protocol if needed.
    
    Andy Green's avatar
    Andy Green committed
    </blockquote>
    <hr>
    
    <h2>lws_set_log_level - Set the logging bitfield</h2>
    <i>void</i>
    <b>lws_set_log_level</b>
    
    Andy Green's avatar
    Andy Green committed
    <i>void (*</i><b>func</b>) <i>(int level, const char *line)</i>)
    
    <h3>Arguments</h3>
    <dl>
    <dt><b>level</b>
    <dd>OR together the LLL_ debug contexts you want output from
    </dl>
    <h3>Description</h3>
    <blockquote>
    
    log level defaults to "err", "warn" and "notice" contexts enabled and
    
    <h2>lws_is_ssl - Find out if connection is using SSL</h2>
    
    <i>int</i>
    
    <b>lws_is_ssl</b>
    (<i>struct lws *</i> <b>wsi</b>)
    
    <h3>Arguments</h3>
    <dl>
    <dt><b>wsi</b>
    
    <dd>websocket connection to check
    
    </dl>
    <h3>Description</h3>
    <blockquote>
    
    Returns 0 if the connection is not using SSL, 1 if using SSL and
    using verified cert, and 2 if using SSL but the cert was not
    checked (appears for client wsi told to skip check on connection)
    </blockquote>
    <hr>
    <h2>lws_partial_buffered - find out if lws buffered the last write</h2>
    <i>int</i>
    <b>lws_partial_buffered</b>
    (<i>struct lws *</i> <b>wsi</b>)
    <h3>Arguments</h3>
    <dl>
    <dt><b>wsi</b>
    
    Andy Green's avatar
    Andy Green committed
    <dd>websocket connection to check
    </dl>
    <h3>Description</h3>
    <blockquote>
    Returns 1 if you cannot use lws_write because the last
    write on this connection is still buffered, and can't be cleared without
    returning to the service loop and waiting for the connection to be
    writeable again.
    <p>
    If you will try to do &gt;1 lws_write call inside a single
    WRITEABLE callback, you must check this after every write and bail if
    set, ask for a new writeable callback and continue writing from there.
    <p>
    This is never set at the start of a writeable callback, but any write
    may set it.
    </blockquote>
    <hr>
    <h2>lws_parse_uri - </h2>
    <i>LWS_EXTERN int</i>
    <b>lws_parse_uri</b>
    (<i>char *</i> <b>p</b>,
    <i>const char **</i> <b>prot</b>,
    <i>const char **</i> <b>ads</b>,
    <i>int *</i> <b>port</b>,
    <i>const char **</i> <b>path</b>)
    <h3>Arguments</h3>
    <dl>
    <dt><b>p</b>
    <dd>incoming uri string.. will get written to
    <dt><b>prot</b>
    <dd>result pointer for protocol part (https://)
    <dt><b>ads</b>
    <dd>result pointer for address part
    <dt><b>port</b>
    <dd>result pointer for port part
    <dt><b>path</b>
    <dd>result pointer for path part
    </dl>
    <h3>Description</h3>
    <blockquote>
    Notice it does so by dropping '\0' into input string
    
    Andy Green's avatar
    Andy Green committed
    and the leading / on the path is consequently lost
    
    Andy Green's avatar
    Andy Green committed
    </blockquote>
    <hr>
    <h2>lws_cancel_service - Cancel servicing of pending websocket activity</h2>
    <i>void</i>
    <b>lws_cancel_service</b>
    (<i>struct lws_context *</i> <b>context</b>)
    <h3>Arguments</h3>
    <dl>
    <dt><b>context</b>
    <dd>Websocket context
    </dl>
    <h3>Description</h3>
    <blockquote>
    This function let a call to <b>lws_service</b> waiting for a timeout
    immediately return.
    <p>
    There is no <b>poll</b> in MBED3, he will fire callbacks when he feels like
    it.
    </blockquote>
    <hr>
    <h2>lws_cancel_service_pt - Cancel servicing of pending socket activity on one thread</h2>
    <i>void</i>
    <b>lws_cancel_service_pt</b>
    (<i>struct lws *</i> <b>wsi</b>)
    <h3>Arguments</h3>
    <dl>
    <dt><b>wsi</b>
    <dd>Cancel service on the thread this wsi is serviced by
    </dl>
    <h3>Description</h3>
    <blockquote>
    This function let a call to <b>lws_service</b> waiting for a timeout
    immediately return.
    </blockquote>
    <hr>
    <h2>lws_cancel_service - Cancel ALL servicing of pending socket activity</h2>
    <i>void</i>
    <b>lws_cancel_service</b>
    (<i>struct lws_context *</i> <b>context</b>)
    <h3>Arguments</h3>
    <dl>
    <dt><b>context</b>
    <dd>Websocket context
    </dl>
    <h3>Description</h3>
    <blockquote>
    This function let a call to <b>lws_service</b> waiting for a timeout
    immediately return.
    </blockquote>
    <hr>
    <h2>lws_cancel_service - Cancel servicing of pending websocket activity</h2>
    <i>void</i>
    <b>lws_cancel_service</b>
    (<i>struct lws_context *</i> <b>context</b>)
    <h3>Arguments</h3>
    <dl>
    <dt><b>context</b>
    <dd>Websocket context
    </dl>
    <h3>Description</h3>
    <blockquote>
    This function let a call to <b>lws_service</b> waiting for a timeout
    immediately return.
    </blockquote>
    <hr>
    <h2>lws_write - Apply protocol then write data to client</h2>
    <i>int</i>
    <b>lws_write</b>
    (<i>struct lws *</i> <b>wsi</b>,
    <i>unsigned char *</i> <b>buf</b>,
    <i>size_t</i> <b>len</b>,
    <i>enum lws_write_protocol</i> <b>wp</b>)
    <h3>Arguments</h3>
    <dl>
    <dt><b>wsi</b>
    <dd>Websocket instance (available from user callback)
    <dt><b>buf</b>
    <dd>The data to send.  For data being sent on a websocket
    connection (ie, not default http), this buffer MUST have
    LWS_PRE bytes valid BEFORE the pointer.
    This is so the protocol header data can be added in-situ.
    <dt><b>len</b>
    <dd>Count of the data bytes in the payload starting from buf
    </dl>
    <h3>Description</h3>
    <blockquote>
    This function provides the way to issue data back to the client
    for both http and websocket protocols.
    <p>
    In the case of sending using websocket protocol, be sure to allocate
    valid storage before and after buf as explained above.  This scheme
    allows maximum efficiency of sending data and protocol in a single
    packet while not burdening the user code with any protocol knowledge.
    <p>
    Return may be -1 for a fatal error needing connection close, or a
    positive number reflecting the amount of bytes actually sent.  This
    can be less than the requested number of bytes due to OS memory
    pressure at any given time.
    </blockquote>
    <hr>
    <h2>lws_hdr_fragment_length - </h2>
    <i>int</i>
    <b>lws_hdr_fragment_length</b>
    (<i>struct lws *</i> <b>wsi</b>,
    <i>enum lws_token_indexes</i> <b>h</b>,
    <i>int</i> <b>frag_idx</b>)
    <h3>Arguments</h3>
    <dl>
    <dt><b>wsi</b>
    <dd>websocket connection
    <dt><b>h</b>
    <dd>which header index we are interested in
    <dt><b>frag_idx</b>
    <dd>which fragment of <tt><b>h</b></tt> we want to get the length of
    </dl>
    <h3>Description</h3>
    <blockquote>
    The returned length does not include the space for a
    terminating '\0'
    </blockquote>
    <hr>
    <h2>lws_hdr_total_length - </h2>
    <i>int</i>
    <b>lws_hdr_total_length</b>
    (<i>struct lws *</i> <b>wsi</b>,
    <i>enum lws_token_indexes</i> <b>h</b>)
    <h3>Arguments</h3>
    <dl>
    <dt><b>wsi</b>
    <dd>websocket connection
    <dt><b>h</b>
    <dd>which header index we are interested in
    </dl>
    <h3>Description</h3>
    <blockquote>
    The returned length does not include the space for a
    terminating '\0'
    </blockquote>
    <hr>
    <h2>lws_hdr_copy_fragment - </h2>
    <i>int</i>
    <b>lws_hdr_copy_fragment</b>
    (<i>struct lws *</i> <b>wsi</b>,
    <i>char *</i> <b>dst</b>,
    <i>int</i> <b>len</b>,
    <i>enum lws_token_indexes</i> <b>h</b>,
    <i>int</i> <b>frag_idx</b>)
    <h3>Arguments</h3>
    <dl>
    <dt><b>wsi</b>
    <dd>websocket connection
    <dt><b>dst</b>
    <dd>destination buffer
    <dt><b>len</b>
    <dd>length of destination buffer
    <dt><b>h</b>
    <dd>which header index we are interested in
    
    </dl>
    <h3>Description</h3>
    <blockquote>
    
    Andy Green's avatar
    Andy Green committed
    The buffer length <tt><b>len</b></tt> must include space for an additional
    terminating '\0', or it will fail returning -1.
    If the requested fragment index is not present, it fails
    returning -1.
    
    Andy Green's avatar
    Andy Green committed
    <h2>lws_hdr_copy - </h2>
    <i>int</i>
    <b>lws_hdr_copy</b>
    (<i>struct lws *</i> <b>wsi</b>,
    <i>char *</i> <b>dst</b>,
    <i>int</i> <b>len</b>,
    <i>enum lws_token_indexes</i> <b>h</b>)
    
    Andy Green's avatar
    Andy Green committed
    <dt><b>wsi</b>
    <dd>websocket connection
    <dt><b>dst</b>
    <dd>destination buffer
    <dt><b>len</b>
    <dd>length of destination buffer
    <dt><b>h</b>
    <dd>which header index we are interested in
    
    </dl>
    <h3>Description</h3>
    <blockquote>
    
    Andy Green's avatar
    Andy Green committed
    The buffer length <tt><b>len</b></tt> must include space for an additional
    terminating '\0', or it will fail returning -1.
    
    Andy Green's avatar
    Andy Green committed
    <h2>lws_frame_is_binary - </h2>
    <i>int</i>
    <b>lws_frame_is_binary</b>
    (<i>struct lws *</i> <b>wsi</b>)
    
    Andy Green's avatar
    Andy Green committed
    <dt><b>wsi</b>
    <dd>the connection we are inquiring about
    
    </dl>
    <h3>Description</h3>
    <blockquote>
    
    Andy Green's avatar
    Andy Green committed
    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.
    
    Andy Green's avatar
    Andy Green committed
    <h2>lws_remaining_packet_payload - Bytes to come before "overall" rx packet is complete</h2>
    <i>size_t</i>
    <b>lws_remaining_packet_payload</b>
    (<i>struct lws *</i> <b>wsi</b>)
    
    Andy Green's avatar
    Andy Green committed
    <dt><b>wsi</b>
    <dd>Websocket instance (available from user callback)
    
    </dl>
    <h3>Description</h3>
    <blockquote>
    
    Andy Green's avatar
    Andy Green committed
    This function is intended to be called from the callback if the
    user code is interested in "complete packets" from the client.
    libwebsockets just passes through payload as it comes and issues a buffer
    additionally when it hits a built-in limit.  The LWS_CALLBACK_RECEIVE
    callback handler can use this API to find out if the buffer it has just
    been given is the last piece of a "complete packet" from the client --
    when that is the case <b>lws_remaining_packet_payload</b> will return
    0.
    <p>
    Many protocols won't care becuse their packets are always small.
    
    </blockquote>
    <hr>
    
    <h2>lws_callback_on_writable - Request a callback when this socket becomes able to be written to without blocking</h2>
    
    <i>int</i>
    
    <b>lws_callback_on_writable</b>
    
    Andy Green's avatar
    Andy Green committed
    (<i>struct lws *</i> <b>wsi</b>)
    
    <h3>Arguments</h3>
    <dl>
    <dt><b>wsi</b>
    
    <dd>Websocket connection instance to get callback for
    </dl>
    <hr>
    <h2>lws_callback_on_writable_all_protocol - Request a callback for all connections using the given protocol when it becomes possible to write to each socket without blocking in turn.</h2>
    <i>int</i>
    <b>lws_callback_on_writable_all_protocol</b>
    
    Andy Green's avatar
    Andy Green committed
    (<i>const struct lws_context *</i> <b>context</b>,
    <i>const struct lws_protocols *</i> <b>protocol</b>)
    
    Andy Green's avatar
    Andy Green committed
    <dt><b>context</b>
    <dd>lws_context
    
    <dt><b>protocol</b>
    <dd>Protocol whose connections will get callbacks
    </dl>
    <hr>
    
    Andy Green's avatar
    Andy Green committed
    <h2>lws_http_transaction_completed - wait for new http transaction or close</h2>
    <i>int LWS_WARN_UNUSED_RESULT</i>
    <b>lws_http_transaction_completed</b>
    (<i>struct lws *</i> <b>wsi</b>)
    <h3>Arguments</h3>
    <dl>
    <dt><b>wsi</b>
    <dd>websocket connection
    </dl>
    <h3>Description</h3>
    <blockquote>
    Returns 1 if the HTTP connection must close now
    Returns 0 and resets connection to wait for new HTTP header /
    transaction if possible
    </blockquote>
    <hr>
    <h2>lws_adopt_socket - adopt foreign socket as if listen socket accepted it</h2>
    <i>struct lws *</i>
    <b>lws_adopt_socket</b>
    (<i>struct lws_context *</i> <b>context</b>,
    <i>lws_sockfd_type</i> <b>accept_fd</b>)
    
    <h3>Arguments</h3>
    <dl>
    <dt><b>context</b>
    
    Andy Green's avatar
    Andy Green committed
    <dd>lws context
    <dt><b>accept_fd</b>
    <dd>fd of already-accepted socket to adopt
    
    </dl>
    <h3>Description</h3>
    <blockquote>
    
    Andy Green's avatar
    Andy Green committed
    Either returns new wsi bound to accept_fd, or closes accept_fd and
    returns NULL, having cleaned up any new wsi pieces.
    <p>
    LWS adopts the socket in http serving mode, it's ready to accept an upgrade
    to ws or just serve http.
    
    </blockquote>
    <hr>
    
    Andy Green's avatar
    Andy Green committed
    <h2>lws_serve_http_file - Send a file back to the client using http</h2>
    <i>int</i>
    <b>lws_serve_http_file</b>
    (<i>struct lws *</i> <b>wsi</b>,
    <i>const char *</i> <b>file</b>,
    <i>const char *</i> <b>content_type</b>,
    <i>const char *</i> <b>other_headers</b>,
    <i>int</i> <b>other_headers_len</b>)
    <h3>Arguments</h3>
    <dl>
    <dt><b>wsi</b>
    <dd>Websocket instance (available from user callback)
    <dt><b>file</b>
    <dd>The file to issue over http
    <dt><b>content_type</b>
    <dd>The http content type, eg, text/html
    <dt><b>other_headers</b>
    <dd>NULL or pointer to header string
    <dt><b>other_headers_len</b>
    <dd>length of the other headers if non-NULL
    </dl>
    <h3>Description</h3>
    <blockquote>
    This function is intended to be called from the callback in response
    to http requests from the client.  It allows the callback to issue
    local files down the http link in a single step.
    <p>
    Returning &lt;0 indicates error and the wsi should be closed.  Returning
    &gt;0 indicates the file was completely sent and
    <b>lws_http_transaction_completed</b> called on the wsi (and close if != 0)
    ==0 indicates the file transfer is started and needs more service later,
    the wsi should be left alone.
    </blockquote>
    <hr>
    <h2>lws_service_fd_tsi - Service polled socket with something waiting</h2>
    <i>int</i>
    <b>lws_service_fd_tsi</b>
    (<i>struct lws_context *</i> <b>context</b>,
    <i>struct lws_pollfd *</i> <b>pollfd</b>,
    <i>int</i> <b>tsi</b>)
    
    <h3>Arguments</h3>
    <dl>
    
    <dt><b>context</b>
    <dd>Websocket context
    
    Andy Green's avatar
    Andy Green committed
    <dt><b>pollfd</b>
    <dd>The pollfd entry describing the socket fd and which events
    happened.
    
    </dl>
    <h3>Description</h3>
    <blockquote>
    
    Andy Green's avatar
    Andy Green committed
    This function takes a pollfd that has POLLIN or POLLOUT activity and
    services it according to the state of the associated
    struct lws.
    <p>
    The one call deals with all "service" that might happen on a socket
    including listen accepts, http files as well as websocket protocol.
    <p>
    If a pollfd says it has something, you can just pass it to
    <b>lws_service_fd</b> whether it is a socket handled by lws or not.
    If it sees it is a lws socket, the traffic will be handled and
    pollfd-&gt;revents will be zeroed now.
    <p>
    If the socket is foreign to lws, it leaves revents alone.  So you can
    see if you should service yourself by checking the pollfd revents
    after letting lws try to service it.
    
    </blockquote>
    <hr>
    
    Andy Green's avatar
    Andy Green committed
    <h2>lws_service - Service any pending websocket activity</h2>
    <i>int</i>
    <b>lws_service</b>
    (<i>struct lws_context *</i> <b>context</b>,
    <i>int</i> <b>timeout_ms</b>)
    
    <h3>Arguments</h3>
    <dl>
    
    <dt><b>context</b>
    <dd>Websocket context
    
    Andy Green's avatar
    Andy Green committed
    <dt><b>timeout_ms</b>
    <dd>Timeout for poll; 0 means return immediately if nothing needed
    service otherwise block and service immediately, returning
    after the timeout if nothing needed service.
    
    </dl>
    <h3>Description</h3>
    <blockquote>
    
    Andy Green's avatar
    Andy Green committed
    This function deals with any pending websocket traffic, for three
    kinds of event.  It handles these events on both server and client
    types of connection the same.
    
    Andy Green's avatar
    Andy Green committed
    1) Accept new connections to our context's server
    <p>
    2) Call the receive callback for incoming frame data received by
    server or client connections.
    <p>
    You need to call this service function periodically to all the above
    functions to happen; if your application is single-threaded you can
    just call it in your main event loop.
    <p>
    Alternatively you can fork a new process that asynchronously handles
    calling this service in a loop.  In that case you are happy if this
    call blocks your thread until it needs to take care of something and
    would call it with a large nonzero timeout.  Your loop then takes no
    CPU while there is nothing happening.
    <p>
    If you are calling it in a single-threaded app, you don't want it to
    wait around blocking other things in your loop from happening, so you
    would call it with a timeout_ms of 0, so it returns immediately if
    nothing is pending, or as soon as it services whatever was pending.
    
    </blockquote>
    <hr>
    
    Andy Green's avatar
    Andy Green committed
    <h2>struct lws_plat_file_ops - Platform-specific file operations</h2>
    <b>struct lws_plat_file_ops</b> {<br>
    &nbsp; &nbsp; <i>lws_filefd_type (*</i><b>open</b>) <i>(struct lws *wsi, const char *filename,unsigned long *filelen, int flags)</i>;<br>
    &nbsp; &nbsp; <i>int (*</i><b>close</b>) <i>(struct lws *wsi, lws_filefd_type fd)</i>;<br>
    &nbsp; &nbsp; <i>unsigned long (*</i><b>seek_cur</b>) <i>(struct lws *wsi, lws_filefd_type fd,long offset_from_cur_pos)</i>;<br>
    &nbsp; &nbsp; <i>int (*</i><b>read</b>) <i>(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,unsigned char *buf, unsigned long len)</i>;<br>
    &nbsp; &nbsp; <i>int (*</i><b>write</b>) <i>(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,unsigned char *buf, unsigned long len)</i>;<br>
    };<br>
    <h3>Members</h3>
    <dl>
    <dt><b>open</b>
    <dd>Open file (always binary access if plat supports it)
    filelen is filled on exit to be the length of the file
    flags should be set to O_RDONLY or O_RDWR
    <dt><b>close</b>
    <dd>Close file
    <dt><b>seek_cur</b>
    <dd>Seek from current position
    <dt><b>read</b>
    <dd>Read fron file *amount is set on exit to amount read
    <dt><b>write</b>
    <dd>Write to file *amount is set on exit as amount written
    </dl>
    <h3>Description</h3>
    <blockquote>
    <p>
    These provide platform-agnostic ways to deal with filesystem access in the
    library and in the user code.
    </blockquote>
    <hr>
    
    <h2>lws_callback_function - User server actions</h2>
    <i>typedef int</i>
    <b>lws_callback_function</b>
    (<i>struct lws *</i> <b>wsi</b>,
    
    <i>enum lws_callback_reasons</i> <b>reason</b>,
    
    Andy Green's avatar
    Andy Green committed
    <i>void *</i> <b>user</b>,
    <i>void *</i> <b>in</b>,
    <i>size_t</i> <b>len</b>)
    <h3>Arguments</h3>
    <dl>
    <dt><b>wsi</b>
    <dd>Opaque websocket instance pointer
    <dt><b>reason</b>
    <dd>The reason for the call
    <dt><b>user</b>
    <dd>Pointer to per-session user data allocated by library
    <dt><b>in</b>
    <dd>Pointer used for some callback reasons
    <dt><b>len</b>
    <dd>Length set for some callback reasons
    </dl>
    <h3>Description</h3>
    <blockquote>
    This callback is the way the user controls what is served.  All the
    protocol detail is hidden and handled by the library.
    <p>
    For each connection / session there is user data allocated that is
    pointed to by "user".  You set the size of this user data area when
    
    the library is initialized with lws_create_server.
    
    Andy Green's avatar
    Andy Green committed
    <p>
    You get an opportunity to initialize user data when called back with
    LWS_CALLBACK_ESTABLISHED reason.
    </blockquote>
    <h3>LWS_CALLBACK_ESTABLISHED</h3>
    <blockquote>
    
    after the server completes a handshake with
    
    Andy Green's avatar
    Andy Green committed
    an incoming client.  If you built the library
    with ssl support, <tt><b>in</b></tt> is a pointer to the
    ssl struct associated with the connection or
    NULL.
    
    <h3>LWS_CALLBACK_CLIENT_CONNECTION_ERROR</h3>
    <blockquote>
    the request client connection has
    
    been unable to complete a handshake with the remote server.  If
    in is non-NULL, you can find an error string of length len where
    it points to.
    
    <h3>LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH</h3>
    <blockquote>
    this is the last chance for the
    client user code to examine the http headers
    and decide to reject the connection.  If the
    content in the headers is interesting to the
    client (url, etc) it needs to copy it out at
    this point since it will be destroyed before
    the CLIENT_ESTABLISHED call
    </blockquote>
    
    <h3>LWS_CALLBACK_CLIENT_ESTABLISHED</h3>
    <blockquote>
    after your client connection completed
    a handshake with the remote server
    
    Andy Green's avatar
    Andy Green committed
    </blockquote>
    <h3>LWS_CALLBACK_CLOSED</h3>
    <blockquote>
    when the websocket session ends
    </blockquote>
    
    <h3>LWS_CALLBACK_CLOSED_HTTP</h3>
    <blockquote>
    when a HTTP (non-websocket) session ends