Skip to content

Commit d608318

Browse files
rluboskartben
authored andcommitted
net: websocket: Make use of any leftover data after HTTP processing
In case HTTP client read out more data from a socket that it processed it will indicate there is leftover data in the receive buffer available. Make use of it at the websocket level, so that no data is lost. As we reuse the same receive buffer in this case, it's only needed to update the count variable to indicate how many bytes are available. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
1 parent 4a85e47 commit d608318

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

subsys/net/lib/websocket/websocket.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,11 @@ int websocket_connect(int sock, struct websocket_request *wreq,
384384

385385
NET_DBG("[%p] WS connection to peer established (fd %d)", ctx, fd);
386386

387-
/* We will re-use the temp buffer in receive function if needed but
388-
* in order that to work the amount of data in buffer must be set to 0
387+
/* We will re-use the temp buffer in receive function. If there were
388+
* any leftover data from HTTP headers processing, we need to reflect
389+
* this in the count variable.
389390
*/
390-
ctx->recv_buf.count = 0;
391+
ctx->recv_buf.count = req.data_len;
391392

392393
/* Init parser FSM */
393394
ctx->parser_state = WEBSOCKET_PARSER_STATE_OPCODE;

0 commit comments

Comments
 (0)