From 6b40ead54db21d4067b457842af130a8fbd7c901 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 28 Sep 2021 09:20:49 +0300 Subject: [PATCH] fix `./v -cc g++ run examples/concurrency/concurrency_http.v` --- vlib/net/openssl/c.v | 1 + vlib/net/tcp.v | 86 ++++++++++++++++++++++---------------------- 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/vlib/net/openssl/c.v b/vlib/net/openssl/c.v index e744c3a616..f605ed0c78 100644 --- a/vlib/net/openssl/c.v +++ b/vlib/net/openssl/c.v @@ -23,6 +23,7 @@ module openssl #include #include +[typedef] pub struct C.SSL { } diff --git a/vlib/net/tcp.v b/vlib/net/tcp.v index 2d96194d78..c2a45a2643 100644 --- a/vlib/net/tcp.v +++ b/vlib/net/tcp.v @@ -48,6 +48,49 @@ pub fn (mut c TcpConn) close() ? { c.sock.close() ? } +pub fn (mut c TcpConn) read_ptr(buf_ptr &byte, len int) ?int { + mut res := wrap_read_result(C.recv(c.sock.handle, voidptr(buf_ptr), len, 0)) ? + $if trace_tcp ? { + eprintln('<<< TcpConn.read_ptr | c.sock.handle: $c.sock.handle | buf_ptr: ${ptr_str(buf_ptr)} len: $len | res: $res') + } + if res > 0 { + $if trace_tcp_data_read ? { + eprintln('<<< TcpConn.read_ptr | 1 data.len: ${res:6} | data: ' + + unsafe { buf_ptr.vstring_with_len(res) }) + } + return res + } + code := error_code() + if code == int(error_ewouldblock) { + c.wait_for_read() ? + res = wrap_read_result(C.recv(c.sock.handle, voidptr(buf_ptr), len, 0)) ? + $if trace_tcp ? { + eprintln('<<< TcpConn.read_ptr | c.sock.handle: $c.sock.handle | buf_ptr: ${ptr_str(buf_ptr)} len: $len | res: $res') + } + $if trace_tcp_data_read ? { + if res > 0 { + eprintln('<<< TcpConn.read_ptr | 2 data.len: ${res:6} | data: ' + + unsafe { buf_ptr.vstring_with_len(res) }) + } + } + return socket_error(res) + } else { + wrap_error(code) ? + } + return none +} + +pub fn (mut c TcpConn) read(mut buf []byte) ?int { + return c.read_ptr(buf.data, buf.len) +} + +pub fn (mut c TcpConn) read_deadline() ?time.Time { + if c.read_deadline.unix == 0 { + return c.read_deadline + } + return none +} + // write_ptr blocks and attempts to write all data pub fn (mut c TcpConn) write_ptr(b &byte, len int) ?int { $if trace_tcp ? { @@ -94,49 +137,6 @@ pub fn (mut c TcpConn) write_string(s string) ?int { return c.write_ptr(s.str, s.len) } -pub fn (mut c TcpConn) read_ptr(buf_ptr &byte, len int) ?int { - mut res := wrap_read_result(C.recv(c.sock.handle, voidptr(buf_ptr), len, 0)) ? - $if trace_tcp ? { - eprintln('<<< TcpConn.read_ptr | c.sock.handle: $c.sock.handle | buf_ptr: ${ptr_str(buf_ptr)} len: $len | res: $res') - } - if res > 0 { - $if trace_tcp_data_read ? { - eprintln('<<< TcpConn.read_ptr | 1 data.len: ${res:6} | data: ' + - unsafe { buf_ptr.vstring_with_len(res) }) - } - return res - } - code := error_code() - if code == int(error_ewouldblock) { - c.wait_for_read() ? - res = wrap_read_result(C.recv(c.sock.handle, voidptr(buf_ptr), len, 0)) ? - $if trace_tcp ? { - eprintln('<<< TcpConn.read_ptr | c.sock.handle: $c.sock.handle | buf_ptr: ${ptr_str(buf_ptr)} len: $len | res: $res') - } - $if trace_tcp_data_read ? { - if res > 0 { - eprintln('<<< TcpConn.read_ptr | 2 data.len: ${res:6} | data: ' + - unsafe { buf_ptr.vstring_with_len(res) }) - } - } - return socket_error(res) - } else { - wrap_error(code) ? - } - return none -} - -pub fn (mut c TcpConn) read(mut buf []byte) ?int { - return c.read_ptr(buf.data, buf.len) -} - -pub fn (mut c TcpConn) read_deadline() ?time.Time { - if c.read_deadline.unix == 0 { - return c.read_deadline - } - return none -} - pub fn (mut c TcpConn) set_read_deadline(deadline time.Time) { c.read_deadline = deadline }