x.websocket: use &byte instead of byteptr
parent
5bc29492fd
commit
4822274d29
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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')
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue