]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ws: handle reads before EAGAIN better
authorDaniel Stenberg <daniel@haxx.se>
Tue, 28 Mar 2023 15:44:59 +0000 (17:44 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 29 Mar 2023 08:23:29 +0000 (10:23 +0200)
Reported-by: simplerobot on github
Fixes #10831
Closes #10856

lib/ws.c

index e8495dcfc016a7c3d76b861461e10ba99585ac21..dc1fa57517256f3a1395746ab50f0796d138fe23 100644 (file)
--- a/lib/ws.c
+++ b/lib/ws.c
@@ -425,11 +425,11 @@ CURL_EXTERN CURLcode curl_ws_recv(struct Curl_easy *data, void *buffer,
     size_t datalen;
     unsigned int recvflags;
 
-    if(!wsp->stillblen) {
+    if(!wsp->stillblen || (result == CURLE_AGAIN)) {
       /* try to get more data */
       size_t n;
-      result = curl_easy_recv(data, data->state.buffer,
-                              data->set.buffer_size, &n);
+      result = curl_easy_recv(data, &data->state.buffer[wsp->stillblen],
+                              data->set.buffer_size - wsp->stillblen, &n);
       if(result)
         return result;
       if(!n) {
@@ -438,10 +438,10 @@ CURL_EXTERN CURLcode curl_ws_recv(struct Curl_easy *data, void *buffer,
         return CURLE_GOT_NOTHING;
       }
       wsp->stillb = data->state.buffer;
-      wsp->stillblen = n;
+      wsp->stillblen += n;
     }
 
-    infof(data, "WS: %u bytes left to decode", (int)wsp->stillblen);
+    infof(data, "WS: %zu bytes left to decode", wsp->stillblen);
     if(!wsp->frame.bytesleft) {
       size_t headlen;
       curl_off_t oleft;
@@ -449,8 +449,8 @@ CURL_EXTERN CURLcode curl_ws_recv(struct Curl_easy *data, void *buffer,
       result = ws_decode(data, (unsigned char *)wsp->stillb, wsp->stillblen,
                          &headlen, &datalen, &oleft, &recvflags);
       if(result == CURLE_AGAIN)
-        /* a packet fragment only */
-        break;
+        /* a packet fragment only, loop and try reading more */
+        continue;
       else if(result)
         return result;
       if(datalen > buflen) {