update ping test client and stop exposing payload to extensions 17/2917/1
authorAndy Green <andy.green@linaro.org>
Wed, 16 Jan 2013 06:35:12 +0000 (14:35 +0800)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Thu, 7 Mar 2013 21:01:25 +0000 (13:01 -0800)
Ping and Pong payload in control messages need to be
above the fray of extension payload munging

Signed-off-by: Andy Green <andy.green@linaro.org>
lib/client-parser.c
lib/handshake.c
lib/libwebsockets.c
lib/output.c
lib/parsers.c
test-server/test-ping.c

index 72e91b2..ee87d71 100644 (file)
@@ -34,7 +34,7 @@ int libwebsocket_client_rx_sm(struct libwebsocket *wsi, unsigned char c)
        struct lws_tokens eff_buf;
        int m;
 
-       lwsl_parser(" CRX: %02X %d\n", c, wsi->lws_rx_parse_state);
+//     lwsl_parser(" CRX: %02X %d\n", c, wsi->lws_rx_parse_state);
 
        switch (wsi->lws_rx_parse_state) {
        case LWS_RXPS_NEW:
@@ -401,6 +401,7 @@ spill:
                        return -1;
 
                case LWS_WS_OPCODE_07__PING:
+                       lwsl_info("client received ping, doing pong\n");
                        /* parrot the ping packet payload back as a pong*/
                        n = libwebsocket_write(wsi, (unsigned char *)
                            &wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
@@ -409,6 +410,9 @@ spill:
                        break;
 
                case LWS_WS_OPCODE_07__PONG:
+                       lwsl_info("client receied pong\n");
+                       lwsl_hexdump(&wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
+                                   wsi->rx_user_buffer_head);
                        /* keep the statistics... */
                        wsi->pings_vs_pongs--;
 
@@ -486,7 +490,9 @@ spill:
                if (eff_buf.token_len > 0) {
                        eff_buf.token[eff_buf.token_len] = '\0';
 
-                       if (wsi->protocol->callback)
+                       if (wsi->protocol->callback) {
+                               if (callback_action == LWS_CALLBACK_CLIENT_RECEIVE_PONG)
+                                       lwsl_info("Client doing pong callback\n");
                                wsi->protocol->callback(
                                                wsi->protocol->owning_server,
                                                wsi,
@@ -494,6 +500,7 @@ spill:
                                                wsi->user_space,
                                                eff_buf.token,
                                                eff_buf.token_len);
+                       }
                }
 already_done:
                wsi->rx_user_buffer_head = 0;
index 634ccc8..d3ce3c8 100644 (file)
@@ -562,6 +562,9 @@ libwebsocket_read(struct libwebsocket_context *context,
 #endif
 
 #ifndef LWS_NO_CLIENT
+
+//             lwsl_info("mode=%d\n", wsi->mode);
+
                switch (wsi->mode) {
                case LWS_CONNMODE_WS_CLIENT_WAITING_PROXY_REPLY:
                case LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE:
index df90289..68c14e6 100644 (file)
@@ -306,9 +306,11 @@ just_kill_connection:
 
        /* delete it from the internal poll list if still present */
 
+       m = 0;
        for (n = 0; n < context->fds_count; n++) {
                if (context->fds[n].fd != wsi->sock)
                        continue;
+               m = 1;
                while (n < context->fds_count - 1) {
                        context->fds[n] = context->fds[n + 1];
                        n++;
@@ -318,6 +320,9 @@ just_kill_connection:
                n = context->fds_count;
        }
 
+       if (!m)
+               lwsl_err("Failed to remove fd %d from fds array\n", wsi->sock);
+
        /* remove also from external POLL support via protocol 0 */
        if (wsi->sock)
                context->protocols[0].callback(context, wsi,
index 8e72b7d..671e78c 100644 (file)
@@ -312,14 +312,17 @@ int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf,
        eff_buf.token = (char *)buf;
        eff_buf.token_len = len;
 
-       for (n = 0; n < wsi->count_active_extensions; n++) {
-               m = wsi->active_extensions[n]->callback(
-                       wsi->protocol->owning_server,
-                       wsi->active_extensions[n], wsi,
-                       LWS_EXT_CALLBACK_PAYLOAD_TX,
-                       wsi->active_extensions_user[n], &eff_buf, 0);
-               if (m < 0)
-                       return -1;
+       if (protocol != LWS_WRITE_PING && protocol != LWS_WRITE_PONG) {
+
+               for (n = 0; n < wsi->count_active_extensions; n++) {
+                       m = wsi->active_extensions[n]->callback(
+                               wsi->protocol->owning_server,
+                               wsi->active_extensions[n], wsi,
+                               LWS_EXT_CALLBACK_PAYLOAD_TX,
+                               wsi->active_extensions_user[n], &eff_buf, 0);
+                       if (m < 0)
+                               return -1;
+               }
        }
 
        buf = (unsigned char *)eff_buf.token;
@@ -586,7 +589,7 @@ send_raw:
        lwsl_debug("\n");
 #endif
 
-       if (protocol == LWS_WRITE_HTTP) {
+       if (protocol == LWS_WRITE_HTTP || protocol == LWS_WRITE_PONG || protocol == LWS_WRITE_PING) {
                if (lws_issue_raw(wsi, (unsigned char *)buf - pre,
                                                              len + pre + post))
                        return -1;
index 98d7124..6ef26dd 100644 (file)
@@ -779,10 +779,11 @@ spill:
                        return -1;
 
                case LWS_WS_OPCODE_07__PING:
+                       lwsl_info("received %d byte ping, sending pong\n", wsi->rx_user_buffer_head);
+                       lwsl_hexdump(&wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING], wsi->rx_user_buffer_head);
                        /* parrot the ping packet payload back as a pong */
                        n = libwebsocket_write(wsi, (unsigned char *)
-                           &wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
-                                   wsi->rx_user_buffer_head, LWS_WRITE_PONG);
+                           &wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING], wsi->rx_user_buffer_head, LWS_WRITE_PONG);
                        /* ... then just drop it */
                        wsi->rx_user_buffer_head = 0;
                        return 0;
index bc03100..d768df1 100644 (file)
@@ -226,6 +226,9 @@ callback_lws_mirror(struct libwebsocket_context * this,
                        shift -= 8;
                }
 
+               while (p - &pingbuf[LWS_SEND_BUFFER_PRE_PADDING] < size)
+                       *p++ = 0;
+
                gettimeofday(&tv, NULL);
 
                psd->ringbuffer[psd->ringbuffer_head].issue_timestamp =