trac 89 add flag on fatal send fail to use simple close
authorAndy Green <andy.green@linaro.org>
Thu, 16 Oct 2014 00:23:46 +0000 (08:23 +0800)
committerAndy Green <andy.green@linaro.org>
Thu, 16 Oct 2014 00:23:46 +0000 (08:23 +0800)
Signed-off-by: Andy Green <andy.green@linaro.org>
lib/libwebsockets.c
lib/output.c
lib/private-libwebsockets.h

index a332fc6..761febe 100644 (file)
@@ -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)) {
index be1e544..b2ab45b 100644 (file)
@@ -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 */
index a52ee41..5946a5e 100755 (executable)
@@ -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;