net: do `$if trace_tcp ? {` in more functions to help debug web server issues

pull/9855/head
Delyan Angelov 2021-04-23 14:37:05 +03:00
parent 7ec90b0f89
commit cf497623dc
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 21 additions and 0 deletions

View File

@ -28,6 +28,9 @@ pub fn dial_tcp(address string) ?&TcpConn {
} }
pub fn (mut c TcpConn) close() ? { pub fn (mut c TcpConn) close() ? {
$if trace_tcp ? {
eprintln(' TcpConn.close | c.sock.handle: $c.sock.handle')
}
c.sock.close() ? c.sock.close() ?
return none return none
} }
@ -204,6 +207,9 @@ pub fn listen_tcp(port int) ?&TcpListener {
} }
pub fn (mut l TcpListener) accept() ?&TcpConn { pub fn (mut l TcpListener) accept() ?&TcpConn {
$if trace_tcp ? {
eprintln(' TcpListener.accept | l.sock.handle: $l.sock.handle')
}
addr := C.sockaddr_storage{} addr := C.sockaddr_storage{}
unsafe { C.memset(&addr, 0, sizeof(C.sockaddr_storage)) } unsafe { C.memset(&addr, 0, sizeof(C.sockaddr_storage)) }
size := sizeof(C.sockaddr_storage) size := sizeof(C.sockaddr_storage)
@ -249,6 +255,9 @@ pub fn (mut c TcpListener) wait_for_accept() ? {
} }
pub fn (mut c TcpListener) close() ? { pub fn (mut c TcpListener) close() ? {
$if trace_tcp ? {
eprintln(' TcpListener.close | c.sock.handle: $c.sock.handle')
}
c.sock.close() ? c.sock.close() ?
return none return none
} }
@ -275,6 +284,9 @@ fn new_tcp_socket() ?TcpSocket {
} $else { } $else {
socket_error(C.fcntl(sockfd, C.F_SETFL, C.fcntl(sockfd, C.F_GETFL) | C.O_NONBLOCK)) ? socket_error(C.fcntl(sockfd, C.F_SETFL, C.fcntl(sockfd, C.F_GETFL) | C.O_NONBLOCK)) ?
} }
$if trace_tcp ? {
eprintln(' new_tcp_socket | s.handle: $s.handle')
}
return s return s
} }
@ -290,6 +302,9 @@ fn tcp_socket_from_handle(sockfd int) ?TcpSocket {
} $else { } $else {
socket_error(C.fcntl(sockfd, C.F_SETFL, C.fcntl(sockfd, C.F_GETFL) | C.O_NONBLOCK)) ? socket_error(C.fcntl(sockfd, C.F_SETFL, C.fcntl(sockfd, C.F_GETFL) | C.O_NONBLOCK)) ?
} }
$if trace_tcp ? {
eprintln(' tcp_socket_from_handle | s.handle: $s.handle')
}
return s return s
} }
@ -312,6 +327,9 @@ pub fn (mut s TcpSocket) set_option_int(opt SocketOption, value int) ? {
} }
fn (mut s TcpSocket) close() ? { fn (mut s TcpSocket) close() ? {
$if trace_tcp ? {
eprintln(' TcpSocket.close | s.handle: $s.handle')
}
return shutdown(s.handle) return shutdown(s.handle)
} }
@ -324,6 +342,9 @@ const (
) )
fn (mut s TcpSocket) connect(a string) ? { fn (mut s TcpSocket) connect(a string) ? {
$if trace_tcp ? {
eprintln(' TcpSocket.connect | s.handle: $s.handle | a: $a')
}
addr := resolve_addr(a, .inet, .tcp) ? addr := resolve_addr(a, .inet, .tcp) ?
res := C.connect(s.handle, &addr.addr, addr.len) res := C.connect(s.handle, &addr.addr, addr.len)
if res == 0 { if res == 0 {