From 4822274d294ed866af0466db9c3eeebec7704dde Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 5 Apr 2021 19:53:48 +0300 Subject: [PATCH] x.websocket: use &byte instead of byteptr --- vlib/x/websocket/handshake.v | 2 +- vlib/x/websocket/io.v | 2 +- vlib/x/websocket/message.v | 2 +- vlib/x/websocket/websocket_client.v | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/vlib/x/websocket/handshake.v b/vlib/x/websocket/handshake.v index 55468829ee..172ae6a1eb 100644 --- a/vlib/x/websocket/handshake.v +++ b/vlib/x/websocket/handshake.v @@ -117,7 +117,7 @@ fn (mut ws Client) read_handshake_str() ?string { mut msg := [1024]byte{} mut buffer := [1]byte{} for total_bytes_read < 1024 { - bytes_read := ws.socket_read_ptr(byteptr(&buffer), 1) ? + bytes_read := ws.socket_read_ptr(&buffer[0], 1) ? if bytes_read == 0 { return error_with_code('unexpected no response from handshake', 5) } diff --git a/vlib/x/websocket/io.v b/vlib/x/websocket/io.v index c24f887fd4..4aeaee6cc2 100644 --- a/vlib/x/websocket/io.v +++ b/vlib/x/websocket/io.v @@ -28,7 +28,7 @@ fn (mut ws Client) socket_read(mut buffer []byte) ?int { } // socket_read reads from socket into the provided byte pointer and length -fn (mut ws Client) socket_read_ptr(buf_ptr byteptr, len int) ?int { +fn (mut ws Client) socket_read_ptr(buf_ptr &byte, len int) ?int { lock { if ws.state in [.closed, .closing] || ws.conn.sock.handle <= 1 { return error('socket_read_ptr: trying to read a closed socket') diff --git a/vlib/x/websocket/message.v b/vlib/x/websocket/message.v index ce530bd4c0..886fb1de8f 100644 --- a/vlib/x/websocket/message.v +++ b/vlib/x/websocket/message.v @@ -89,7 +89,7 @@ fn (mut ws Client) read_payload(frame &Frame) ?[]byte { mut read_buf := [1]byte{} mut bytes_read := 0 for bytes_read < frame.payload_len { - len := ws.socket_read_ptr(byteptr(&read_buf), 1) ? + len := ws.socket_read_ptr(&read_buf[0], 1) ? if len != 1 { return error('expected read all message, got zero') } diff --git a/vlib/x/websocket/websocket_client.v b/vlib/x/websocket/websocket_client.v index d0212cd53e..e082417bcd 100644 --- a/vlib/x/websocket/websocket_client.v +++ b/vlib/x/websocket/websocket_client.v @@ -229,7 +229,7 @@ pub fn (mut ws Client) pong() ? { } // write_ptr writes len bytes provided a byteptr with a websocket messagetype -pub fn (mut ws Client) write_ptr(bytes byteptr, payload_len int, code OPCode) ?int { +pub fn (mut ws Client) write_ptr(bytes &byte, payload_len int, code OPCode) ?int { // ws.debug_log('write_ptr code: $code') if ws.state != .open || ws.conn.sock.handle < 1 { // todo: send error here later @@ -286,7 +286,7 @@ pub fn (mut ws Client) write_ptr(bytes byteptr, payload_len int, code OPCode) ?i len := header.len + payload_len mut frame_buf := []byte{len: len} unsafe { - C.memcpy(&frame_buf[0], byteptr(header.data), header.len) + C.memcpy(&frame_buf[0], &byte(header.data), header.len) if payload_len > 0 { C.memcpy(&frame_buf[header.len], bytes, payload_len) } @@ -307,7 +307,7 @@ pub fn (mut ws Client) write_ptr(bytes byteptr, payload_len int, code OPCode) ?i // write writes a byte array with a websocket messagetype to socket pub fn (mut ws Client) write(bytes []byte, code OPCode) ?int { - return ws.write_ptr(byteptr(bytes.data), bytes.len, code) + return ws.write_ptr(&byte(bytes.data), bytes.len, code) } // write_string, writes a string with a websocket texttype to socket