Skip to content

Commit

Permalink
net: websockets: Fix websocket close procedure
Browse files Browse the repository at this point in the history
The websocket implementation did not comply with the RFC 6455 when it
comes to connection close. The websocket should send in such case Close
control frame. This commit fixes this behaviour.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
  • Loading branch information
rlubos authored and mbolivar-nordic committed Feb 3, 2023
1 parent 7f02199 commit 432ff20
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions subsys/net/lib/websocket/websocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ static int websocket_interal_disconnect(struct websocket_context *ctx)

NET_DBG("[%p] Disconnecting", ctx);

ret = websocket_send_msg(ctx->sock, NULL, 0, WEBSOCKET_OPCODE_CLOSE,
true, true, SYS_FOREVER_MS);
if (ret < 0) {
NET_ERR("[%p] Failed to send close message (err %d).", ctx, ret);
}

ret = close(ctx->real_sock);

websocket_context_unref(ctx);
Expand Down

0 comments on commit 432ff20

Please sign in to comment.