diff options
author | Daniel Stenberg <daniel@haxx.se> | 2023-03-28 17:44:59 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2023-03-29 10:23:29 +0200 |
commit | b19cbebbb46800faebf9690103cf85e408c4a2c6 (patch) | |
tree | 3bc57f8cfc85421813c858c1d2e0b43b139bda9e | |
parent | baeaeecb0a3e9399ac329c5464204b1f5d4453a1 (diff) | |
download | curl-b19cbebbb46800faebf9690103cf85e408c4a2c6.tar.gz |
ws: handle reads before EAGAIN better
Reported-by: simplerobot on github
Fixes #10831
Closes #10856
-rw-r--r-- | lib/ws.c | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -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) { |