from the code -- it's not just defeated from logging
but removed from compilation
+--without-extensions Remove all code and data around protocol extensions.
+ This reduces the code footprint considerably but
+ you will lose extension features like compression.
+ However that may be irrelevant for embedded use and
+ the code / data size / speed improvements may be
+ critical.
+
Externally configurable important constants
-------------------------------------------
fi
AM_CONDITIONAL(NO_SERVER, test x$no_server = xyes)
+#
+#
+#
+AC_ARG_WITH(extensions,
+ [ --without-extensions dont build any stuff related to extensions ],
+ [ no_extensions=yes
+ ])
+if test "x$no_extensions" = "xyes" ; then
+CFLAGS="$CFLAGS -DLWS_NO_EXTENSIONS"
+fi
+AM_CONDITIONAL(NO_EXTENSIONS, test x$no_extensions = xyes)
#
#
libwebsockets.h \
base64-decode.c \
output.c \
- extension.c \
- extension-deflate-stream.c extension-deflate-stream.h \
- extension-deflate-frame.c extension-deflate-frame.h\
private-libwebsockets.h
+if NO_EXTENSIONS
+else
+dist_libwebsockets_la_SOURCES+= extension.c \
+ extension-deflate-stream.c extension-deflate-stream.h \
+ extension-deflate-frame.c extension-deflate-frame.h
+endif
+
if NO_DAEMONIZE
else
dist_libwebsockets_la_SOURCES+= daemonize.c
#endif
lwsl_client("__libwebsocket_client_connect_2\n");
-
+#ifndef LWS_NO_EXTENSIONS
wsi->candidate_children_list = NULL;
+#endif
/*
* proxy?
{
struct libwebsocket *wsi;
int n;
+#ifndef LWS_NO_EXTENSIONS
int m;
struct libwebsocket_extension *ext;
int handled;
+#endif
+
#ifndef LWS_OPENSSL_SUPPORT
if (ssl_connection) {
lwsl_err("libwebsockets not configured for ssl\n");
wsi->pings_vs_pongs = 0;
wsi->protocol = NULL;
wsi->pending_timeout = NO_PENDING_TIMEOUT;
+#ifndef LWS_NO_EXTENSIONS
wsi->count_active_extensions = 0;
+#endif
#ifdef LWS_OPENSSL_SUPPORT
wsi->use_ssl = ssl_connection;
#endif
wsi->utf8_token[n].token_len = 0;
}
+#ifndef LWS_NO_EXTENSIONS
/*
* Check with each extension if it is able to route and proxy this
* connection for us. For example, an extension like x-google-mux
wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT;
return wsi;
}
-
+#endif
lwsl_client("libwebsocket_client_connect: direct conn\n");
return __libwebsocket_client_connect_2(context, wsi);
int callback_action = LWS_CALLBACK_CLIENT_RECEIVE;
int handled;
struct lws_tokens eff_buf;
+#ifndef LWS_NO_EXTENSIONS
int m;
+#endif
// lwsl_parser(" CRX: %02X %d\n", c, wsi->lws_rx_parse_state);
default:
lwsl_parser("Reserved opcode 0x%2X\n", wsi->opcode);
+#ifndef LWS_NO_EXTENSIONS
/*
* It's something special we can't understand here.
* Pass the payload up to the extension's parsing
}
if (!handled) {
+#else
+ {
+#endif
lwsl_ext("Unhandled extended opcode "
"0x%x - ignoring frame\n", wsi->opcode);
wsi->rx_user_buffer_head = 0;
eff_buf.token = &wsi->rx_user_buffer[
LWS_SEND_BUFFER_PRE_PADDING];
eff_buf.token_len = wsi->rx_user_buffer_head;
-
+#ifndef LWS_NO_EXTENSIONS
for (n = 0; n < wsi->count_active_extensions; n++) {
m = wsi->active_extensions[n]->callback(
wsi->protocol->owning_server,
return -1;
}
}
-
+#endif
if (eff_buf.token_len > 0) {
eff_buf.token[eff_buf.token_len] = '\0';
char pkt[1024];
char *p = &pkt[0];
const char *pc;
- const char *c;
- int more = 1;
int okay = 0;
+#ifndef LWS_NO_EXTENSIONS
char ext_name[128];
struct libwebsocket_extension *ext;
void *v;
+ int more = 1;
+ const char *c;
+#endif
int len = 0;
int n;
static const char magic_websocket_04_masking_guid[] =
check_extensions:
-
+#ifndef LWS_NO_EXTENSIONS
/* instantiate the accepted extensions */
if (!wsi->utf8_token[WSI_TOKEN_EXTENSIONS].token_len) {
n = 0;
}
-
check_accept:
+#endif
if (wsi->ietf_spec_revision == 0) {
wsi->protocol->callback(context, wsi,
LWS_CALLBACK_CLIENT_ESTABLISHED,
wsi->user_space, NULL, 0);
-
+#ifndef LWS_NO_EXTENSIONS
/*
* inform all extensions, not just active ones since they
* already know
LWS_EXT_CALLBACK_ANY_WSI_ESTABLISHED, v, NULL, 0);
ext++;
}
+#endif
return 0;
char hash[20];
char *p = pkt;
int n;
+#ifndef LWS_NO_EXTENSIONS
struct libwebsocket_extension *ext;
struct libwebsocket_extension *ext1;
int ext_count = 0;
+#endif
unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 1 +
MAX_BROADCAST_PAYLOAD + LWS_SEND_BUFFER_POST_PADDING];
static const char magic_websocket_guid[] =
/* tell the server what extensions we could support */
p += sprintf(p, "Sec-WebSocket-Extensions: ");
-
+#ifndef LWS_NO_EXTENSIONS
ext = context->extensions;
while (ext && ext->callback) {
ext++;
}
-
+#endif
p += sprintf(p, "\x0d\x0a");
if (wsi->ietf_spec_revision)
if (wsi->protocol->callback(context, wsi,
LWS_CALLBACK_HTTP, wsi->user_space,
wsi->utf8_token[WSI_TOKEN_GET_URI].token,
- wsi->utf8_token[WSI_TOKEN_GET_URI].token_len))
+ wsi->utf8_token[WSI_TOKEN_GET_URI].token_len)) {
+ lwsl_info("LWS_CALLBACK_HTTP wanted to close\n");
goto bail;
+ }
return 0;
}
if (!wsi->protocol)
lwsl_err("NULL protocol at libwebsocket_read\n");
+
/*
* It's websocket
*
switch (wsi->ietf_spec_revision) {
case 0: /* applies to 76 and 00 */
wsi->xor_mask = xor_no_mask;
- if (handshake_00(context, wsi))
+ if (handshake_00(context, wsi)) {
+ lwsl_info("handshake_00 has failed the connection\n");
goto bail;
+ }
break;
case 4: /* 04 */
wsi->xor_mask = xor_mask_04;
lwsl_parser("libwebsocket_parse calling handshake_04\n");
- if (handshake_0405(context, wsi))
+ if (handshake_0405(context, wsi)) {
+ lwsl_info("handshake_0405 has failed the connection\n");
goto bail;
+ }
break;
case 5:
case 6:
case 13:
wsi->xor_mask = xor_mask_05;
lwsl_parser("libwebsocket_parse calling handshake_04\n");
- if (handshake_0405(context, wsi))
+ if (handshake_0405(context, wsi)) {
+ lwsl_info("handshake_0405 xor 05 has failed the connection\n");
goto bail;
+ }
break;
default:
switch (wsi->mode) {
case LWS_CONNMODE_WS_CLIENT:
for (n = 0; n < len; n++)
- if (libwebsocket_client_rx_sm(wsi, *buf++) < 0)
+ if (libwebsocket_client_rx_sm(wsi, *buf++) < 0) {
+ lwsl_info("client rx has bailed\n");
goto bail;
+ }
return 0;
default:
#ifndef LWS_NO_SERVER
/* LWS_CONNMODE_WS_SERVING */
- if (libwebsocket_interpret_incoming_packet(wsi, buf, len) < 0)
+ if (libwebsocket_interpret_incoming_packet(wsi, buf, len) < 0) {
+ lwsl_info("interpret_incoming_packet has bailed\n");
goto bail;
+ }
#endif
break;
default:
return 0;
bail:
+ lwsl_info("closing connection at libwebsocket_read bail:\n");
libwebsocket_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
#endif
#endif
+
static int log_level = LLL_ERR | LLL_WARN | LLL_NOTICE;
static void lwsl_emit_stderr(int level, const char *line);
static void (*lwsl_emit)(int level, const char *line) = lwsl_emit_stderr;
int old_state;
unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 2 +
LWS_SEND_BUFFER_POST_PADDING];
+#ifndef LWS_NO_EXTENSIONS
int ret;
int m;
struct lws_tokens eff_buf;
struct libwebsocket_extension *ext;
+#endif
if (!wsi)
return;
wsi->close_reason = reason;
+#ifndef LWS_NO_EXTENSIONS
/*
* are his extensions okay with him closing? Eg he might be a mux
* parent and just his ch1 aspect is closing?
*/
-
for (n = 0; n < wsi->count_active_extensions; n++) {
if (!wsi->active_extensions[n]->callback)
continue;
}
}
-
-
/*
* flush any tx pending from extensions, since we may send close packet
* if there are problems with send, just nuke the connection
goto just_kill_connection;
}
}
+#endif
/*
* signal we are closing, libsocket_write will
/* else, the send failed and we should just hang up */
}
+#ifndef LWS_NO_EXTENSIONS
just_kill_connection:
+#endif
lwsl_debug("libwebsocket_close_and_free_session: just_kill_connection\n");
} else
lwsl_debug("not calling back closed, old_state=%d\n", old_state);
+#ifndef LWS_NO_EXTENSIONS
/* deallocate any active extension contexts */
for (n = 0; n < wsi->count_active_extensions; n++) {
NULL, NULL, 0);
ext++;
}
+#endif
/* free up his parsing allocations */
lws_handle_POLLOUT_event(struct libwebsocket_context *context,
struct libwebsocket *wsi, struct pollfd *pollfd)
{
- struct lws_tokens eff_buf;
int n;
+#ifndef LWS_NO_EXTENSIONS
+ struct lws_tokens eff_buf;
int ret;
int m;
int handled = 0;
wsi->extension_data_pending = 0;
user_service:
+#endif
/* one shot */
if (pollfd) {
LWS_CALLBACK_CLEAR_MODE_POLL_FD,
(void *)(long)wsi->sock, NULL, POLLOUT);
}
-
+#ifndef LWS_NO_EXTENSIONS
notify_action:
+#endif
if (wsi->mode == LWS_CONNMODE_WS_CLIENT)
n = LWS_CALLBACK_CLIENT_WRITEABLE;
libwebsocket_service_timeout_check(struct libwebsocket_context *context,
struct libwebsocket *wsi, unsigned int sec)
{
+#ifndef LWS_NO_EXTENSIONS
int n;
/*
wsi, LWS_EXT_CALLBACK_1HZ,
wsi->active_extensions_user[n], NULL, sec);
+#endif
if (!wsi->pending_timeout)
return;
int n;
int m;
struct timeval tv;
+#ifndef LWS_NO_EXTENSIONS
int more = 1;
+#endif
struct lws_tokens eff_buf;
#ifndef LWS_NO_CLIENT
extern int lws_client_socket_service(struct libwebsocket_context *context, struct libwebsocket *wsi, struct pollfd *pollfd);
*/
eff_buf.token = (char *)buf;
-
+#ifndef LWS_NO_EXTENSIONS
more = 1;
while (more) {
if (m)
more = 1;
}
-
+#endif
/* service incoming data */
if (eff_buf.token_len) {
/* we closed wsi */
return 0;
}
-
+#ifndef LWS_NO_EXTENSIONS
eff_buf.token = NULL;
eff_buf.token_len = 0;
}
+#endif
#ifdef LWS_OPENSSL_SUPPORT
if (wsi->ssl && SSL_pending(wsi->ssl))
void
libwebsocket_context_destroy(struct libwebsocket_context *context)
{
+#ifndef LWS_NO_EXTENSIONS
int n;
int m;
struct libwebsocket_extension *ext;
ext->callback(context, ext, NULL, (enum libwebsocket_extension_callback_reasons)m, NULL, NULL, 0);
ext++;
}
+#endif
#ifdef WIN32
#else
return 0;
}
+#ifndef LWS_NO_EXTENSIONS
int
lws_any_extension_handled(struct libwebsocket_context *context,
struct libwebsocket *wsi,
return NULL;
}
+#endif
/**
* libwebsocket_callback_on_writable() - Request a callback when this socket
libwebsocket_callback_on_writable(struct libwebsocket_context *context,
struct libwebsocket *wsi)
{
+#ifndef LWS_NO_EXTENSIONS
int n;
int handled = 0;
if (handled)
return 1;
-
+#endif
if (wsi->position_in_fds_table < 0) {
lwsl_err("libwebsocket_callback_on_writable: "
"failed to find socket %d\n", wsi->sock);
* entry that has a NULL callback pointer.
* It's not const because we write the owning_server member
* @extensions: NULL or array of libwebsocket_extension structs listing the
- * extensions this context supports
+ * extensions this context supports. If you configured with
+ * --without-extensions, you should give NULL here.
* @ssl_cert_filepath: If libwebsockets was compiled to use ssl, and you want
* to listen using SSL, set to the filepath to fetch the
* server cert from, otherwise NULL for unencrypted
void *user)
{
int n;
- int m;
int fd;
struct sockaddr_in serv_addr, cli_addr;
int opt = 1;
unsigned int slen;
char *p;
struct libwebsocket *wsi;
+#ifndef LWS_NO_EXTENSIONS
+ int m;
+#endif
#ifdef LWS_OPENSSL_SUPPORT
SSL_METHOD *method;
lwsl_info(" MAX_USER_RX_BUFFER: %u\n", MAX_USER_RX_BUFFER);
lwsl_info(" MAX_BROADCAST_PAYLOAD: %u\n", MAX_BROADCAST_PAYLOAD);
lwsl_info(" LWS_MAX_PROTOCOLS: %u\n", LWS_MAX_PROTOCOLS);
+#ifndef LWS_NO_EXTENSIONS
lwsl_info(" LWS_MAX_EXTENSIONS_ACTIVE: %u\n", LWS_MAX_EXTENSIONS_ACTIVE);
+#else
+ lwsl_notice(" Configured without extension support\n");
+#endif
lwsl_info(" SPEC_LATEST_SUPPORTED: %u\n", SPEC_LATEST_SUPPORTED);
lwsl_info(" AWAITING_TIMEOUT: %u\n", AWAITING_TIMEOUT);
lwsl_info(" CIPHERS_LIST_STRING: '%s'\n", CIPHERS_LIST_STRING);
return NULL;
}
context->fds_count = 0;
+#ifndef LWS_NO_EXTENSIONS
context->extensions = extensions;
+#endif
context->last_timeout_check_s = 0;
context->user_space = user;
}
memset(wsi, 0, sizeof (struct libwebsocket));
wsi->sock = sockfd;
+#ifndef LWS_NO_EXTENSIONS
wsi->count_active_extensions = 0;
+#endif
wsi->mode = LWS_CONNMODE_SERVER_LISTENER;
insert_wsi_socket_into_fds(context, wsi);
memset(wsi, 0, sizeof (struct libwebsocket));
wsi->sock = fd;
wsi->mode = LWS_CONNMODE_BROADCAST_PROXY_LISTENER;
+#ifndef LWS_NO_EXTENSIONS
wsi->count_active_extensions = 0;
+#endif
/* note which protocol we are proxying */
wsi->protocol_index_for_broadcast_proxy =
context->count_protocols;
insert_wsi_socket_into_fds(context, wsi);
}
-
+#ifndef LWS_NO_EXTENSIONS
/*
* give all extensions a chance to create any per-context
* allocations they need
extensions++;
}
}
-
+#endif
return context;
}
LWS_CALLBACK_CLEAR_MODE_POLL_FD,
};
+#ifndef LWS_NO_EXTENSIONS
enum libwebsocket_extension_callback_reasons {
LWS_EXT_CALLBACK_SERVER_CONTEXT_CONSTRUCT,
LWS_EXT_CALLBACK_CLIENT_CONTEXT_CONSTRUCT,
LWS_EXT_CALLBACK_PAYLOAD_TX,
LWS_EXT_CALLBACK_PAYLOAD_RX,
};
+#endif
enum libwebsocket_write_protocol {
LWS_WRITE_TEXT,
struct libwebsocket;
struct libwebsocket_context;
+/* needed even with extensions disabled for create context */
struct libwebsocket_extension;
/**
enum libwebsocket_callback_reasons reason, void *user,
void *in, size_t len);
-
+#ifndef LWS_NO_EXTENSIONS
/**
* extension_callback_function() - Hooks to allow extensions to operate
* @context: Websockets context
struct libwebsocket *wsi,
enum libwebsocket_extension_callback_reasons reason, void *user,
void *in, size_t len);
+#endif
/**
* struct libwebsocket_protocols - List of protocols and handlers server
int protocol_index;
};
+#ifndef LWS_NO_EXTENSIONS
/**
* struct libwebsocket_extension - An extension we know how to cope with
*
size_t per_session_data_size;
void * per_context_private_data;
};
+#endif
LWS_EXTERN
void lws_set_log_level(int level, void (*log_emit_function)(int level, const char *line));
LWS_EXTERN int
lws_b64_decode_string(const char *in, char *out, int out_size);
+#ifndef LWS_NO_EXTENSIONS
LWS_EXTERN struct libwebsocket_extension libwebsocket_internal_extensions[];
+#endif
#ifdef __cplusplus
}
p += sprintf(p, " ");
for (m = 0; m < 16 && (start + m) < len; m++) {
- if (buf[start + m] >= ' ' && buf[start + m] <= 127)
+ if (buf[start + m] >= ' ' && buf[start + m] < 127)
*p++ = buf[start + m];
else
*p++ = '.';
*p++ = '\n';
*p = '\0';
- lwsl_debug(line);
+ lwsl_debug("%s", line);
}
lwsl_debug("\n");
}
int lws_issue_raw(struct libwebsocket *wsi, unsigned char *buf, size_t len)
{
int n;
+#ifndef LWS_NO_EXTENSIONS
int m;
/*
return 0;
}
}
-
+#endif
if (!wsi->sock)
lwsl_warn("** error 0 sock but expected to send\n");
return 0;
}
+#ifdef LWS_NO_EXTENSIONS
+int
+lws_issue_raw_ext_access(struct libwebsocket *wsi,
+ unsigned char *buf, size_t len)
+{
+ return lws_issue_raw(wsi, buf, len);
+}
+#else
int
lws_issue_raw_ext_access(struct libwebsocket *wsi,
unsigned char *buf, size_t len)
return 0;
}
+#endif
/**
* libwebsocket_write() - Apply protocol then write data to client
wsi->xor_mask != xor_no_mask;
unsigned char *dropmask = NULL;
unsigned char is_masked_bit = 0;
+#ifndef LWS_NO_EXTENSIONS
struct lws_tokens eff_buf;
int m;
+#endif
if (lws_confirm_legit_wsi(wsi)) {
lwsl_err("libwebsocket_write on illegitimate wsi\n");
if (wsi->state != WSI_STATE_ESTABLISHED)
return -1;
+#ifndef LWS_NO_EXTENSIONS
/* give a change to the extensions to modify payload */
eff_buf.token = (char *)buf;
eff_buf.token_len = len;
buf = (unsigned char *)eff_buf.token;
len = eff_buf.token_len;
+#endif
switch (wsi->ietf_spec_revision) {
/* chrome likes this as of 30 Oct 2010 */
close(fd);
if (wsi->protocol->callback(context, wsi, LWS_CALLBACK_HTTP_FILE_COMPLETION, wsi->user_space,
- wsi->filepath, wsi->filepos))
+ wsi->filepath, wsi->filepos)) {
+ lwsl_info("closing connecton after file_completion returned nonzero\n");
libwebsocket_close_and_free_session(context, wsi, LWS_CLOSE_STATUS_NOSTATUS);
+ }
return 0;
}
int n;
unsigned char buf[20 + 4];
struct lws_tokens eff_buf;
+#ifndef LWS_NO_EXTENSIONS
int handled;
int m;
+#endif
#if 0
lwsl_debug("RX: %02X ", c);
case LWS_RXPS_PAYLOAD_UNTIL_LENGTH_EXHAUSTED:
+
if (wsi->ietf_spec_revision < 4 ||
(wsi->all_zero_nonce && wsi->ietf_spec_revision >= 5))
wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING +
break;
default:
-
+#ifndef LWS_NO_EXTENSIONS
lwsl_parser("passing opcode %x up to exts\n", wsi->opcode);
/*
}
if (!handled)
+#endif
lwsl_ext("Unhandled extended opcode "
"0x%x - ignoring frame\n", wsi->opcode);
eff_buf.token = &wsi->rx_user_buffer[
LWS_SEND_BUFFER_PRE_PADDING];
eff_buf.token_len = wsi->rx_user_buffer_head;
-
+#ifndef LWS_NO_EXTENSIONS
for (n = 0; n < wsi->count_active_extensions; n++) {
m = wsi->active_extensions[n]->callback(
wsi->protocol->owning_server,
return -1;
}
}
-
+#endif
if (eff_buf.token_len > 0) {
eff_buf.token[eff_buf.token_len] = '\0';
int clear_rxflow = !!wsi->rxflow_buffer;
struct libwebsocket_context *context = wsi->protocol->owning_server;
-#ifdef DEBUG
+#if 0
lwsl_parser("received %d byte packet\n", (int)len);
lwsl_hexdump(buf, len);
#endif
#endif
struct libwebsocket_protocols *protocols;
int count_protocols;
+#ifndef LWS_NO_EXTENSIONS
struct libwebsocket_extension *extensions;
-
+#endif
void *user_space;
};
struct libwebsocket {
const struct libwebsocket_protocols *protocol;
+#ifndef LWS_NO_EXTENSIONS
struct libwebsocket_extension *
active_extensions[LWS_MAX_EXTENSIONS_ACTIVE];
void *active_extensions_user[LWS_MAX_EXTENSIONS_ACTIVE];
int count_active_extensions;
-
+ char extension_data_pending;
+ struct libwebsocket *extension_handles;
+ struct libwebsocket *candidate_children_list;
+#endif
enum lws_connection_states state;
char name_buffer[LWS_MAX_HEADER_NAME_LENGTH];
int rxflow_change_to;
enum lws_rx_parse_state lws_rx_parse_state;
- char extension_data_pending;
- struct libwebsocket *candidate_children_list;
- struct libwebsocket *extension_handles;
/* 04 protocol specific */
extern int
lws_handle_POLLOUT_event(struct libwebsocket_context *context,
struct libwebsocket *wsi, struct pollfd *pollfd);
-
+#ifndef LWS_NO_EXTENSIONS
extern int
lws_any_extension_handled(struct libwebsocket_context *context,
struct libwebsocket *wsi,
extern void *
lws_get_extension_user_matching_ext(struct libwebsocket *wsi,
struct libwebsocket_extension *ext);
+#endif
extern int
lws_client_interpret_server_handshake(struct libwebsocket_context *context,
char *m = mask_summing_buf;
int nonce_len = 0;
int accept_len;
+#ifndef LWS_NO_EXTENSIONS
char *c;
char ext_name[128];
struct libwebsocket_extension *ext;
int ext_count = 0;
int more = 1;
+#endif
if (!wsi->utf8_token[WSI_TOKEN_HOST].token_len ||
!wsi->utf8_token[WSI_TOKEN_KEY].token_len) {
LWS_CPYAPP_TOKEN(p, WSI_TOKEN_PROTOCOL);
}
+#ifndef LWS_NO_EXTENSIONS
/*
* Figure out which extensions the client has that we want to
* enable on this connection, and give him back the list
n = 0;
}
}
-
+#endif
/* end of response packet */
LWS_CPYAPP(p, "\x0d\x0a\x0d\x0a");
wsi->masking_key_04);
}
+#ifndef LWS_NO_EXTENSIONS
if (!lws_any_extension_handled(context, wsi,
LWS_EXT_CALLBACK_HANDSHAKE_REPLY_TX,
- response, p - response)) {
-
+ response, p - response))
+#endif
+ {
/* okay send the handshake response accepting the connection */
lwsl_parser("issuing response packet %d len\n", (int)(p - response));
}
memset(new_wsi, 0, sizeof(struct libwebsocket));
+#ifndef LWS_NO_EXTENSIONS
new_wsi->count_active_extensions = 0;
+#endif
new_wsi->pending_timeout = NO_PENDING_TIMEOUT;
/* intialize the instance struct */
new_wsi->sock = accept_fd;
new_wsi->mode = LWS_CONNMODE_BROADCAST_PROXY;
new_wsi->state = WSI_STATE_ESTABLISHED;
+#ifndef LWS_NO_EXTENSIONS
new_wsi->count_active_extensions = 0;
+#endif
/* note which protocol we are proxying */
new_wsi->protocol_index_for_broadcast_proxy =
wsi->protocol_index_for_broadcast_proxy;
It's not const because we write the owning_server member
<dt><b>extensions</b>
<dd>NULL or array of libwebsocket_extension structs listing the
-extensions this context supports
+extensions this context supports. If you configured with
+--without-extensions, you should give NULL here.
<dt><b>ssl_cert_filepath</b>
<dd>If libwebsockets was compiled to use ssl, and you want
to listen using SSL, set to the filepath to fetch the
{
unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 4096 +
LWS_SEND_BUFFER_POST_PADDING];
- int l;
+ int l = 0;
+ int n;
switch (reason) {
case LWS_CALLBACK_CLIENT_WRITEABLE:
- l = sprintf((char *)&buf[LWS_SEND_BUFFER_PRE_PADDING],
+ for (n = 0; n < 1; n++)
+ l += sprintf((char *)&buf[LWS_SEND_BUFFER_PRE_PADDING + l],
"c #%06X %d %d %d;",
(int)random() & 0xffffff,
(int)random() % 500,
*/
context = libwebsocket_create_context(CONTEXT_PORT_NO_LISTEN, NULL,
- protocols, libwebsocket_internal_extensions,
+ protocols,
+#ifndef LWS_NO_EXTENSIONS
+ libwebsocket_internal_extensions,
+#else
+ NULL,
+#endif
NULL, NULL, NULL, -1, -1, 0, NULL);
if (context == NULL) {
fprintf(stderr, "Creating libwebsocket context failed\n");
cert_path = key_path = NULL;
context = libwebsocket_create_context(server_port, interface, protocols,
+#ifndef LWS_NO_EXTENSIONS
libwebsocket_internal_extensions,
+#else
+ NULL,
+#endif
cert_path, key_path, NULL, -1, -1, opts, NULL);
if (context == NULL) {
fprintf(stderr, "libwebsocket init failed\n");
context = libwebsocket_create_context(CONTEXT_PORT_NO_LISTEN, NULL,
protocols,
- libwebsocket_internal_extensions,
+#ifndef LWS_NO_EXTENSIONS
+ libwebsocket_internal_extensions,
+#else
+ NULL,
+#endif
NULL, NULL, NULL, -1, -1, 0, NULL);
if (context == NULL) {
fprintf(stderr, "Creating libwebsocket context failed\n");
/* lws-mirror_protocol */
-#define MAX_MESSAGE_QUEUE 64
+#define MAX_MESSAGE_QUEUE 128
struct per_session_data__lws_mirror {
struct libwebsocket *wsi;
case LWS_CALLBACK_SERVER_WRITEABLE:
if (close_testing)
break;
- if (pss->ringbuffer_tail != ringbuffer_head) {
+ while (pss->ringbuffer_tail != ringbuffer_head) {
n = libwebsocket_write(wsi, (unsigned char *)
ringbuffer[pss->ringbuffer_tail].payload +
pss->ringbuffer_tail++;
if (((ringbuffer_head - pss->ringbuffer_tail) &
- (MAX_MESSAGE_QUEUE - 1)) < (MAX_MESSAGE_QUEUE - 15)) {
+ (MAX_MESSAGE_QUEUE - 1)) == (MAX_MESSAGE_QUEUE - 15)) {
for (n = 0; n < num_wsi_choked; n++)
libwebsocket_rx_flow_control(wsi_choked[n], 1);
num_wsi_choked = 0;
}
+ // lwsl_debug("tx fifo %d\n", (ringbuffer_head - pss->ringbuffer_tail) & (MAX_MESSAGE_QUEUE - 1));
-// lwsl_debug("tx fifo %d\n", (ringbuffer_head - pss->ringbuffer_tail) & (MAX_MESSAGE_QUEUE - 1));
-
- libwebsocket_callback_on_writable(context, wsi);
-
+ if (lws_send_pipe_choked(wsi)) {
+ libwebsocket_callback_on_writable(context, wsi);
+ return 0;
+ }
}
break;
ringbuffer_head++;
if (((ringbuffer_head - pss->ringbuffer_tail) &
- (MAX_MESSAGE_QUEUE - 1)) < (MAX_MESSAGE_QUEUE - 10))
+ (MAX_MESSAGE_QUEUE - 1)) != (MAX_MESSAGE_QUEUE - 2))
goto done;
choke:
cert_path = key_path = NULL;
context = libwebsocket_create_context(port, interface, protocols,
+#ifndef LWS_NO_EXTENSIONS
libwebsocket_internal_extensions,
+#else
+ NULL,
+#endif
cert_path, key_path, NULL, -1, -1, opts, NULL);
if (context == NULL) {
lwsl_err("libwebsocket init failed\n");