From: Andy Green Date: Thu, 16 Oct 2014 00:23:46 +0000 (+0800) Subject: trac 89 add flag on fatal send fail to use simple close X-Git-Tag: upstream/1.7.3~547 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1e49918a4f1b55fd2d2f6c07de40db2f66df7a92;p=platform%2Fupstream%2Flibwebsockets.git trac 89 add flag on fatal send fail to use simple close Signed-off-by: Andy Green --- diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index a332fc6..761febe 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -53,6 +53,9 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context, old_state = wsi->state; + if (wsi->socket_is_permanently_unusable) + goto just_kill_connection; + switch (old_state) { case WSI_STATE_DEAD_SOCKET: return; @@ -86,15 +89,9 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context, LWS_CALLBACK_CLIENT_CONNECTION_ERROR, wsi->user_space, NULL, 0); free(wsi->u.hdr.ah); + wsi->u.hdr.ah = NULL; goto just_kill_connection; } - - if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING) { - if (wsi->u.hdr.ah) { - free(wsi->u.hdr.ah); - wsi->u.hdr.ah = NULL; - } - } if (wsi->mode == LWS_CONNMODE_HTTP_SERVING_ACCEPTED) { if (wsi->u.http.fd != LWS_INVALID_FILE) { @@ -218,6 +215,11 @@ just_kill_connection: wsi->rxflow_buffer = NULL; } + if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING && wsi->u.hdr.ah) { + free(wsi->u.hdr.ah); + wsi->u.hdr.ah = NULL; + } + if ((old_state == WSI_STATE_ESTABLISHED || wsi->mode == LWS_CONNMODE_WS_SERVING || wsi->mode == LWS_CONNMODE_WS_CLIENT)) { diff --git a/lib/output.c b/lib/output.c index be1e544..b2ab45b 100644 --- a/lib/output.c +++ b/lib/output.c @@ -132,6 +132,8 @@ int lws_issue_raw(struct libwebsocket *wsi, unsigned char *buf, size_t len) switch (n) { case LWS_SSL_CAPABLE_ERROR: + /* we're going to close, let close know sends aren't possible */ + wsi->socket_is_permanently_unusable = 1; return -1; case LWS_SSL_CAPABLE_MORE_SERVICE: /* nothing got sent, not fatal, retry the whole thing later */ diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index a52ee41..5946a5e 100755 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -742,6 +742,7 @@ struct libwebsocket { unsigned int hdr_parsing_completed:1; unsigned int user_space_externally_allocated:1; + unsigned int socket_is_permanently_unusable:1; char pending_timeout; /* enum pending_timeout */ time_t pending_timeout_limit;