From bd67b647f28d66486789d4e756a95c89df32a909 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Mon, 28 Dec 2020 01:06:57 +0100 Subject: [PATCH] websocket: vfmt --- cmd/tools/vtest-cleancode.v | 2 ++ vlib/x/websocket/websocket_client.v | 12 ++++++------ vlib/x/websocket/websocket_server.v | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/tools/vtest-cleancode.v b/cmd/tools/vtest-cleancode.v index 52937ac5bc..89238eda4d 100644 --- a/cmd/tools/vtest-cleancode.v +++ b/cmd/tools/vtest-cleancode.v @@ -69,6 +69,8 @@ const ( 'vlib/strings/', 'vlib/time/', 'vlib/vweb/', + 'vlib/x/websocket/websocket_server.v', + 'vlib/x/websocket/websocket_client.v', ] ) diff --git a/vlib/x/websocket/websocket_client.v b/vlib/x/websocket/websocket_client.v index 1ba7705531..348faffe0e 100644 --- a/vlib/x/websocket/websocket_client.v +++ b/vlib/x/websocket/websocket_client.v @@ -1,5 +1,5 @@ // websocket module implements websocket client and a websocket server -// attribution: @thecoderr the author of original websocket client +// attribution: @thecoderr the author of original websocket client module websocket import net @@ -123,7 +123,7 @@ pub fn (mut ws Client) listen() ? { if ws.state in [.closed, .closing] { return } - ws.debug_log('got message: $msg.opcode') + ws.debug_log('got message: $msg.opcode') match msg.opcode { .text_frame { ws.debug_log('read: text') @@ -245,7 +245,7 @@ pub fn (mut ws Client) write_ptr(bytes byteptr, payload_len int, code OPCode) ? unsafe {C.memcpy(&header[2], &len16, 2)} } else if payload_len > 0xffff && payload_len <= 0xffffffffffffffff { len_bytes := htonl64(u64(payload_len)) - header[1] = 127 + header[1] = 127 unsafe {C.memcpy(&header[2], len_bytes.data, 8)} } } else { @@ -263,7 +263,7 @@ pub fn (mut ws Client) write_ptr(bytes byteptr, payload_len int, code OPCode) ? header[5] = masking_key[1] header[6] = masking_key[2] header[7] = masking_key[3] - } else if payload_len > 0xffff && payload_len <= 0xffffffffffffffff { + } else if payload_len > 0xffff && payload_len <= 0xffffffffffffffff { len64 := htonl64(u64(payload_len)) header[1] = (127 | 0x80) unsafe {C.memcpy(&header[2], len64.data, 8)} @@ -344,13 +344,13 @@ pub fn (mut ws Client) close(code int, message string) ? { // send_control_frame sends a control frame to the server fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []byte) ? { - ws.debug_log('send control frame $code, frame_type: $frame_typ') + ws.debug_log('send control frame $code, frame_type: $frame_typ') if ws.state !in [.open, .closing] && ws.conn.sock.handle > 1 { return error('socket is not connected') } header_len := if ws.is_server { 2 } else { 6 } frame_len := header_len + payload.len - mut control_frame := []byte{len: frame_len} + mut control_frame := []byte{len: frame_len} mut masking_key := if !ws.is_server { create_masking_key() } else { empty_bytearr } defer { unsafe { diff --git a/vlib/x/websocket/websocket_server.v b/vlib/x/websocket/websocket_server.v index 7680c9d878..406eeb627f 100644 --- a/vlib/x/websocket/websocket_server.v +++ b/vlib/x/websocket/websocket_server.v @@ -30,8 +30,8 @@ pub: resource_name string // resource that the client access client_key string // unique key of client pub mut: - server &Server - client &Client + server &Server + client &Client } // new_server instance a new websocket server on provided port and route