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

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

index 4feac10..f73918d 100644 (file)
@@ -1455,7 +1455,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)
 {
@@ -1480,7 +1480,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;
@@ -1510,4 +1510,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 c9da8fc..2d2e672 100644 (file)
@@ -1587,7 +1587,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 8765306..3dad2e2 100644 (file)
@@ -2062,8 +2062,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)++);