mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
net: support -d trace_tcp_data_read
and -d trace_tcp_data_write
too
This commit is contained in:
parent
9b14f71631
commit
669a4ea1be
@ -42,6 +42,9 @@ pub fn (mut c TcpConn) write_ptr(b &byte, len int) ?int {
|
||||
'>>> TcpConn.write_ptr | c.sock.handle: $c.sock.handle | b: ${ptr_str(b)} len: $len |\n' +
|
||||
unsafe { b.vstring_with_len(len) })
|
||||
}
|
||||
$if trace_tcp_data_write ? {
|
||||
eprintln('>>> TcpConn.write_ptr | data.len: ${len:6} | data: ' + b.vstring_with_len(len))
|
||||
}
|
||||
unsafe {
|
||||
mut ptr_base := &byte(b)
|
||||
mut total_sent := 0
|
||||
@ -49,6 +52,9 @@ pub fn (mut c TcpConn) write_ptr(b &byte, len int) ?int {
|
||||
ptr := ptr_base + total_sent
|
||||
remaining := len - total_sent
|
||||
mut sent := C.send(c.sock.handle, ptr, remaining, msg_nosignal)
|
||||
$if trace_tcp_data_write ? {
|
||||
eprintln('>>> TcpConn.write_ptr | data chunk, total_sent: ${total_sent:6}, remaining: ${remaining:6}, sent: ${sent:6}, ptr: ${ptr_str(ptr)}')
|
||||
}
|
||||
if sent < 0 {
|
||||
code := error_code()
|
||||
if code == int(error_ewouldblock) {
|
||||
@ -86,6 +92,10 @@ pub fn (mut c TcpConn) read_ptr(buf_ptr &byte, len int) ?int {
|
||||
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: ' +
|
||||
buf_ptr.vstring_with_len(res))
|
||||
}
|
||||
return res
|
||||
}
|
||||
code := error_code()
|
||||
@ -95,6 +105,12 @@ pub fn (mut c TcpConn) read_ptr(buf_ptr &byte, len int) ?int {
|
||||
$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: ' +
|
||||
buf_ptr.vstring_with_len(res))
|
||||
}
|
||||
}
|
||||
return socket_error(res)
|
||||
} else {
|
||||
wrap_error(code) ?
|
||||
@ -224,6 +240,9 @@ pub fn (mut l TcpListener) accept() ?&TcpConn {
|
||||
}
|
||||
}
|
||||
new_sock := tcp_socket_from_handle(new_handle) ?
|
||||
$if trace_tcp ? {
|
||||
eprintln(' TcpListener.accept | << new_sock: $new_sock')
|
||||
}
|
||||
return &TcpConn{
|
||||
sock: new_sock
|
||||
read_timeout: net.tcp_default_read_timeout
|
||||
|
Loading…
Reference in New Issue
Block a user