net: websockets: Fix websocket close procedure

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>
This commit is contained in:
Robert Lubos 2023-01-26 16:07:46 +01:00 committed by Marti Bolivar
parent 7f0219985d
commit 432ff20a72
1 changed files with 6 additions and 0 deletions

View File

@ -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);