#include "private-libwebsockets.h"
-struct libwebsocket *libwebsocket_client_connect_2(
+struct libwebsocket *lws_client_connect_2(
struct libwebsocket_context *context,
struct libwebsocket *wsi
) {
int plen = 0;
const char *ads;
- lwsl_client("libwebsocket_client_connect_2\n");
+ lwsl_client("lws_client_connect_2\n");
/*
* proxy?
* handling as oom4 does. We have to run the whole close flow.
*/
- libwebsocket_set_timeout(wsi,
+ lws_set_timeout(wsi,
PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE,
AWAITING_TIMEOUT);
#ifdef LWS_USE_IPV6
goto failed;
}
- libwebsocket_set_timeout(wsi,
+ lws_set_timeout(wsi,
PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE,
AWAITING_TIMEOUT);
* cover with a timeout.
*/
- libwebsocket_set_timeout(wsi,
+ lws_set_timeout(wsi,
PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE, AWAITING_TIMEOUT);
wsi->mode = LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE;
pfd.fd = wsi->sock;
pfd.revents = LWS_POLLIN;
- n = libwebsocket_service_fd(context, &pfd);
+ n = lws_service_fd(context, &pfd);
if (n < 0)
goto failed;
}
/**
- * libwebsocket_client_connect() - Connect to another websocket server
+ * lws_client_connect() - Connect to another websocket server
* @context: Websocket context
* @address: Remote server address, eg, "myserver.com"
* @port: Port to connect to on the remote server, eg, 80
*/
LWS_VISIBLE struct libwebsocket *
-libwebsocket_client_connect(struct libwebsocket_context *context,
+lws_client_connect(struct libwebsocket_context *context,
const char *address,
int port,
int ssl_connection,
if (lws_ext_callback_for_each_extension_type(context, wsi,
LWS_EXT_CALLBACK_CAN_PROXY_CLIENT_CONNECTION,
(void *)address, port) > 0) {
- lwsl_client("libwebsocket_client_connect: ext handling conn\n");
+ lwsl_client("lws_client_connect: ext handling conn\n");
- libwebsocket_set_timeout(wsi,
+ lws_set_timeout(wsi,
PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE,
AWAITING_TIMEOUT);
wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT;
return wsi;
}
- lwsl_client("libwebsocket_client_connect: direct conn\n");
+ lwsl_client("lws_client_connect: direct conn\n");
- return libwebsocket_client_connect_2(context, wsi);
+ return lws_client_connect_2(context, wsi);
bail1:
lws_free(wsi->u.hdr.ah);
/**
- * libwebsocket_client_connect_extended() - Connect to another websocket server
+ * lws_client_connect_extended() - Connect to another websocket server
* @context: Websocket context
* @address: Remote server address, eg, "myserver.com"
* @port: Port to connect to on the remote server, eg, 80
*/
LWS_VISIBLE struct libwebsocket *
-libwebsocket_client_connect_extended(struct libwebsocket_context *context,
+lws_client_connect_extended(struct libwebsocket_context *context,
const char *address,
int port,
int ssl_connection,
void *userdata)
{
struct libwebsocket *ws =
- libwebsocket_client_connect(context, address, port,
+ lws_client_connect(context, address, port,
ssl_connection, path, host, origin, protocol,
ietf_version_or_minus_one);
* we do not care about how it went, we are closing
* immediately afterwards
*/
- libwebsocket_write(wsi, (unsigned char *)
+ lws_write(wsi, (unsigned char *)
&wsi->u.ws.rx_user_buffer[
LWS_SEND_BUFFER_PRE_PADDING],
wsi->u.ws.rx_user_buffer_head, LWS_WRITE_CLOSE);
wsi->u.ws.ping_pending_flag = 1;
/* get it sent as soon as possible */
- libwebsocket_callback_on_writable(wsi->protocol->owning_server, wsi);
+ lws_callback_on_writable(wsi->protocol->owning_server, wsi);
ping_drop:
wsi->u.ws.rx_user_buffer_head = 0;
handled = 1;
/*
* No it's real payload, pass it up to the user callback.
* It's nicely buffered with the pre-padding taken care of
- * so it can be sent straight out again using libwebsocket_write
+ * so it can be sent straight out again using lws_write
*/
if (handled)
goto already_done;
* timeout protection set in client-handshake.c
*/
- if (libwebsocket_client_connect_2(context, wsi) == NULL) {
+ if (lws_client_connect_2(context, wsi) == NULL) {
/* closed */
lwsl_client("closed\n");
return -1;
/* clear his proxy connection timeout */
- libwebsocket_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
+ lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
/* fallthru */
*/
/*
- * take care of our libwebsocket_callback_on_writable
+ * take care of our lws_callback_on_writable
* happening at a time when there's no real connection yet
*/
if (lws_change_pollfd(wsi, LWS_POLLOUT, 0))
lwsl_info(
"SSL_connect WANT_WRITE... retrying\n");
- libwebsocket_callback_on_writable(
+ lws_callback_on_writable(
context, wsi);
some_wait:
wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_SSL;
*/
lwsl_info("SSL_connect WANT_WRITE... retrying\n");
- libwebsocket_callback_on_writable(context, wsi);
+ lws_callback_on_writable(context, wsi);
goto some_wait;
}
#endif
wsi->mode = LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE2;
- libwebsocket_set_timeout(wsi,
+ lws_set_timeout(wsi,
PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND,
AWAITING_TIMEOUT);
LWS_CLOSE_STATUS_NOSTATUS);
return 0;
case LWS_SSL_CAPABLE_MORE_SERVICE:
- libwebsocket_callback_on_writable(context, wsi);
+ lws_callback_on_writable(context, wsi);
break;
}
wsi->u.hdr.parser_state = WSI_TOKEN_NAME_PART;
wsi->u.hdr.lextable_pos = 0;
wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY;
- libwebsocket_set_timeout(wsi,
+ lws_set_timeout(wsi,
PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE,
AWAITING_TIMEOUT);
break;
/* clear his proxy connection timeout */
- libwebsocket_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
+ lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
/* free up his parsing allocations */
* create the random key
*/
- n = libwebsockets_get_random(context, hash, 16);
+ n = lws_get_random(context, hash, 16);
if (n != 16) {
lwsl_err("Unable to read from random dev %s\n",
SYSTEM_RANDOM_FILEPATH);
key_b64[39] = '\0'; /* enforce composed length below buf sizeof */
n = sprintf(buf, "%s258EAFA5-E914-47DA-95CA-C5AB0DC85B11", key_b64);
- libwebsockets_SHA1((unsigned char *)buf, n, (unsigned char *)hash);
+ lws_SHA1((unsigned char *)buf, n, (unsigned char *)hash);
lws_b64_encode_string(hash, 20,
wsi->u.hdr.ah->initial_handshake_hash_base64,
}
/**
- * libwebsocket_create_context() - Create the websocket handler
+ * lws_create_context() - Create the websocket handler
* @info: pointer to struct with parameters
*
* This function creates the listening socket (if serving) and takes care
*
* After initialization, it returns a struct libwebsocket_context * that
* represents this server. After calling, user code needs to take care
- * of calling libwebsocket_service() with the context pointer to get the
+ * of calling lws_service() with the context pointer to get the
* server's sockets serviced. This must be done in the same process
* context as the initialization call.
*
*/
LWS_VISIBLE struct libwebsocket_context *
-libwebsocket_create_context(struct lws_context_creation_info *info)
+lws_create_context(struct lws_context_creation_info *info)
{
struct libwebsocket_context *context = NULL;
char *p;
#ifdef LWS_USE_LIBEV
/* (Issue #264) In order to *avoid breaking backwards compatibility*, we
* enable libev mediated SIGINT handling with a default handler of
- * libwebsocket_sigint_cb. The handler can be overridden or disabled
- * by invoking libwebsocket_sigint_cfg after creating the context, but
- * before invoking libwebsocket_initloop:
+ * lws_sigint_cb. The handler can be overridden or disabled
+ * by invoking lws_sigint_cfg after creating the context, but
+ * before invoking lws_initloop:
*/
context->use_ev_sigint = 1;
- context->lws_ev_sigint_cb = &libwebsocket_sigint_cb;
+ context->lws_ev_sigint_cb = &lws_sigint_cb;
#endif /* LWS_USE_LIBEV */
/* to reduce this allocation, */
goto bail;
}
- if (lws_plat_init_lookup(context)) {
+ if (lws_plat_init_lookup(context))
goto bail;
- }
- if (lws_plat_init_fd_tables(context)) {
+ if (lws_plat_init_fd_tables(context))
goto bail;
- }
lws_context_init_extensions(info, context);
/* override for backwards compatibility */
if (info->http_proxy_port)
context->http_proxy_port = info->http_proxy_port;
- libwebsocket_set_proxy(context, info->http_proxy_address);
+ lws_set_proxy(context, info->http_proxy_address);
} else {
#ifdef LWS_HAVE_GETENV
p = getenv("http_proxy");
if (p)
- libwebsocket_set_proxy(context, p);
+ lws_set_proxy(context, p);
#endif
}
return context;
bail:
- libwebsocket_context_destroy(context);
+ lws_context_destroy(context);
return NULL;
}
/**
- * libwebsocket_context_destroy() - Destroy the websocket context
+ * lws_context_destroy() - Destroy the websocket context
* @context: Websocket context
*
* This function closes any active connections and then frees the
* undefined.
*/
LWS_VISIBLE void
-libwebsocket_context_destroy(struct libwebsocket_context *context)
+lws_context_destroy(struct libwebsocket_context *context)
{
/* Note that this is used for freeing partially allocated structs as well
* so make sure you don't try to free something uninitialized */
lwsl_info(" LWS_MAX_EXTENSIONS_ACTIVE: %u\n", LWS_MAX_EXTENSIONS_ACTIVE);
}
-LWS_VISIBLE struct libwebsocket_extension *libwebsocket_get_internal_extensions()
+LWS_VISIBLE struct libwebsocket_extension *lws_get_internal_extensions()
{
return libwebsocket_internal_extensions;
}
* Yes, he's choked. Don't spill the rest now get a callback
* when he is ready to send and take care of it there
*/
- libwebsocket_callback_on_writable(
+ lws_callback_on_writable(
wsi->protocol->owning_server, wsi);
wsi->extension_data_pending = 1;
ret = 0;
*/
LWS_VISIBLE int
-libwebsocket_read(struct libwebsocket_context *context,
+lws_read(struct libwebsocket_context *context,
struct libwebsocket *wsi, unsigned char *buf, size_t len)
{
size_t n;
wsi->u.http.content_remain = wsi->u.http.content_length;
if (!wsi->u.http.content_remain) {
/* there is no POST content */
- libwebsocket_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
+ lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
if (wsi->protocol->callback) {
n = wsi->protocol->callback(
wsi->protocol->owning_server, wsi,
if (!wsi->u.http.content_remain) {
/* he sent the content in time */
- libwebsocket_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
+ lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
if (wsi->protocol->callback) {
n = wsi->protocol->callback(
wsi->protocol->owning_server, wsi,
}
goto http_complete;
} else
- libwebsocket_set_timeout(wsi,
+ lws_set_timeout(wsi,
PENDING_TIMEOUT_HTTP_CONTENT,
AWAITING_TIMEOUT);
}
}
break;
default:
- lwsl_err("libwebsocket_read: Unhandled state\n");
+ lwsl_err("lws_read: Unhandled state\n");
break;
}
read_ok:
/* Nothing more to do for now. */
- lwsl_debug("libwebsocket_read: read_ok\n");
+ lwsl_debug("lws_read: read_ok\n");
return 0;
http_complete:
- lwsl_debug("libwebsocket_read: http_complete\n");
+ lwsl_debug("lws_read: http_complete\n");
#ifndef LWS_NO_SERVER
/* Did the client want to keep the HTTP connection going? */
return 0;
bail:
- lwsl_debug("closing connection at libwebsocket_read bail:\n");
+ lwsl_debug("closing connection at lws_read bail:\n");
libwebsocket_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
}
/**
- * libwebsockets_return_http_status() - Return simple http status
+ * lws_return_http_status() - Return simple http status
* @context: libwebsockets context
* @wsi: Websocket instance (available from user callback)
* @code: Status index, eg, 404
* Helper to report HTTP errors back to the client cleanly and
* consistently
*/
-LWS_VISIBLE int libwebsockets_return_http_status(
+LWS_VISIBLE int lws_return_http_status(
struct libwebsocket_context *context, struct libwebsocket *wsi,
unsigned int code, const char *html_body)
{
if (lws_finalize_http_header(context, wsi, &p, end))
return 1;
- m = libwebsocket_write(wsi, start, p - start, LWS_WRITE_HTTP_HEADERS);
+ m = lws_write(wsi, start, p - start, LWS_WRITE_HTTP_HEADERS);
if (m != (int)(p - start))
return 1;
n = sprintf((char *)start, "<html><body><h1>%u</h1>%s</body></html>", code, html_body);
- m = libwebsocket_write(wsi, start, n, LWS_WRITE_HTTP);
+ m = lws_write(wsi, start, n, LWS_WRITE_HTTP);
return m != n;
}
if (swsi->u.http2.waiting_tx_credit && swsi->u.http2.tx_credit > 0) {
lwsl_info("%s: %p: waiting_tx_credit -> wait on writeable\n", __func__, wsi);
swsi->u.http2.waiting_tx_credit = 0;
- libwebsocket_callback_on_writable(context, swsi);
+ lws_callback_on_writable(context, swsi);
}
break;
}
if (revents & EV_WRITE)
eventfd.revents |= LWS_POLLOUT;
- libwebsocket_service_fd(context, &eventfd);
+ lws_service_fd(context, &eventfd);
}
LWS_VISIBLE void
-libwebsocket_sigint_cb(struct ev_loop *loop,
+lws_sigint_cb(struct ev_loop *loop,
struct ev_signal *watcher, int revents)
{
ev_break(loop, EVBREAK_ALL);
}
-LWS_VISIBLE int libwebsocket_sigint_cfg(
+LWS_VISIBLE int lws_sigint_cfg(
struct libwebsocket_context *context,
int use_ev_sigint,
lws_ev_signal_cb* cb)
context->lws_ev_sigint_cb = cb;
}
else {
- context->lws_ev_sigint_cb = &libwebsocket_sigint_cb;
+ context->lws_ev_sigint_cb = &lws_sigint_cb;
};
return 0;
};
LWS_VISIBLE int
-libwebsocket_initloop(
+lws_initloop(
struct libwebsocket_context *context,
struct ev_loop *loop)
{
case WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE:
if (wsi->truncated_send_len) {
- libwebsocket_callback_on_writable(context, wsi);
+ lws_callback_on_writable(context, wsi);
return;
}
lwsl_info("wsi %p completed WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE\n", wsi);
if (wsi->truncated_send_len) {
lwsl_info("wsi %p entering WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE\n", wsi);
wsi->state = WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE;
- libwebsocket_set_timeout(wsi, PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE, 5);
+ lws_set_timeout(wsi, PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE, 5);
return;
}
break;
} while (ret);
/*
- * signal we are closing, libwebsocket_write will
+ * signal we are closing, lws_write will
* add any necessary version-specific stuff. If the write fails,
* no worries we are closing anyway. If we didn't initiate this
* close, then our state has been changed to
/* make valgrind happy */
memset(buf, 0, sizeof(buf));
- n = libwebsocket_write(wsi,
+ n = lws_write(wsi,
&buf[LWS_SEND_BUFFER_PRE_PADDING + 2],
0, LWS_WRITE_CLOSE);
if (n >= 0) {
* out of politeness
*/
- libwebsocket_set_timeout(wsi,
+ lws_set_timeout(wsi,
PENDING_TIMEOUT_CLOSE_ACK, 1);
lwsl_debug("sent close indication, awaiting ack\n");
}
/**
- * libwebsockets_get_peer_addresses() - Get client address information
+ * lws_get_peer_addresses() - Get client address information
* @context: Libwebsockets context
* @wsi: Local struct libwebsocket associated with
* @fd: Connection socket descriptor
*/
LWS_VISIBLE void
-libwebsockets_get_peer_addresses(struct libwebsocket_context *context,
+lws_get_peer_addresses(struct libwebsocket_context *context,
struct libwebsocket *wsi, lws_sockfd_type fd, char *name, int name_len,
char *rip, int rip_len)
{
ret = libwebsockets_get_addresses(context, p, name, name_len, rip, rip_len);
bail:
- lws_latency(context, wsi, "libwebsockets_get_peer_addresses", ret, 1);
+ lws_latency(context, wsi, "lws_get_peer_addresses", ret, 1);
#else
(void)context;
(void)wsi;
}
/**
- * libwebsocket_context_user() - get the user data associated with the context
+ * lws_context_user() - get the user data associated with the context
* @context: Websocket context
*
* This returns the optional user allocation that can be attached to
* using globals statics in the user code.
*/
LWS_EXTERN void *
-libwebsocket_context_user(struct libwebsocket_context *context)
+lws_context_user(struct libwebsocket_context *context)
{
return context->user_space;
}
/**
- * libwebsocket_callback_all_protocol() - Callback all connections using
+ * lws_callback_all_protocol() - Callback all connections using
* the given protocol with the given reason
*
* @protocol: Protocol whose connections will get callbacks
*/
LWS_VISIBLE int
-libwebsocket_callback_all_protocol(
+lws_callback_all_protocol(
const struct libwebsocket_protocols *protocol, int reason)
{
struct libwebsocket_context *context = protocol->owning_server;
}
/**
- * libwebsocket_set_timeout() - marks the wsi as subject to a timeout
+ * lws_set_timeout() - marks the wsi as subject to a timeout
*
* You will not need this unless you are doing something special
*
*/
LWS_VISIBLE void
-libwebsocket_set_timeout(struct libwebsocket *wsi,
+lws_set_timeout(struct libwebsocket *wsi,
enum pending_timeout reason, int secs)
{
time_t now;
#if LWS_POSIX
/**
- * libwebsocket_get_socket_fd() - returns the socket file descriptor
+ * lws_get_socket_fd() - returns the socket file descriptor
*
* You will not need this unless you are doing something special
*
*/
LWS_VISIBLE int
-libwebsocket_get_socket_fd(struct libwebsocket *wsi)
+lws_get_socket_fd(struct libwebsocket *wsi)
{
return wsi->sock;
}
/**
- * libwebsocket_rx_flow_control() - Enable and disable socket servicing for
+ * 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
*/
LWS_VISIBLE int
-libwebsocket_rx_flow_control(struct libwebsocket *wsi, int enable)
+lws_rx_flow_control(struct libwebsocket *wsi, int enable)
{
if (enable == (wsi->rxflow_change_to & LWS_RXFLOW_ALLOW))
return 0;
- lwsl_info("libwebsocket_rx_flow_control(0x%p, %d)\n", wsi, enable);
+ lwsl_info("lws_rx_flow_control(0x%p, %d)\n", wsi, enable);
wsi->rxflow_change_to = LWS_RXFLOW_PENDING_CHANGE | !!enable;
return 0;
}
/**
- * libwebsocket_rx_flow_allow_all_protocol() - Allow all connections with this protocol to receive
+ * 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
*/
LWS_VISIBLE void
-libwebsocket_rx_flow_allow_all_protocol(
+lws_rx_flow_allow_all_protocol(
const struct libwebsocket_protocols *protocol)
{
struct libwebsocket_context *context = protocol->owning_server;
if (!wsi)
continue;
if (wsi->protocol == protocol)
- libwebsocket_rx_flow_control(wsi, LWS_RXFLOW_ALLOW);
+ lws_rx_flow_control(wsi, LWS_RXFLOW_ALLOW);
}
}
/**
- * libwebsocket_canonical_hostname() - returns this host's hostname
+ * lws_canonical_hostname() - returns this host's hostname
*
* 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
* @context: Websocket context
*/
LWS_VISIBLE extern const char *
-libwebsocket_canonical_hostname(struct libwebsocket_context *context)
+lws_canonical_hostname(struct libwebsocket_context *context)
{
return (const char *)context->canonical_hostname;
}
n = callback_function(context, wsi, reason, user, in, len);
if (!n)
- n = _libwebsocket_rx_flow_control(wsi);
+ n = _lws_rx_flow_control(wsi);
return n;
}
/**
- * libwebsocket_set_proxy() - Setups proxy to libwebsocket_context.
+ * lws_set_proxy() - Setups proxy to libwebsocket_context.
* @context: pointer to struct libwebsocket_context you want set proxy to
* @proxy: pointer to c string containing proxy in format address:port
*
*/
LWS_VISIBLE int
-libwebsocket_set_proxy(struct libwebsocket_context *context, const char *proxy)
+lws_set_proxy(struct libwebsocket_context *context, const char *proxy)
{
char *p;
char authstring[96];
}
/**
- * libwebsockets_get_protocol() - Returns a protocol pointer from a websocket
+ * lws_get_protocol() - Returns a protocol pointer from a websocket
* connection.
* @wsi: pointer to struct websocket you want to know the protocol of
*
*/
LWS_VISIBLE const struct libwebsocket_protocols *
-libwebsockets_get_protocol(struct libwebsocket *wsi)
+lws_get_protocol(struct libwebsocket *wsi)
{
return wsi->protocol;
}
LWS_VISIBLE int
-libwebsocket_is_final_fragment(struct libwebsocket *wsi)
+lws_is_final_fragment(struct libwebsocket *wsi)
{
return wsi->u.ws.final;
}
LWS_VISIBLE unsigned char
-libwebsocket_get_reserved_bits(struct libwebsocket *wsi)
+lws_get_reserved_bits(struct libwebsocket *wsi)
{
return wsi->u.ws.rsv;
}
* lws_partial_buffered() - find out if lws buffered the last write
* @wsi: websocket connection to check
*
- * Returns 1 if you cannot use libwebsocket_write because the last
+ * 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.
*
- * If you will try to do >1 libwebsocket_write call inside a single
+ * If you will try to do >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.
*
if (wsi->pps)
lwsl_err("pps overwrite\n");
wsi->pps = pend;
- libwebsocket_rx_flow_control(wsi, 0);
- libwebsocket_callback_on_writable(context, wsi);
+ lws_rx_flow_control(wsi, 0);
+ lws_callback_on_writable(context, wsi);
}
LWS_VISIBLE size_t
#define libwebsockets_SHA1 lws_SHA1
#define libwebsocket_read lws_read
#define libwebsocket_get_internal_extensions lws_get_internal_extensions
-
+#define libwebsocket_write_protocol lws_write_protocol
#ifdef __cplusplus
#include <cstddef>
LWS_EXT_CALLBACK_PAYLOAD_RX,
};
-enum libwebsocket_write_protocol {
+enum lws_write_protocol {
LWS_WRITE_TEXT,
LWS_WRITE_BINARY,
LWS_WRITE_CONTINUATION,
* for example, to send a script to the client
* which will then open the websockets connection.
* @in points to the URI path requested and
- * libwebsockets_serve_http_file() makes it very
+ * lws_serve_http_file() makes it very
* simple to send back a file to the client.
* Normally after sending the file you are done
* with the http connection, since the rest of the
*
* LWS_CALLBACK_CLIENT_WRITEABLE:
* LWS_CALLBACK_SERVER_WRITEABLE: If you call
- * libwebsocket_callback_on_writable() on a connection, you will
+ * lws_callback_on_writable() on a connection, you will
* get one of these callbacks coming when the connection socket
* is able to accept another write packet without blocking.
* If it already was able to take another packet without blocking,
* you support. If the frame size is exceeded, there is no
* error, but the buffer will spill to the user callback when
* full, which you can detect by using
- * libwebsockets_remaining_packet_payload(). Notice that you
+ * lws_remaining_packet_payload(). Notice that you
* just talk about frame size here, the LWS_SEND_BUFFER_PRE_PADDING
* and post-padding are automatically also allocated on top.
* @id: ignored by lws, but useful to contain user information bound
* switch (wsi->protocol->id), user code might use some bits as
* capability flags based on selected protocol version, etc.
* @user: User provided context data at the protocol level.
- * Accessible via libwebsockets_get_protocol(wsi)->user
+ * Accessible via lws_get_protocol(wsi)->user
* This should not be confused with wsi->user, it is not the same.
* The library completely ignores any value in here.
* @owning_server: the server init call fills in this opaque pointer when
* @uid: user id to change to after setting listen socket, or -1.
* @options: 0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK
* @user: optional user pointer that can be recovered via the context
- * pointer using libwebsocket_context_user
+ * pointer using lws_context_user
* @ka_time: 0 for no keepalive, otherwise apply this keepalive timeout to
* all libwebsocket sockets, client or server
* @ka_probes: if ka_time was nonzero, after the timeout expires how many
* This allows us to add protocol info before and after the data, and send as
* one packet on the network without payload copying, for maximum efficiency.
*
- * So for example you need this kind of code to use libwebsocket_write with a
+ * So for example you need this kind of code to use lws_write with a
* 128-byte payload
*
* char buf[LWS_SEND_BUFFER_PRE_PADDING + 128 + LWS_SEND_BUFFER_POST_PADDING];
* // fill your part of the buffer... for example here it's all zeros
* memset(&buf[LWS_SEND_BUFFER_PRE_PADDING], 0, 128);
*
- * libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], 128,
+ * lws_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], 128,
* LWS_WRITE_TEXT);
*
* When sending LWS_WRITE_HTTP, there is no protocol addition and you can just
LWS_VISIBLE LWS_EXTERN int
lws_write(struct libwebsocket *wsi, unsigned char *buf, size_t len,
- enum libwebsocket_write_protocol protocol);
+ enum lws_write_protocol protocol);
/* helper for case where buffer may be const */
#define lws_write_http(wsi, buf, len) \
return 0;
}
-LWS_VISIBLE int libwebsockets_get_random(struct libwebsocket_context *context,
+LWS_VISIBLE int lws_get_random(struct libwebsocket_context *context,
void *buf, int len)
{
(void)context;
}
/**
- * libwebsocket_cancel_service() - Cancel servicing of pending websocket activity
+ * lws_cancel_service() - Cancel servicing of pending websocket activity
* @context: Websocket context
*
- * This function let a call to libwebsocket_service() waiting for a timeout
+ * This function let a call to lws_service() waiting for a timeout
* immediately return.
*
* There is no poll() in MBED3, he will fire callbacks when he feels like
* it.
*/
LWS_VISIBLE void
-libwebsocket_cancel_service(struct libwebsocket_context *context)
+lws_cancel_service(struct libwebsocket_context *context)
{
(void)context;
}
lwsl_debug("%s: wsi %p\r\n", __func__, (void *)wsi);
- libwebsocket_service_fd(wsi->protocol->owning_server, &pollfd);
+ lws_service_fd(wsi->protocol->owning_server, &pollfd);
}
extern "C" void mbed3_tcp_stream_bind(void *sock, int port, struct libwebsocket *wsi)
lwsl_debug("%s: lws %p\n", __func__, wsi);
- return libwebsocket_service_fd(wsi->protocol->owning_server, &pollfd);
+ return lws_service_fd(wsi->protocol->owning_server, &pollfd);
}
/*
lwsl_debug("%s: wsi %p (servicing now)\r\n", __func__, (void *)wsi);
- libwebsocket_service_fd(wsi->protocol->owning_server, &pollfd);
+ lws_service_fd(wsi->protocol->owning_server, &pollfd);
}
void lws_conn_listener::onError(Socket *s, socket_error_t err)
return ((unsigned long long)tv.tv_sec * 1000000LL) + tv.tv_usec;
}
-LWS_VISIBLE int libwebsockets_get_random(struct libwebsocket_context *context,
+LWS_VISIBLE int lws_get_random(struct libwebsocket_context *context,
void *buf, int len)
{
return read(context->fd_random, (char *)buf, len);
}
/**
- * libwebsocket_cancel_service() - Cancel servicing of pending websocket activity
+ * lws_cancel_service() - Cancel servicing of pending websocket activity
* @context: Websocket context
*
- * This function let a call to libwebsocket_service() waiting for a timeout
+ * This function let a call to lws_service() waiting for a timeout
* immediately return.
*/
LWS_VISIBLE void
-libwebsocket_cancel_service(struct libwebsocket_context *context)
+lws_cancel_service(struct libwebsocket_context *context)
{
char buf = 0;
#else
if (n == 0) /* poll timeout */ {
#endif
- libwebsocket_service_fd(context, NULL);
+ lws_service_fd(context, NULL);
return 0;
}
continue;
}
- m = libwebsocket_service_fd(context, &context->fds[n]);
+ m = lws_service_fd(context, &context->fds[n]);
if (m < 0)
return -1;
/* if something closed, retry this slot */
return 1;
}
-LWS_VISIBLE int libwebsockets_get_random(struct libwebsocket_context *context,
+LWS_VISIBLE int lws_get_random(struct libwebsocket_context *context,
void *buf, int len)
{
int n;
}
/**
- * libwebsocket_cancel_service() - Cancel servicing of pending websocket activity
+ * lws_cancel_service() - Cancel servicing of pending websocket activity
* @context: Websocket context
*
- * This function let a call to libwebsocket_service() waiting for a timeout
+ * This function let a call to lws_service() waiting for a timeout
* immediately return.
*/
LWS_VISIBLE void
-libwebsocket_cancel_service(struct libwebsocket_context *context)
+lws_cancel_service(struct libwebsocket_context *context)
{
WSASetEvent(context->events[0]);
}
if (!wsi || wsi->sock_send_blocking)
continue;
pfd->revents = LWS_POLLOUT;
- n = libwebsocket_service_fd(context, pfd);
+ n = lws_service_fd(context, pfd);
if (n < 0)
return n;
}
context->service_tid = 0;
if (ev == WSA_WAIT_TIMEOUT) {
- libwebsocket_service_fd(context, NULL);
+ lws_service_fd(context, NULL);
return 0;
}
wsi->sock_send_blocking = FALSE;
}
- return libwebsocket_service_fd(context, pfd);
+ return lws_service_fd(context, pfd);
}
LWS_VISIBLE int
/* fetch the per-frame nonce */
- n = libwebsockets_get_random(wsi->protocol->owning_server,
+ n = lws_get_random(wsi->protocol->owning_server,
wsi->u.ws.frame_masking_nonce_04, 4);
if (n != 4) {
lwsl_parser("Unable to read from random device %s %d\n",
}
}
/* always callback on writeable */
- libwebsocket_callback_on_writable(
+ lws_callback_on_writable(
wsi->protocol->owning_server, wsi);
return n;
memcpy(wsi->truncated_send_malloc, buf + n, real_len - n);
/* since something buffered, force it to get another chance to send */
- libwebsocket_callback_on_writable(wsi->protocol->owning_server, wsi);
+ lws_callback_on_writable(wsi->protocol->owning_server, wsi);
return real_len;
}
/**
- * libwebsocket_write() - Apply protocol then write data to client
+ * lws_write() - Apply protocol then write data to client
* @wsi: Websocket instance (available from user callback)
* @buf: The data to send. For data being sent on a websocket
* connection (ie, not default http), this buffer MUST have
* pressure at any given time.
*/
-LWS_VISIBLE int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf,
- size_t len, enum libwebsocket_write_protocol protocol)
+LWS_VISIBLE int lws_write(struct libwebsocket *wsi, unsigned char *buf,
+ size_t len, enum lws_write_protocol protocol)
{
int n;
int pre = 0;
if (len == 0 && protocol != LWS_WRITE_CLOSE &&
protocol != LWS_WRITE_PING && protocol != LWS_WRITE_PONG) {
- lwsl_warn("zero length libwebsocket_write attempt\n");
+ lwsl_warn("zero length lws_write attempt\n");
return 0;
}
/*
* it is how many bytes of user buffer got sent... may be < orig_len
* in which case callback when writable has already been arranged
- * and user code can call libwebsocket_write() again with the rest
+ * and user code can call lws_write() again with the rest
* later.
*/
return n - (pre + post);
}
-LWS_VISIBLE int libwebsockets_serve_http_file_fragment(
+LWS_VISIBLE int lws_serve_http_file_fragment(
struct libwebsocket_context *context, struct libwebsocket *wsi)
{
int n;
if (lws_issue_raw(wsi, wsi->truncated_send_malloc +
wsi->truncated_send_offset,
wsi->truncated_send_len) < 0) {
- lwsl_info("closing from libwebsockets_serve_http_file_fragment\n");
+ lwsl_info("closing from lws_serve_http_file_fragment\n");
return -1;
}
continue;
if (n < 0)
return -1; /* caller will close */
if (n) {
- libwebsocket_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, AWAITING_TIMEOUT);
+ lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, AWAITING_TIMEOUT);
wsi->u.http.filepos += n;
- m = libwebsocket_write(wsi, context->service_buffer, n,
+ m = lws_write(wsi, context->service_buffer, n,
wsi->u.http.filepos == wsi->u.http.filelen ? LWS_WRITE_HTTP_FINAL : LWS_WRITE_HTTP);
if (m < 0)
return -1;
}
lwsl_info("choked before able to send whole file (post)\n");
- libwebsocket_callback_on_writable(context, wsi);
+ lws_callback_on_writable(context, wsi);
return 0; /* indicates further processing must be done */
}
wsi->u.ws.ping_pending_flag = 1;
/* get it sent as soon as possible */
- libwebsocket_callback_on_writable(wsi->protocol->owning_server, wsi);
+ lws_callback_on_writable(wsi->protocol->owning_server, wsi);
ping_drop:
wsi->u.ws.rx_user_buffer_head = 0;
return 0;
/*
* No it's real payload, pass it up to the user callback.
* It's nicely buffered with the pre-padding taken care of
- * so it can be sent straight out again using libwebsocket_write
+ * so it can be sent straight out again using lws_write
*/
eff_buf.token = &wsi->u.ws.rx_user_buffer[
/**
- * libwebsockets_remaining_packet_payload() - Bytes to come before "overall"
+ * lws_remaining_packet_payload() - Bytes to come before "overall"
* rx packet is complete
* @wsi: Websocket instance (available from user callback)
*
* 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 libwebsockets_remaining_packet_payload() will return
+ * when that is the case lws_remaining_packet_payload() will return
* 0.
*
* Many protocols won't care becuse their packets are always small.
*/
LWS_VISIBLE size_t
-libwebsockets_remaining_packet_payload(struct libwebsocket *wsi)
+lws_remaining_packet_payload(struct libwebsocket *wsi)
{
return wsi->u.ws.rx_packet_length;
}
if (tid == -1)
return -1;
if (tid != sampled_tid)
- libwebsocket_cancel_service(context);
+ lws_cancel_service(context);
}
}
/**
- * libwebsocket_callback_on_writable() - Request a callback when this socket
+ * lws_callback_on_writable() - Request a callback when this socket
* becomes able to be written to without
* blocking
*
*/
LWS_VISIBLE int
-libwebsocket_callback_on_writable(struct libwebsocket_context *context,
+lws_callback_on_writable(struct libwebsocket_context *context,
struct libwebsocket *wsi)
{
#ifdef LWS_USE_HTTP2
}
/**
- * libwebsocket_callback_on_writable_all_protocol() - Request a callback for
+ * 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.
*/
LWS_VISIBLE int
-libwebsocket_callback_on_writable_all_protocol(
+lws_callback_on_writable_all_protocol(
const struct libwebsocket_protocols *protocol)
{
struct libwebsocket_context *context = protocol->owning_server;
if (!wsi)
continue;
if (wsi->protocol == protocol)
- libwebsocket_callback_on_writable(context, wsi);
+ lws_callback_on_writable(context, wsi);
}
return 0;
char mode; /* enum connection_mode */
char state; /* enum lws_connection_states */
char lws_rx_parse_state; /* enum lws_rx_parse_state */
- char rx_frame_type; /* enum libwebsocket_write_protocol */
+ char rx_frame_type; /* enum lws_write_protocol */
unsigned int hdr_parsing_completed:1;
unsigned int user_space_externally_allocated:1;
LWS_EXTERN int
-libwebsocket_service_timeout_check(struct libwebsocket_context *context,
+lws_service_timeout_check(struct libwebsocket_context *context,
struct libwebsocket *wsi, unsigned int sec);
LWS_EXTERN struct libwebsocket *
-libwebsocket_client_connect_2(struct libwebsocket_context *context,
+lws_client_connect_2(struct libwebsocket_context *context,
struct libwebsocket *wsi);
LWS_EXTERN struct libwebsocket *
unsigned char *buf, size_t len);
LWS_EXTERN int
-_libwebsocket_rx_flow_control(struct libwebsocket *wsi);
+_lws_rx_flow_control(struct libwebsocket *wsi);
LWS_EXTERN void
lws_union_transition(struct libwebsocket *wsi, enum connection_mode mode);
LWS_EXTERN int lws_server_socket_service(
struct libwebsocket_context *context,
struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd);
- LWS_EXTERN int _libwebsocket_rx_flow_control(struct libwebsocket *wsi);
+ LWS_EXTERN int _lws_rx_flow_control(struct libwebsocket *wsi);
LWS_EXTERN int lws_handshake_server(struct libwebsocket_context *context,
struct libwebsocket *wsi, unsigned char **buf, size_t len);
#else
#define lws_server_socket_service(_a, _b, _c) (0)
-#define _libwebsocket_rx_flow_control(_a) (0)
+#define _lws_rx_flow_control(_a) (0)
#define lws_handshake_server(_a, _b, _c, _d) (0)
#endif
"%s258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
lws_hdr_simple_ptr(wsi, WSI_TOKEN_KEY));
- libwebsockets_SHA1(context->service_buffer, n, hash);
+ lws_SHA1(context->service_buffer, n, hash);
accept_len = lws_b64_encode_string((char *)hash, 20,
(char *)context->service_buffer,
#ifdef DEBUG
fwrite(response, 1, p - response, stderr);
#endif
- n = libwebsocket_write(wsi, (unsigned char *)response,
+ n = lws_write(wsi, (unsigned char *)response,
p - response, LWS_WRITE_HTTP_HEADERS);
if (n != (p - response)) {
lwsl_debug("handshake_0405: ERROR writing to socket\n");
}
int
-_libwebsocket_rx_flow_control(struct libwebsocket *wsi)
+_lws_rx_flow_control(struct libwebsocket *wsi)
{
struct libwebsocket_context *context = wsi->protocol->owning_server;
/* stuff is still buffered, not ready to really accept new input */
if (wsi->rxflow_buffer) {
/* get ourselves called back to deal with stashed buffer */
- libwebsocket_callback_on_writable(context, wsi);
+ lws_callback_on_writable(context, wsi);
return 0;
}
* if there is content supposed to be coming,
* put a timeout on it having arrived
*/
- libwebsocket_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT,
+ lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT,
AWAITING_TIMEOUT);
if (wsi->protocol->callback)
* HTTP keep-alive. No keep-alive header allocation for
* ISSUING_FILE, as this uses HTTP/1.0.
*
- * In any case, return 0 and let libwebsocket_read decide how to
+ * In any case, return 0 and let lws_read decide how to
* proceed based on state
*/
if (wsi->state != WSI_STATE_HTTP_ISSUING_FILE)
lwsl_parser("libwebsocket_parse sees parsing complete\n");
wsi->mode = LWS_CONNMODE_PRE_WS_SERVING_ACCEPT;
- libwebsocket_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
+ lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
/* is this websocket protocol or normal http 1.0? */
upgrade_ws:
if (!wsi->protocol)
- lwsl_err("NULL protocol at libwebsocket_read\n");
+ lwsl_err("NULL protocol at lws_read\n");
/*
* It's websocket
wsi->u.http.content_length = 0;
/* He asked for it to stay alive indefinitely */
- libwebsocket_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
+ lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
if (lws_allocate_header_table(wsi))
return 1;
if (wsi->state != WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE) {
/* hm this may want to send (via HTTP callback for example) */
- n = libwebsocket_read(context, wsi,
+ n = lws_read(context, wsi,
context->service_buffer, len);
if (n < 0)
/* we closed wsi */
}
/* >0 == completion, <0 == error */
- n = libwebsockets_serve_http_file_fragment(context, wsi);
+ n = lws_serve_http_file_fragment(context, wsi);
if (n < 0 || (n > 0 && lws_http_transaction_completed(wsi)))
goto fail;
break;
new_wsi->sock = accept_fd;
/* the transport is accepted... give him time to negotiate */
- libwebsocket_set_timeout(new_wsi,
+ lws_set_timeout(new_wsi,
PENDING_TIMEOUT_ESTABLISH_WITH_SERVER,
AWAITING_TIMEOUT);
}
/**
- * libwebsockets_serve_http_file() - Send a file back to the client using http
+ * lws_serve_http_file() - Send a file back to the client using http
* @context: libwebsockets context
* @wsi: Websocket instance (available from user callback)
* @file: The file to issue over http
* the wsi should be left alone.
*/
-LWS_VISIBLE int libwebsockets_serve_http_file(
+LWS_VISIBLE int lws_serve_http_file(
struct libwebsocket_context *context,
struct libwebsocket *wsi, const char *file,
const char *content_type, const char *other_headers,
if (wsi->u.http.fd == LWS_INVALID_FILE) {
lwsl_err("Unable to open '%s'\n", file);
- libwebsockets_return_http_status(context, wsi,
+ lws_return_http_status(context, wsi,
HTTP_STATUS_NOT_FOUND, NULL);
return -1;
}
if (lws_finalize_http_header(context, wsi, &p, end))
return -1;
- ret = libwebsocket_write(wsi, response,
+ ret = lws_write(wsi, response,
p - response, LWS_WRITE_HTTP_HEADERS);
if (ret != (p - response)) {
lwsl_err("_write returned %d from %d\n", ret, (p - response));
wsi->u.http.filepos = 0;
wsi->state = WSI_STATE_HTTP_ISSUING_FILE;
- return libwebsockets_serve_http_file_fragment(context, wsi);
+ return lws_serve_http_file_fragment(context, wsi);
}
break;
}
wsi->pps = LWS_PPS_NONE;
- libwebsocket_rx_flow_control(wsi, 1);
+ lws_rx_flow_control(wsi, 1);
return 0; /* leave POLLOUT active */
}
if (wsi->u.ws.payload_is_close)
write_type = LWS_WRITE_CLOSE;
- n = libwebsocket_write(wsi,
+ n = lws_write(wsi,
&wsi->u.ws.ping_payload_buf[
LWS_SEND_BUFFER_PRE_PADDING],
wsi->u.ws.ping_payload_len,
int
-libwebsocket_service_timeout_check(struct libwebsocket_context *context,
+lws_service_timeout_check(struct libwebsocket_context *context,
struct libwebsocket *wsi, unsigned int sec)
{
/*
}
/**
- * libwebsocket_service_fd() - Service polled socket with something waiting
+ * lws_service_fd() - Service polled socket with something waiting
* @context: Websocket context
* @pollfd: The pollfd entry describing the socket fd and which events
* happened.
*/
LWS_VISIBLE int
-libwebsocket_service_fd(struct libwebsocket_context *context,
+lws_service_fd(struct libwebsocket_context *context,
struct libwebsocket_pollfd *pollfd)
{
struct libwebsocket *wsi;
if (!wsi)
continue;
- if (libwebsocket_service_timeout_check(context, wsi, now))
+ if (lws_service_timeout_check(context, wsi, now))
/* he did time out... */
if (mfd == our_fd) {
/* it was the guy we came to service! */
*/
n = lws_poll_listen_fd(&context->fds[listen_socket_fds_index]);
if (n > 0) { /* there's a conn waiting for us */
- libwebsocket_service_fd(context,
+ lws_service_fd(context,
&context->
fds[listen_socket_fds_index]);
context->listen_service_extraseen++;
lws_handle_POLLOUT_event(context, wsi, pollfd)) {
if (wsi->state == WSI_STATE_RETURNED_CLOSE_ALREADY)
wsi->state = WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE;
- lwsl_info("libwebsocket_service_fd: closing\n");
+ lwsl_info("lws_service_fd: closing\n");
goto close_and_handled;
}
/* service incoming data */
if (eff_buf.token_len) {
- n = libwebsocket_read(context, wsi,
+ n = lws_read(context, wsi,
(unsigned char *)eff_buf.token,
eff_buf.token_len);
if (n < 0) {
#ifdef LWS_NO_SERVER
n =
#endif
- _libwebsocket_rx_flow_control(wsi); /* n ignored, needed for NO_SERVER case */
+ _lws_rx_flow_control(wsi); /* n ignored, needed for NO_SERVER case */
}
break;
}
/**
- * libwebsocket_service() - Service any pending websocket activity
+ * lws_service() - Service any pending websocket activity
* @context: Websocket context
* @timeout_ms: Timeout for poll; 0 means return immediately if nothing needed
* service otherwise block and service immediately, returning
*/
LWS_VISIBLE int
-libwebsocket_service(struct libwebsocket_context *context, int timeout_ms)
+lws_service(struct libwebsocket_context *context, int timeout_ms)
{
return lws_plat_service(context, timeout_ms);
}
*/
LWS_VISIBLE unsigned char *
-libwebsockets_SHA1(const unsigned char *d, size_t n, unsigned char *md)
+lws_SHA1(const unsigned char *d, size_t n, unsigned char *md)
{
struct sha1_ctxt ctx;
if (insert_wsi_socket_into_fds(context, wsi))
goto fail;
- libwebsocket_set_timeout(wsi, PENDING_TIMEOUT_SSL_ACCEPT,
+ lws_set_timeout(wsi, PENDING_TIMEOUT_SSL_ACCEPT,
AWAITING_TIMEOUT);
lwsl_info("inserted SSL accept into fds, trying SSL_accept\n");
accepted:
/* OK, we are accepted... give him some time to negotiate */
- libwebsocket_set_timeout(wsi,
+ lws_set_timeout(wsi,
PENDING_TIMEOUT_ESTABLISH_WITH_SERVER,
AWAITING_TIMEOUT);
fprintf(stderr, "callback_lws_mirror: LWS_CALLBACK_CLIENT_ESTABLISHED\n");
- libwebsockets_get_random(context, rands, sizeof(rands[0]));
+ lws_get_random(context, rands, sizeof(rands[0]));
mirror_lifetime = 10 + (rands[0] & 1023);
/* useful to test single connection stability */
if (longlived)
* LWS_CALLBACK_CLIENT_WRITEABLE will come next service
*/
- libwebsocket_callback_on_writable(context, wsi);
+ lws_callback_on_writable(context, wsi);
break;
case LWS_CALLBACK_CLOSED:
case LWS_CALLBACK_CLIENT_WRITEABLE:
for (n = 0; n < 1; n++) {
- libwebsockets_get_random(context, rands, sizeof(rands));
+ lws_get_random(context, rands, sizeof(rands));
l += sprintf((char *)&buf[LWS_SEND_BUFFER_PRE_PADDING + l],
"c #%06X %d %d %d;",
(int)rands[0] & 0xffffff,
(int)rands[3] % 24);
}
- n = libwebsocket_write(wsi,
+ n = lws_write(wsi,
&buf[LWS_SEND_BUFFER_PRE_PADDING], l, opts | LWS_WRITE_TEXT);
if (n < 0)
return -1;
} else
/* get notified as soon as we can write again */
- libwebsocket_callback_on_writable(context, wsi);
+ lws_callback_on_writable(context, wsi);
break;
default:
info.port = CONTEXT_PORT_NO_LISTEN;
info.protocols = protocols;
#ifndef LWS_NO_EXTENSIONS
- info.extensions = libwebsocket_get_internal_extensions();
+ info.extensions = lws_get_internal_extensions();
#endif
info.gid = -1;
info.uid = -1;
- context = libwebsocket_create_context(&info);
+ context = lws_create_context(&info);
if (context == NULL) {
fprintf(stderr, "Creating libwebsocket context failed\n");
return 1;
/* create a client websocket using dumb increment protocol */
- wsi_dumb = libwebsocket_client_connect(context, address, port, use_ssl,
+ wsi_dumb = lws_client_connect(context, address, port, use_ssl,
"/", argv[optind], argv[optind],
protocols[PROTOCOL_DUMB_INCREMENT].name, ietf_version);
n = 0;
while (n >= 0 && !was_closed && !force_exit) {
- n = libwebsocket_service(context, 10);
+ n = lws_service(context, 10);
if (n < 0)
continue;
/* create a client websocket using mirror protocol */
- wsi_mirror = libwebsocket_client_connect(context,
+ wsi_mirror = lws_client_connect(context,
address, port, use_ssl, "/",
argv[optind], argv[optind],
protocols[PROTOCOL_LWS_MIRROR].name, ietf_version);
bail:
fprintf(stderr, "Exiting\n");
- libwebsocket_context_destroy(context);
+ lws_context_destroy(context);
return ret;
case LWS_CALLBACK_SERVER_WRITEABLE:
do_tx:
- n = libwebsocket_write(wsi, &pss->buf[LWS_SEND_BUFFER_PRE_PADDING], pss->len, LWS_WRITE_TEXT);
+ n = lws_write(wsi, &pss->buf[LWS_SEND_BUFFER_PRE_PADDING], pss->len, LWS_WRITE_TEXT);
if (n < 0) {
lwsl_err("ERROR %d writing to socket, hanging up\n", n);
return 1;
}
memcpy(&pss->buf[LWS_SEND_BUFFER_PRE_PADDING], in, len);
pss->len = (unsigned int)len;
- libwebsocket_callback_on_writable(context, wsi);
+ lws_callback_on_writable(context, wsi);
break;
#endif
/* we will send our packet... */
pss->len = sprintf((char *)&pss->buf[LWS_SEND_BUFFER_PRE_PADDING], "hello from libwebsockets-test-echo client pid %d index %d\n", getpid(), pss->index++);
lwsl_notice("Client TX: %s", &pss->buf[LWS_SEND_BUFFER_PRE_PADDING]);
- n = libwebsocket_write(wsi, &pss->buf[LWS_SEND_BUFFER_PRE_PADDING], pss->len, LWS_WRITE_TEXT);
+ n = lws_write(wsi, &pss->buf[LWS_SEND_BUFFER_PRE_PADDING], pss->len, LWS_WRITE_TEXT);
if (n < 0) {
lwsl_err("ERROR %d writing to socket, hanging up\n", n);
return -1;
info.iface = _interface;
info.protocols = protocols;
#ifndef LWS_NO_EXTENSIONS
- info.extensions = libwebsocket_get_internal_extensions();
+ info.extensions = lws_get_internal_extensions();
#endif
if (use_ssl && !client) {
info.ssl_cert_filepath = ssl_cert;
info.uid = -1;
info.options = opts;
- context = libwebsocket_create_context(&info);
+ context = lws_create_context(&info);
if (context == NULL) {
lwsl_err("libwebsocket init failed\n");
return -1;
address[sizeof(address) - 1] = '\0';
sprintf(ads_port, "%s:%u", address, port & 65535);
- wsi = libwebsocket_client_connect(context, address,
+ wsi = lws_client_connect(context, address,
port, use_ssl, uri, ads_port,
ads_port, NULL, -1);
if (!wsi) {
gettimeofday(&tv, NULL);
if (((((unsigned long long)tv.tv_sec * 1000000) + tv.tv_usec) - oldus) > rate_us) {
- libwebsocket_callback_on_writable_all_protocol(&protocols[0]);
+ lws_callback_on_writable_all_protocol(&protocols[0]);
oldus = ((unsigned long long)tv.tv_sec * 1000000) + tv.tv_usec;
}
}
#endif
- n = libwebsocket_service(context, 10);
+ n = lws_service(context, 10);
}
#ifndef LWS_NO_CLIENT
bail:
#endif
- libwebsocket_context_destroy(context);
+ lws_context_destroy(context);
lwsl_notice("libwebsockets-test-echo exited cleanly\n");
#ifndef _WIN32
fprintf(stderr, "server sees client connect\n");
psf->state = FRAGSTATE_START_MESSAGE;
/* start the ball rolling */
- libwebsocket_callback_on_writable(context, wsi);
+ lws_callback_on_writable(context, wsi);
break;
case LWS_CALLBACK_CLIENT_ESTABLISHED:
psf->total_message += len;
psf->packets_left++;
- if (libwebsocket_is_final_fragment(wsi))
+ if (lws_is_final_fragment(wsi))
psf->state = FRAGSTATE_POST_PAYLOAD_SUM;
break;
switch (psf->state) {
case FRAGSTATE_START_MESSAGE:
- libwebsockets_get_random(context, &ran, sizeof(ran));
+ lws_get_random(context, &ran, sizeof(ran));
psf->packets_left = (ran % 1024) + 1;
fprintf(stderr, "Spamming %d random fragments\n",
psf->packets_left);
* code for rx spill because the rx buffer is full
*/
- libwebsockets_get_random(context, &ran, sizeof(ran));
+ lws_get_random(context, &ran, sizeof(ran));
chunk = (ran % 8000) + 1;
psf->total_message += chunk;
- libwebsockets_get_random(context, bp, chunk);
+ lws_get_random(context, bp, chunk);
for (n = 0; n < chunk; n++)
psf->sum += bp[n];
else
psf->state = FRAGSTATE_POST_PAYLOAD_SUM;
- n = libwebsocket_write(wsi, bp, chunk, write_mode);
+ n = lws_write(wsi, bp, chunk, write_mode);
if (n < 0)
return -1;
if (n < chunk) {
return -1;
}
- libwebsocket_callback_on_writable(context, wsi);
+ lws_callback_on_writable(context, wsi);
break;
case FRAGSTATE_POST_PAYLOAD_SUM:
bp[2] = psf->sum >> 8;
bp[3] = psf->sum;
- n = libwebsocket_write(wsi, (unsigned char *)bp,
+ n = lws_write(wsi, (unsigned char *)bp,
4, LWS_WRITE_BINARY);
if (n < 0)
return -1;
psf->state = FRAGSTATE_START_MESSAGE;
- libwebsocket_callback_on_writable(context, wsi);
+ lws_callback_on_writable(context, wsi);
break;
}
break;
info.iface = iface;
info.protocols = protocols;
#ifndef LWS_NO_EXTENSIONS
- info.extensions = libwebsocket_get_internal_extensions();
+ info.extensions = lws_get_internal_extensions();
#endif
if (use_ssl) {
info.ssl_cert_filepath = LOCAL_RESOURCE_PATH"/libwebsockets-test-server.pem";
info.uid = -1;
info.options = opts;
- context = libwebsocket_create_context(&info);
+ context = lws_create_context(&info);
if (context == NULL) {
fprintf(stderr, "libwebsocket init failed\n");
return -1;
if (client) {
address = argv[optind];
fprintf(stderr, "Connecting to %s:%u\n", address, port);
- wsi = libwebsocket_client_connect(context, address,
+ wsi = lws_client_connect(context, address,
port, use_ssl, "/", address,
"origin", protocols[PROTOCOL_FRAGGLE].name,
-1);
n = 0;
while (!n && !terminate)
- n = libwebsocket_service(context, 50);
+ n = lws_service(context, 50);
fprintf(stderr, "Terminating...\n");
bail:
- libwebsocket_context_destroy(context);
+ lws_context_destroy(context);
return 0;
}
* LWS_CALLBACK_CLIENT_WRITEABLE will come next service
*/
- libwebsocket_callback_on_writable(this, wsi);
+ lws_callback_on_writable(this, wsi);
break;
case LWS_CALLBACK_CLIENT_RECEIVE:
global_tx_count++;
if (use_mirror)
- n = libwebsocket_write(wsi,
+ n = lws_write(wsi,
&pingbuf[LWS_SEND_BUFFER_PRE_PADDING],
size, write_options | LWS_WRITE_BINARY);
else
- n = libwebsocket_write(wsi,
+ n = lws_write(wsi,
&pingbuf[LWS_SEND_BUFFER_PRE_PADDING],
size, write_options | LWS_WRITE_PING);
info.port = CONTEXT_PORT_NO_LISTEN;
info.protocols = protocols;
#ifndef LWS_NO_EXTENSIONS
- info.extensions = libwebsocket_get_internal_extensions();
+ info.extensions = lws_get_internal_extensions();
#endif
info.gid = -1;
info.uid = -1;
- context = libwebsocket_create_context(&info);
+ context = lws_create_context(&info);
if (context == NULL) {
fprintf(stderr, "Creating libwebsocket context failed\n");
return 1;
/* create client websockets using dumb increment protocol */
for (n = 0; n < clients; n++) {
- ping_wsi[n] = libwebsocket_client_connect(context, address,
+ ping_wsi[n] = lws_client_connect(context, address,
port, use_ssl, "/", address,
"origin", protocols[PROTOCOL_LWS_MIRROR].name,
ietf_version);
}
}
- libwebsockets_get_peer_addresses(context, ping_wsi[0],
- libwebsocket_get_socket_fd(ping_wsi[0]),
+ lws_get_peer_addresses(context, ping_wsi[0],
+ lws_get_socket_fd(ping_wsi[0]),
peer_name, sizeof peer_name, ip, sizeof ip);
fprintf(stderr, "Websocket PING %s (%s) %d bytes of data.\n",
if (!interrupted_time) {
if ((l - oldus) > interval_us) {
for (n = 0; n < clients; n++)
- libwebsocket_callback_on_writable(
+ lws_callback_on_writable(
context, ping_wsi[n]);
oldus = l;
}
}
if (!interval_us)
- n = libwebsocket_service(context, 0);
+ n = lws_service(context, 0);
else
- n = libwebsocket_service(context, 1);
+ n = lws_service(context, 1);
}
/* stats */
((double)global_rx_count * (double)size) /
((double)(l - started) / 1000000.0) / 1024.0);
- libwebsocket_context_destroy(context);
+ lws_context_destroy(context);
return 0;
case LWS_CALLBACK_SERVER_WRITEABLE:
n = sprintf((char *)p, "%d", pss->number++);
- m = libwebsocket_write(wsi, p, n, LWS_WRITE_TEXT);
+ m = lws_write(wsi, p, n, LWS_WRITE_TEXT);
if (m < n) {
lwsl_err("ERROR %d writing to di socket\n", n);
return -1;
dump_handshake_info(wsi);
if (len < 1) {
- libwebsockets_return_http_status(context, wsi,
+ lws_return_http_status(context, wsi,
HTTP_STATUS_BAD_REQUEST, NULL);
goto try_to_reuse;
}
/* this example server has no concept of directories */
if (strchr((const char *)in + 1, '/')) {
- libwebsockets_return_http_status(context, wsi,
+ lws_return_http_status(context, wsi,
HTTP_STATUS_FORBIDDEN, NULL);
goto try_to_reuse;
}
* this is mandated by changes in HTTP2
*/
- n = libwebsocket_write(wsi,
+ n = lws_write(wsi,
buffer + LWS_SEND_BUFFER_PRE_PADDING,
p - (buffer + LWS_SEND_BUFFER_PRE_PADDING),
LWS_WRITE_HTTP_HEADERS);
/*
* book us a LWS_CALLBACK_HTTP_WRITEABLE callback
*/
- libwebsocket_callback_on_writable(context, wsi);
+ lws_callback_on_writable(context, wsi);
break;
}
mimetype = get_mimetype(buf);
if (!mimetype) {
lwsl_err("Unknown mimetype for %s\n", buf);
- libwebsockets_return_http_status(context, wsi,
+ lws_return_http_status(context, wsi,
HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE, NULL);
return -1;
}
other_headers = leaf_path;
}
- n = libwebsockets_serve_http_file(context, wsi, buf,
+ n = lws_serve_http_file(context, wsi, buf,
mimetype, other_headers, n);
if (n < 0 || ((n > 0) && lws_http_transaction_completed(wsi)))
return -1; /* error or can't reuse connection: close the socket */
case LWS_CALLBACK_HTTP_BODY_COMPLETION:
lwsl_notice("LWS_CALLBACK_HTTP_BODY_COMPLETION\n");
/* the whole of the sent body arrived, close or reuse the connection */
- libwebsockets_return_http_status(context, wsi,
+ lws_return_http_status(context, wsi,
HTTP_STATUS_OK, NULL);
goto try_to_reuse;
* is handled by the library itself if you sent a
* content-length header
*/
- m = libwebsocket_write(wsi,
+ m = lws_write(wsi,
buffer + LWS_SEND_BUFFER_PRE_PADDING,
n, LWS_WRITE_HTTP);
if (m < 0)
goto bail;
if (m) /* while still active, extend timeout */
- libwebsocket_set_timeout(wsi,
+ lws_set_timeout(wsi,
PENDING_TIMEOUT_HTTP_CONTENT, 5);
/* if we have indigestion, let him clear it before eating more */
} while (!lws_send_pipe_choked(wsi));
later:
- libwebsocket_callback_on_writable(context, wsi);
+ lws_callback_on_writable(context, wsi);
break;
flush_bail:
/* true if still partial pending */
if (lws_partial_buffered(wsi)) {
- libwebsocket_callback_on_writable(context, wsi);
+ lws_callback_on_writable(context, wsi);
break;
}
close(pss->fd);
case LWS_CALLBACK_GET_THREAD_ID:
/*
- * if you will call "libwebsocket_callback_on_writable"
+ * if you will call "lws_callback_on_writable"
* from a different thread, return the caller thread ID
* here so lws can use this information to work out if it
* should signal the poll() loop to exit and restart early
break;
while (pss->ringbuffer_tail != ringbuffer_head) {
- n = libwebsocket_write(wsi, (unsigned char *)
+ n = lws_write(wsi, (unsigned char *)
ringbuffer[pss->ringbuffer_tail].payload +
LWS_SEND_BUFFER_PRE_PADDING,
ringbuffer[pss->ringbuffer_tail].len,
if (((ringbuffer_head - pss->ringbuffer_tail) &
(MAX_MESSAGE_QUEUE - 1)) == (MAX_MESSAGE_QUEUE - 15))
- libwebsocket_rx_flow_allow_all_protocol(
- libwebsockets_get_protocol(wsi));
+ lws_rx_flow_allow_all_protocol(
+ lws_get_protocol(wsi));
if (lws_partial_buffered(wsi) || lws_send_pipe_choked(wsi)) {
- libwebsocket_callback_on_writable(context, wsi);
+ lws_callback_on_writable(context, wsi);
break;
}
/*
choke:
lwsl_debug("LWS_CALLBACK_RECEIVE: throttling %p\n", wsi);
- libwebsocket_rx_flow_control(wsi, 0);
+ lws_rx_flow_control(wsi, 0);
done:
- libwebsocket_callback_on_writable_all_protocol(
- libwebsockets_get_protocol(wsi));
+ lws_callback_on_writable_all_protocol(
+ lws_get_protocol(wsi));
break;
/*
* This mutex lock protects code that changes or relies on wsi list outside of
* the service thread. The service thread will acquire it when changing the
* wsi list and other threads should acquire it while dereferencing wsis or
- * calling apis like libwebsocket_callback_on_writable_all_protocol() which
+ * calling apis like lws_callback_on_writable_all_protocol() which
* use the wsi list and wsis from a different thread context.
*/
pthread_mutex_t lock_established_conns;
* them is protected by the same lock
*/
pthread_mutex_lock(&lock_established_conns);
- libwebsocket_callback_on_writable_all_protocol(
+ lws_callback_on_writable_all_protocol(
&protocols[PROTOCOL_DUMB_INCREMENT]);
pthread_mutex_unlock(&lock_established_conns);
usleep(100000);
void sighandler(int sig)
{
force_exit = 1;
- libwebsocket_cancel_service(context);
+ lws_cancel_service(context);
}
static struct option options[] = {
info.iface = iface;
info.protocols = protocols;
#ifndef LWS_NO_EXTENSIONS
- info.extensions = libwebsocket_get_internal_extensions();
+ info.extensions = lws_get_internal_extensions();
#endif
info.ssl_cert_filepath = NULL;
info.uid = -1;
info.options = opts;
- context = libwebsocket_create_context(&info);
+ context = lws_create_context(&info);
if (context == NULL) {
lwsl_err("libwebsocket init failed\n");
return -1;
n = 0;
while (n >= 0 && !force_exit) {
- n = libwebsocket_service(context, 50);
+ n = lws_service(context, 50);
}
/* wait for pthread_dumb to exit */
pthread_join(pthread_dumb, &retval);
done:
- libwebsocket_context_destroy(context);
+ lws_context_destroy(context);
pthread_mutex_destroy(&lock_established_conns);
void sighandler(int sig)
{
force_exit = 1;
- libwebsocket_cancel_service(context);
+ lws_cancel_service(context);
}
static struct option options[] = {
info.iface = iface;
info.protocols = protocols;
#ifndef LWS_NO_EXTENSIONS
- info.extensions = libwebsocket_get_internal_extensions();
+ info.extensions = lws_get_internal_extensions();
#endif
info.ssl_cert_filepath = NULL;
info.uid = -1;
info.options = opts;
- context = libwebsocket_create_context(&info);
+ context = lws_create_context(&info);
if (context == NULL) {
lwsl_err("libwebsocket init failed\n");
return -1;
ms = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
if ((ms - oldms) > 50) {
- libwebsocket_callback_on_writable_all_protocol(
+ lws_callback_on_writable_all_protocol(
&protocols[PROTOCOL_DUMB_INCREMENT]);
oldms = ms;
}
* match anything under libwebsockets
* control
*/
- if (libwebsocket_service_fd(context,
+ if (lws_service_fd(context,
&pollfds[n]) < 0)
goto done;
#else
* the number of ms in the second argument.
*/
- n = libwebsocket_service(context, 50);
+ n = lws_service(context, 50);
#endif
}
done:
#endif
- libwebsocket_context_destroy(context);
+ lws_context_destroy(context);
lwsl_notice("libwebsockets-test-server exited cleanly\n");