client allow user callback to close on nonzero return
authorAndy Green <andy.green@linaro.org>
Sat, 15 Mar 2014 01:32:40 +0000 (09:32 +0800)
committerAndy Green <andy.green@linaro.org>
Sat, 15 Mar 2014 01:32:40 +0000 (09:32 +0800)
Signed-off-by: Andy Green <andy.green@linaro.org>
lib/client-parser.c
lib/extension-deflate-frame.c
lib/handshake.c

index b6b592b..23c8f07 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * libwebsockets - small server side websockets and web server implementation
  *
- * Copyright (C) 2010-2013 Andy Green <andy@warmcat.com>
+ * Copyright (C) 2010-2014 Andy Green <andy@warmcat.com>
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -382,7 +382,8 @@ spill:
                        }
                }
 #endif
-               if (eff_buf.token_len <= 0 && callback_action != LWS_CALLBACK_CLIENT_RECEIVE_PONG)
+               if (eff_buf.token_len <= 0 &&
+                           callback_action != LWS_CALLBACK_CLIENT_RECEIVE_PONG)
                        goto already_done;
 
                eff_buf.token[eff_buf.token_len] = '\0';
@@ -393,7 +394,7 @@ spill:
                if (callback_action == LWS_CALLBACK_CLIENT_RECEIVE_PONG)
                        lwsl_info("Client doing pong callback\n");
 
-               wsi->protocol->callback(
+               m = wsi->protocol->callback(
                        wsi->protocol->owning_server,
                        wsi,
                        (enum libwebsocket_callback_reasons)callback_action,
@@ -401,6 +402,10 @@ spill:
                        eff_buf.token,
                        eff_buf.token_len);
 
+               /* if user code wants to close, let caller know */
+               if (m)
+                       return 1;
+
 already_done:
                wsi->u.ws.rx_user_buffer_head = 0;
                break;
index b206476..6cf6ac0 100644 (file)
@@ -163,7 +163,7 @@ bail:
                                 * we will get a destroy callback to take care
                                 * of closing nicely
                                 */
-                               lwsl_err("zlib error inflate %d: %s\n",
+                               lwsl_info("zlib error inflate %d: %s\n",
                                                           n, conn->zs_in.msg);
                                return -1;
                        }
index c7989c5..7611a6a 100644 (file)
@@ -146,7 +146,7 @@ http_postbody:
                case LWS_CONNMODE_WS_CLIENT:
                        for (n = 0; n < len; n++)
                                if (libwebsocket_client_rx_sm(wsi, *buf++)) {
-                                       lwsl_info("client_rx_sm failed\n");
+                                       lwsl_debug("client_rx_sm failed\n");
                                        goto bail;
                                }
                        return 0;
@@ -417,7 +417,7 @@ cleanup:
                        for (n = 0; n < len; n++)
                                if (libwebsocket_client_rx_sm(
                                                             wsi, *buf++) < 0) {
-                                       lwsl_info("client rx has bailed\n");
+                                       lwsl_debug("client rx has bailed\n");
                                        goto bail;
                                }
 
@@ -450,7 +450,7 @@ bail_nuke_ah:
 #endif
 
 bail:
-       lwsl_info("closing connection at libwebsocket_read bail:\n");
+       lwsl_debug("closing connection at libwebsocket_read bail:\n");
 
        libwebsocket_close_and_free_session(context, wsi,
                                                     LWS_CLOSE_STATUS_NOSTATUS);