cleanups after api changes and mbed update

Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
Andy Green 2015-12-04 16:54:12 +08:00
parent 9c9f2180f3
commit dc6e47cafc
3 changed files with 96 additions and 141 deletions

View file

@ -91,9 +91,9 @@ lws_create_context(struct lws_context_creation_info *info)
lwsl_notice("IPV6 compiled in but disabled\n"); lwsl_notice("IPV6 compiled in but disabled\n");
#else #else
lwsl_notice("IPV6 not compiled in\n"); lwsl_notice("IPV6 not compiled in\n");
#endif
#endif #endif
lws_feature_status_libev(info); lws_feature_status_libev(info);
#endif
lwsl_info(" LWS_MAX_HEADER_LEN: %u\n", LWS_MAX_HEADER_LEN); lwsl_info(" LWS_MAX_HEADER_LEN: %u\n", LWS_MAX_HEADER_LEN);
lwsl_info(" LWS_MAX_PROTOCOLS: %u\n", LWS_MAX_PROTOCOLS); lwsl_info(" LWS_MAX_PROTOCOLS: %u\n", LWS_MAX_PROTOCOLS);
@ -148,21 +148,13 @@ lws_create_context(struct lws_context_creation_info *info)
/* to reduce this allocation, */ /* to reduce this allocation, */
context->max_fds = getdtablesize(); context->max_fds = getdtablesize();
lwsl_notice(" static allocation: %u + (%u x %u fds) = %u bytes\n", lwsl_notice(" ctx mem: %u bytes\n", sizeof(struct lws_context) +
sizeof(struct lws_context), ((sizeof(struct lws_pollfd) + sizeof(struct lws *)) *
sizeof(struct lws_pollfd) + context->max_fds));
sizeof(struct lws *),
context->max_fds,
sizeof(struct lws_context) +
((sizeof(struct lws_pollfd) +
sizeof(struct lws *)) *
context->max_fds));
context->fds = lws_zalloc(sizeof(struct lws_pollfd) * context->fds = lws_zalloc(sizeof(struct lws_pollfd) * context->max_fds);
context->max_fds);
if (context->fds == NULL) { if (context->fds == NULL) {
lwsl_err("Unable to allocate fds array for %d connections\n", lwsl_err("OOM allocating %d fds\n", context->max_fds);
context->max_fds);
goto bail; goto bail;
} }
@ -195,10 +187,8 @@ lws_create_context(struct lws_context_creation_info *info)
#endif #endif
} }
lwsl_notice( lwsl_notice(" per-conn mem: %u + %u headers + protocol rx buf\n",
" per-conn mem: %u + %u headers + protocol rx buf\n", sizeof(struct lws), sizeof(struct allocated_headers));
sizeof(struct lws),
sizeof(struct allocated_headers));
if (lws_context_init_server_ssl(info, context)) if (lws_context_init_server_ssl(info, context))
goto bail; goto bail;
@ -219,12 +209,8 @@ lws_create_context(struct lws_context_creation_info *info)
/* initialize supported protocols */ /* initialize supported protocols */
for (context->count_protocols = 0; for (context->count_protocols = 0;
info->protocols[context->count_protocols].callback; info->protocols[context->count_protocols].callback;
context->count_protocols++) { context->count_protocols++) {
// lwsl_notice(" Protocol: %s\n",
// info->protocols[context->count_protocols].name);
info->protocols[context->count_protocols].owning_server = info->protocols[context->count_protocols].owning_server =
context; context;
info->protocols[context->count_protocols].protocol_index = info->protocols[context->count_protocols].protocol_index =
@ -242,16 +228,13 @@ lws_create_context(struct lws_context_creation_info *info)
* give all extensions a chance to create any per-context * give all extensions a chance to create any per-context
* allocations they need * allocations they need
*/ */
if (info->port != CONTEXT_PORT_NO_LISTEN) { if (info->port != CONTEXT_PORT_NO_LISTEN) {
if (lws_ext_callback_for_each_extension_type(context, NULL, if (lws_ext_callback_for_each_extension_type(context, NULL,
LWS_EXT_CALLBACK_SERVER_CONTEXT_CONSTRUCT, LWS_EXT_CALLBACK_SERVER_CONTEXT_CONSTRUCT, NULL, 0) < 0)
NULL, 0) < 0)
goto bail; goto bail;
} else } else
if (lws_ext_callback_for_each_extension_type(context, NULL, if (lws_ext_callback_for_each_extension_type(context, NULL,
LWS_EXT_CALLBACK_CLIENT_CONTEXT_CONSTRUCT, LWS_EXT_CALLBACK_CLIENT_CONTEXT_CONSTRUCT, NULL, 0) < 0)
NULL, 0) < 0)
goto bail; goto bail;
return context; return context;
@ -272,10 +255,8 @@ bail:
LWS_VISIBLE void LWS_VISIBLE void
lws_context_destroy(struct lws_context *context) lws_context_destroy(struct lws_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 */
int n;
struct lws_protocols *protocol = NULL; struct lws_protocols *protocol = NULL;
int n;
lwsl_notice("%s\n", __func__); lwsl_notice("%s\n", __func__);
@ -288,12 +269,12 @@ lws_context_destroy(struct lws_context *context)
#endif #endif
for (n = 0; n < context->fds_count; n++) { for (n = 0; n < context->fds_count; n++) {
struct lws *wsi = struct lws *wsi = wsi_from_fd(context, context->fds[n].fd);
wsi_from_fd(context, context->fds[n].fd);
if (!wsi) if (!wsi)
continue; continue;
lws_close_and_free_session(context, lws_close_and_free_session(context, wsi,
wsi, LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY /* no protocol close */); LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY
/* no protocol close */);
n--; n--;
} }
@ -301,20 +282,12 @@ lws_context_destroy(struct lws_context *context)
* give all extensions a chance to clean up any per-context * give all extensions a chance to clean up any per-context
* allocations they might have made * allocations they might have made
*/ */
// TODO: I am not sure, but are we never supposed to be able to run a server
// and client at the same time for a given context? n = lws_ext_callback_for_each_extension_type(context, NULL,
// Otherwise both of these callbacks should always be called! LWS_EXT_CALLBACK_SERVER_CONTEXT_DESTRUCT, NULL, 0);
if (context->listen_port != CONTEXT_PORT_NO_LISTEN) {
if (lws_ext_callback_for_each_extension_type(context, NULL, n = lws_ext_callback_for_each_extension_type(context, NULL,
LWS_EXT_CALLBACK_SERVER_CONTEXT_DESTRUCT, NULL, 0) < 0) { LWS_EXT_CALLBACK_CLIENT_CONTEXT_DESTRUCT, NULL, 0);
lwsl_err("Got error from server extension callback on cleanup");
}
} else {
if (lws_ext_callback_for_each_extension_type(context, NULL,
LWS_EXT_CALLBACK_CLIENT_CONTEXT_DESTRUCT, NULL, 0) < 0) {
lwsl_err("Got error from client extension callback on cleanup");
}
}
/* /*
* inform all the protocols that they are done and will have no more * inform all the protocols that they are done and will have no more
@ -323,8 +296,9 @@ lws_context_destroy(struct lws_context *context)
protocol = context->protocols; protocol = context->protocols;
if (protocol) { if (protocol) {
while (protocol->callback) { while (protocol->callback) {
protocol->callback(context, NULL, LWS_CALLBACK_PROTOCOL_DESTROY, protocol->callback(context, NULL,
NULL, NULL, 0); LWS_CALLBACK_PROTOCOL_DESTROY,
NULL, NULL, 0);
protocol++; protocol++;
} }
} }

View file

@ -44,18 +44,14 @@ lws_free_wsi(struct lws *wsi)
return; return;
/* Protocol user data may be allocated either internally by lws /* Protocol user data may be allocated either internally by lws
* or by specified the user. Important we don't free external user data */ * or by specified the user.
if (wsi->protocol && wsi->protocol->per_session_data_size * We should only free what we allocated. */
&& wsi->user_space && !wsi->user_space_externally_allocated) { if (wsi->protocol && wsi->protocol->per_session_data_size &&
wsi->user_space && !wsi->user_space_externally_allocated)
lws_free(wsi->user_space); lws_free(wsi->user_space);
}
lws_free2(wsi->rxflow_buffer); lws_free2(wsi->rxflow_buffer);
lws_free2(wsi->truncated_send_malloc); lws_free2(wsi->truncated_send_malloc);
// TODO: Probably should handle the union structs in wsi->u here depending
// on connection mode as well. Too spaghetti for me to follow however...
lws_free_header_table(wsi); lws_free_header_table(wsi);
lws_free(wsi); lws_free(wsi);
} }
@ -64,17 +60,24 @@ void
lws_close_and_free_session(struct lws_context *context, lws_close_and_free_session(struct lws_context *context,
struct lws *wsi, enum lws_close_status reason) struct lws *wsi, enum lws_close_status reason)
{ {
int n, m, ret; int n, m, ret, old_state;
int old_state;
unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 2 +
LWS_SEND_BUFFER_POST_PADDING];
struct lws_tokens eff_buf; struct lws_tokens eff_buf;
unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 2 +
LWS_SEND_BUFFER_POST_PADDING];
if (!wsi) if (!wsi)
return; return;
old_state = wsi->state; old_state = wsi->state;
if (wsi->mode == LWS_CONNMODE_HTTP_SERVING_ACCEPTED &&
wsi->u.http.fd != LWS_INVALID_FILE) {
lwsl_debug("closing http file\n");
compatible_file_close(wsi->u.http.fd);
wsi->u.http.fd = LWS_INVALID_FILE;
context->protocols[0].callback(context, wsi,
LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0);
}
if (wsi->socket_is_permanently_unusable || if (wsi->socket_is_permanently_unusable ||
reason == LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY) reason == LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY)
goto just_kill_connection; goto just_kill_connection;
@ -107,24 +110,13 @@ lws_close_and_free_session(struct lws_context *context,
wsi->u.ws.close_reason = reason; wsi->u.ws.close_reason = reason;
if (wsi->mode == LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT || if (wsi->mode == LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT ||
wsi->mode == LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE) wsi->mode == LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE)
goto just_kill_connection; goto just_kill_connection;
if (wsi->mode == LWS_CONNMODE_HTTP_SERVING) if (wsi->mode == LWS_CONNMODE_HTTP_SERVING)
context->protocols[0].callback(context, wsi, context->protocols[0].callback(context, wsi,
LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0); LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0);
if (wsi->mode == LWS_CONNMODE_HTTP_SERVING_ACCEPTED) {
if (wsi->u.http.fd != LWS_INVALID_FILE) {
// TODO: If we're just closing with LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY this file descriptor might leak?
lwsl_debug("closing http file\n");
compatible_file_close(wsi->u.http.fd);
wsi->u.http.fd = LWS_INVALID_FILE;
context->protocols[0].callback(context, wsi,
LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0);
}
}
/* /*
* are his extensions okay with him closing? Eg he might be a mux * are his extensions okay with him closing? Eg he might be a mux
* parent and just his ch1 aspect is closing? * parent and just his ch1 aspect is closing?
@ -165,7 +157,8 @@ lws_close_and_free_session(struct lws_context *context,
if (eff_buf.token_len) if (eff_buf.token_len)
if (lws_issue_raw(wsi, (unsigned char *)eff_buf.token, if (lws_issue_raw(wsi, (unsigned char *)eff_buf.token,
eff_buf.token_len) != eff_buf.token_len) { eff_buf.token_len) !=
eff_buf.token_len) {
lwsl_debug("close: ext spill failed\n"); lwsl_debug("close: ext spill failed\n");
goto just_kill_connection; goto just_kill_connection;
} }
@ -191,25 +184,20 @@ lws_close_and_free_session(struct lws_context *context,
/* make valgrind happy */ /* make valgrind happy */
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
n = lws_write(wsi, n = lws_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING + 2],
&buf[LWS_SEND_BUFFER_PRE_PADDING + 2], 0, LWS_WRITE_CLOSE);
0, LWS_WRITE_CLOSE);
if (n >= 0) { if (n >= 0) {
/* /*
* we have sent a nice protocol level indication we * we have sent a nice protocol level indication we
* now wish to close, we should not send anything more * now wish to close, we should not send anything more
*/ */
wsi->state = WSI_STATE_AWAITING_CLOSE_ACK; wsi->state = WSI_STATE_AWAITING_CLOSE_ACK;
/* /*
* ...and we should wait for a reply for a bit * ...and we should wait for a reply for a bit
* out of politeness * out of politeness
*/ */
lws_set_timeout(wsi, PENDING_TIMEOUT_CLOSE_ACK, 1);
lws_set_timeout(wsi,
PENDING_TIMEOUT_CLOSE_ACK, 1);
lwsl_debug("sent close indication, awaiting ack\n"); lwsl_debug("sent close indication, awaiting ack\n");
return; return;
@ -228,10 +216,9 @@ just_kill_connection:
* we won't be servicing or receiving anything further from this guy * we won't be servicing or receiving anything further from this guy
* delete socket from the internal poll list if still present * delete socket from the internal poll list if still present
*/ */
lws_ssl_remove_wsi_from_buffered_list(context, wsi); lws_ssl_remove_wsi_from_buffered_list(context, wsi);
// checking return redundant since we anyway close /* checking return redundant since we anyway close */
remove_wsi_socket_from_fds(context, wsi); remove_wsi_socket_from_fds(context, wsi);
wsi->state = WSI_STATE_DEAD_SOCKET; wsi->state = WSI_STATE_DEAD_SOCKET;
@ -245,11 +232,10 @@ just_kill_connection:
lws_free2(wsi->u.ws.rx_user_buffer); lws_free2(wsi->u.ws.rx_user_buffer);
if (wsi->truncated_send_malloc) { if (wsi->truncated_send_malloc)
/* not going to be completed... nuke it */ /* not going to be completed... nuke it */
lws_free2(wsi->truncated_send_malloc); lws_free2(wsi->truncated_send_malloc);
wsi->truncated_send_len = 0;
}
if (wsi->u.ws.ping_payload_buf) { if (wsi->u.ws.ping_payload_buf) {
lws_free2(wsi->u.ws.ping_payload_buf); lws_free2(wsi->u.ws.ping_payload_buf);
wsi->u.ws.ping_payload_alloc = 0; wsi->u.ws.ping_payload_alloc = 0;
@ -261,13 +247,13 @@ just_kill_connection:
/* tell the user it's all over for this guy */ /* tell the user it's all over for this guy */
if (wsi->protocol && wsi->protocol->callback && if (wsi->protocol && wsi->protocol->callback &&
((old_state == WSI_STATE_ESTABLISHED) || ((old_state == WSI_STATE_ESTABLISHED) ||
(old_state == WSI_STATE_RETURNED_CLOSE_ALREADY) || (old_state == WSI_STATE_RETURNED_CLOSE_ALREADY) ||
(old_state == WSI_STATE_AWAITING_CLOSE_ACK) || (old_state == WSI_STATE_AWAITING_CLOSE_ACK) ||
(old_state == WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE))) { (old_state == WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE))) {
lwsl_debug("calling back CLOSED\n"); lwsl_debug("calling back CLOSED\n");
wsi->protocol->callback(context, wsi, LWS_CALLBACK_CLOSED, wsi->protocol->callback(context, wsi, LWS_CALLBACK_CLOSED,
wsi->user_space, NULL, 0); wsi->user_space, NULL, 0);
} else if (wsi->mode == LWS_CONNMODE_HTTP_SERVING_ACCEPTED) { } else if (wsi->mode == LWS_CONNMODE_HTTP_SERVING_ACCEPTED) {
lwsl_debug("calling back CLOSED_HTTP\n"); lwsl_debug("calling back CLOSED_HTTP\n");
context->protocols[0].callback(context, wsi, context->protocols[0].callback(context, wsi,
@ -276,15 +262,16 @@ just_kill_connection:
wsi->mode == LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT) { wsi->mode == LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT) {
lwsl_debug("Connection closed before server reply\n"); lwsl_debug("Connection closed before server reply\n");
context->protocols[0].callback(context, wsi, context->protocols[0].callback(context, wsi,
LWS_CALLBACK_CLIENT_CONNECTION_ERROR, LWS_CALLBACK_CLIENT_CONNECTION_ERROR,
wsi->user_space, NULL, 0 ); wsi->user_space, NULL, 0);
} else } else
lwsl_debug("not calling back closed mode=%d state=%d\n", lwsl_debug("not calling back closed mode=%d state=%d\n",
wsi->mode, old_state); wsi->mode, old_state);
/* deallocate any active extension contexts */ /* deallocate any active extension contexts */
if (lws_ext_callback_for_each_active(wsi, LWS_EXT_CALLBACK_DESTROY, NULL, 0) < 0) if (lws_ext_callback_for_each_active(wsi, LWS_EXT_CALLBACK_DESTROY,
NULL, 0) < 0)
lwsl_warn("extension destruction failed\n"); lwsl_warn("extension destruction failed\n");
#ifndef LWS_NO_EXTENSIONS #ifndef LWS_NO_EXTENSIONS
for (n = 0; n < wsi->count_active_extensions; n++) for (n = 0; n < wsi->count_active_extensions; n++)
@ -298,8 +285,6 @@ just_kill_connection:
LWS_EXT_CALLBACK_DESTROY_ANY_WSI_CLOSING, NULL, 0) < 0) LWS_EXT_CALLBACK_DESTROY_ANY_WSI_CLOSING, NULL, 0) < 0)
lwsl_warn("ext destroy wsi failed\n"); lwsl_warn("ext destroy wsi failed\n");
/* lwsl_info("closing fd=%d\n", wsi->sock); */
if (!lws_ssl_close(wsi) && lws_socket_is_valid(wsi->sock)) { if (!lws_ssl_close(wsi) && lws_socket_is_valid(wsi->sock)) {
#if LWS_POSIX #if LWS_POSIX
n = shutdown(wsi->sock, SHUT_RDWR); n = shutdown(wsi->sock, SHUT_RDWR);
@ -317,8 +302,8 @@ just_kill_connection:
} }
/* outermost destroy notification for wsi (user_space still intact) */ /* outermost destroy notification for wsi (user_space still intact) */
context->protocols[0].callback(context, wsi, context->protocols[0].callback(context, wsi, LWS_CALLBACK_WSI_DESTROY,
LWS_CALLBACK_WSI_DESTROY, wsi->user_space, NULL, 0); wsi->user_space, NULL, 0);
lws_free_wsi(wsi); lws_free_wsi(wsi);
} }
@ -495,12 +480,11 @@ lws_context_user(struct lws_context *context)
*/ */
LWS_VISIBLE int LWS_VISIBLE int
lws_callback_all_protocol( lws_callback_all_protocol(const struct lws_protocols *protocol, int reason)
const struct lws_protocols *protocol, int reason)
{ {
struct lws_context *context = protocol->owning_server; struct lws_context *context = protocol->owning_server;
int n;
struct lws *wsi; struct lws *wsi;
int n;
for (n = 0; n < context->fds_count; n++) { for (n = 0; n < context->fds_count; n++) {
wsi = wsi_from_fd(context, context->fds[n].fd); wsi = wsi_from_fd(context, context->fds[n].fd);
@ -508,7 +492,7 @@ lws_callback_all_protocol(
continue; continue;
if (wsi->protocol == protocol) if (wsi->protocol == protocol)
protocol->callback(context, wsi, protocol->callback(context, wsi,
reason, wsi->user_space, NULL, 0); reason, wsi->user_space, NULL, 0);
} }
return 0; return 0;
@ -525,8 +509,7 @@ lws_callback_all_protocol(
*/ */
LWS_VISIBLE void LWS_VISIBLE void
lws_set_timeout(struct lws *wsi, lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs)
enum pending_timeout reason, int secs)
{ {
time_t now; time_t now;
@ -615,7 +598,7 @@ lws_rx_flow_control(struct lws *wsi, int enable)
if (enable == (wsi->rxflow_change_to & LWS_RXFLOW_ALLOW)) if (enable == (wsi->rxflow_change_to & LWS_RXFLOW_ALLOW))
return 0; return 0;
lwsl_info("lws_rx_flow_control(0x%p, %d)\n", wsi, enable); lwsl_info("%s: (0x%p, %d)\n", __func__, wsi, enable);
wsi->rxflow_change_to = LWS_RXFLOW_PENDING_CHANGE | !!enable; wsi->rxflow_change_to = LWS_RXFLOW_PENDING_CHANGE | !!enable;
return 0; return 0;
@ -794,28 +777,33 @@ lws_ensure_user_space(struct lws *wsi)
return 1; return 1;
} }
} else } else
lwsl_info("%s: %p protocol pss %u, user_space=%d\n", __func__, wsi, wsi->protocol->per_session_data_size, wsi->user_space); lwsl_info("%s: %p protocol pss %u, user_space=%d\n",
__func__, wsi, wsi->protocol->per_session_data_size,
wsi->user_space);
return 0; return 0;
} }
#if LWS_POSIX
LWS_VISIBLE void lwsl_emit_stderr(int level, const char *line) LWS_VISIBLE void lwsl_emit_stderr(int level, const char *line)
{ {
char buf[300];
unsigned long long now; unsigned long long now;
char buf[300];
int n; int n;
buf[0] = '\0'; buf[0] = '\0';
for (n = 0; n < LLL_COUNT; n++) for (n = 0; n < LLL_COUNT; n++) {
if (level == (1 << n)) { if (level != (1 << n))
now = time_in_microseconds() / 100; continue;
sprintf(buf, "[%llu:%04d] %s: ", (unsigned long long) now / 10000, now = time_in_microseconds() / 100;
(int)(now % 10000), log_level_names[n]); sprintf(buf, "[%llu:%04d] %s: ",
break; (unsigned long long) now / 10000,
} (int)(now % 10000), log_level_names[n]);
break;
}
fprintf(stderr, "%s%s", buf, line); fprintf(stderr, "%s%s", buf, line);
} }
#endif
LWS_VISIBLE void _lws_logv(int filter, const char *format, va_list vl) LWS_VISIBLE void _lws_logv(int filter, const char *format, va_list vl)
{ {
@ -851,12 +839,11 @@ LWS_VISIBLE void _lws_log(int filter, const char *format, ...)
*/ */
LWS_VISIBLE void lws_set_log_level(int level, LWS_VISIBLE void lws_set_log_level(int level,
void (*log_emit_function)(int level, void (*func)(int level, const char *line))
const char *line))
{ {
log_level = level; log_level = level;
if (log_emit_function) if (func)
lwsl_emit = log_emit_function; lwsl_emit = func;
} }
/** /**
@ -997,10 +984,8 @@ libwebsocket_cancel_service(struct lws_context *context)
#ifdef LWS_USE_LIBEV #ifdef LWS_USE_LIBEV
#undef libwebsocket_sigint_cfg #undef libwebsocket_sigint_cfg
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
libwebsocket_sigint_cfg( libwebsocket_sigint_cfg(struct lws_context *context, int use_ev_sigint,
struct lws_context *context, lws_ev_signal_cb* cb)
int use_ev_sigint,
lws_ev_signal_cb* cb)
{ {
return lws_sigint_cfg(context, use_ev_sigint, cb); return lws_sigint_cfg(context, use_ev_sigint, cb);
} }

View file

@ -157,7 +157,7 @@ void lws_conn_listener::start(const uint16_t port)
srv.error_check(err); srv.error_check(err);
} }
int lws_conn::actual_onRX(Socket *s) void lws_conn::onRX(Socket *s)
{ {
struct lws_pollfd pollfd; struct lws_pollfd pollfd;
@ -169,7 +169,7 @@ int lws_conn::actual_onRX(Socket *s)
lwsl_debug("%s: lws %p\n", __func__, wsi); lwsl_debug("%s: lws %p\n", __func__, wsi);
return lws_service_fd(wsi->protocol->owning_server, &pollfd); lws_service_fd(wsi->protocol->owning_server, &pollfd);
} }
/* /*
@ -204,13 +204,13 @@ void lws_conn_listener::onIncoming(TCPListener *tl, void *impl)
lws_server_socket_service(wsi->protocol->owning_server, lws_server_socket_service(wsi->protocol->owning_server,
wsi, (struct pollfd *)conn); wsi, (struct pollfd *)conn);
conn->ts->setOnSent(Socket::SentHandler_t(conn, &lws_conn::onSent));
conn->ts->setOnReadable(TCPStream::ReadableHandler_t(conn, &lws_conn::onRX));
conn->ts->setOnError(TCPStream::ErrorHandler_t(conn, &lws_conn::onError)); conn->ts->setOnError(TCPStream::ErrorHandler_t(conn, &lws_conn::onError));
conn->ts->setOnDisconnect(TCPStream::DisconnectHandler_t(conn, conn->ts->setOnDisconnect(TCPStream::DisconnectHandler_t(conn,
&lws_conn::onDisconnect)); &lws_conn::onDisconnect));
conn->ts->setOnSent(Socket::SentHandler_t(conn, &lws_conn::onSent));
conn->ts->setOnReadable(TCPStream::ReadableHandler_t(conn, &lws_conn::onRX));
conn->actual_onRX((Socket *)conn->ts); conn->onRX((Socket *)conn->ts);
lwsl_debug("%s: exit\n", __func__); lwsl_debug("%s: exit\n", __func__);
} }
@ -242,11 +242,6 @@ lws_plat_delete_socket_from_fds(struct lws_context *context,
(void)m; (void)m;
} }
void lws_conn::onRX(Socket *s)
{
actual_onRX(s);
}
void lws_conn_listener::onDisconnect(TCPStream *s) void lws_conn_listener::onDisconnect(TCPStream *s)
{ {
lwsl_info("%s\r\n", __func__); lwsl_info("%s\r\n", __func__);
@ -272,7 +267,8 @@ void lws_conn::onSent(Socket *s, uint16_t len)
(void)len; (void)len;
if (!awaiting_on_writeable) { if (!awaiting_on_writeable) {
lwsl_debug("%s: wsi %p (setting writable=1)\r\n", __func__, (void *)wsi); lwsl_debug("%s: wsi %p (setting writable=1)\r\n",
__func__, (void *)wsi);
writeable = 1; writeable = 1;
return; return;
} }
@ -298,6 +294,7 @@ void lws_conn_listener::onError(Socket *s, socket_error_t err)
void lws_conn::onDisconnect(TCPStream *s) void lws_conn::onDisconnect(TCPStream *s)
{ {
lwsl_notice("%s:\r\n", __func__);
(void)s; (void)s;
lws_close_and_free_session(wsi->protocol->owning_server, wsi, lws_close_and_free_session(wsi->protocol->owning_server, wsi,
LWS_CLOSE_STATUS_NOSTATUS); LWS_CLOSE_STATUS_NOSTATUS);
@ -308,6 +305,5 @@ void lws_conn::onError(Socket *s, socket_error_t err)
{ {
(void) s; (void) s;
lwsl_notice("Socket Error: %s (%d)\r\n", socket_strerror(err), err); lwsl_notice("Socket Error: %s (%d)\r\n", socket_strerror(err), err);
if (ts) s->close();
ts->close();
} }