picoev: add more logging of errors (#20558)

This commit is contained in:
Hitalo Souza 2024-02-25 16:35:13 -04:00 committed by GitHub
parent 0367f343b0
commit 9703029dbe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 69 additions and 26 deletions

View file

@ -67,11 +67,9 @@ fn setup_sock(fd int) ! {
}
@[inline]
fn req_read(fd int, b &u8, max_len int, idx int) int {
fn req_read(fd int, buffer &u8, max_len int, offset int) int {
// use `recv` instead of `read` for windows compatibility
unsafe {
return C.recv(fd, b + idx, max_len - idx, 0)
}
return unsafe { C.recv(fd, buffer + offset, max_len - offset, 0) }
}
fn fatal_socket_error(fd int) bool {
@ -102,7 +100,9 @@ fn fatal_socket_error(fd int) bool {
fn listen(config Config) !int {
// not using the `net` modules sockets, because not all socket options are defined
fd := C.socket(config.family, net.SocketType.tcp, 0)
assert fd != -1
if fd == -1 {
return error('Failed to create socket')
}
$if trace_fd ? {
eprintln('listen: ${fd}')