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