handle rx flow control active when consuming payload
authorAndy Green <andy@warmcat.com>
Fri, 9 Sep 2016 20:44:56 +0000 (04:44 +0800)
committerAndy Green <andy@warmcat.com>
Fri, 9 Sep 2016 20:44:56 +0000 (04:44 +0800)
https://github.com/warmcat/libwebsockets/issues/622

lib/parsers.c
lib/private-libwebsockets.h
lib/server.c

index 8af5079d1485de42ae54bf15d5f61c4d0a98a5d5..505498571fb8cf7662f45cec3b1fe59b25a48535 100644 (file)
@@ -1505,7 +1505,7 @@ lws_remaining_packet_payload(struct lws *wsi)
  * to expect in that state and can deal with it in bulk more efficiently.
  */
 
-void
+int
 lws_payload_until_length_exhausted(struct lws *wsi, unsigned char **buf,
                                   size_t *len)
 {
@@ -1530,7 +1530,7 @@ lws_payload_until_length_exhausted(struct lws *wsi, unsigned char **buf,
 
        /* we want to leave 1 byte for the parser to handle properly */
        if (avail <= 1)
-               return;
+               return 0;
 
        avail--;
        rx_ubuf = wsi->u.ws.rx_ubuf + LWS_PRE + wsi->u.ws.rx_ubuf_head;
@@ -1560,4 +1560,6 @@ lws_payload_until_length_exhausted(struct lws *wsi, unsigned char **buf,
        wsi->u.ws.rx_ubuf_head += avail;
        wsi->u.ws.rx_packet_length -= avail;
        *len -= avail;
+
+       return avail;
 }
index 35e6e6d2072c7e84c651fc10d63447a72747a55b..1a0792a0c76ee7dd9ccbf9230f4b387779999574 100644 (file)
@@ -1435,7 +1435,7 @@ lws_client_interpret_server_handshake(struct lws *wsi);
 LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_rx_sm(struct lws *wsi, unsigned char c);
 
-LWS_EXTERN void
+LWS_EXTERN int
 lws_payload_until_length_exhausted(struct lws *wsi, unsigned char **buf, size_t *len);
 
 LWS_EXTERN int LWS_WARN_UNUSED_RESULT
index df175dd615d2d534eca1a35ca2fa681ece1ad822..1ac3651521c1f56bad31a408f2ee77151476697a 100644 (file)
@@ -1853,8 +1853,11 @@ lws_interpret_incoming_packet(struct lws *wsi, unsigned char **buf, size_t len)
 
                /* consume payload bytes efficiently */
                if (wsi->lws_rx_parse_state ==
-                   LWS_RXPS_PAYLOAD_UNTIL_LENGTH_EXHAUSTED)
-                       lws_payload_until_length_exhausted(wsi, buf, &len);
+                   LWS_RXPS_PAYLOAD_UNTIL_LENGTH_EXHAUSTED) {
+                       m = lws_payload_until_length_exhausted(wsi, buf, &len);
+                       if (wsi->rxflow_buffer)
+                               wsi->rxflow_pos += m;
+               }
 
                /* process the byte */
                m = lws_rx_sm(wsi, *(*buf)++);