net, net.http: fix C.FD_ISSET declaration (#19594)

This commit is contained in:
shove 2023-10-19 16:29:13 +08:00 committed by GitHub
parent 092358fd24
commit 07390ef4c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 10 additions and 15 deletions

View file

@ -109,7 +109,7 @@ fn C.FD_ZERO(fdset &C.fd_set)
fn C.FD_SET(fd int, fdset &C.fd_set) fn C.FD_SET(fd int, fdset &C.fd_set)
fn C.FD_ISSET(fd int, fdset &C.fd_set) bool fn C.FD_ISSET(fd int, fdset &C.fd_set) int
fn C.inet_pton(family AddrFamily, saddr &char, addr voidptr) int fn C.inet_pton(family AddrFamily, saddr &char, addr voidptr) int

View file

@ -85,7 +85,7 @@ fn @select(handle int, test Select, timeout time.Duration) !bool {
} }
} }
return C.FD_ISSET(handle, &set) return C.FD_ISSET(handle, &set) != 0
} }
[inline] [inline]
@ -108,7 +108,7 @@ fn select_deadline(handle int, test Select, deadline time.Time) !bool {
} }
// Deadline elapsed // Deadline elapsed
return false return err_timed_out
} }
// wait_for_common wraps the common wait code // wait_for_common wraps the common wait code

View file

@ -193,6 +193,7 @@ fn (req &Request) read_all_from_client_connection(r &net.TcpConn) ![]u8 {
mut read := i64(0) mut read := i64(0)
mut b := []u8{len: 32768} mut b := []u8{len: 32768}
for { for {
r.wait_for_read()!
old_read := read old_read := read
new_read := r.read(mut b[read..]) or { break } new_read := r.read(mut b[read..]) or { break }
read += new_read read += new_read

View file

@ -580,5 +580,5 @@ fn @select(handle int, test Select, timeout time.Duration) !bool {
$if trace_ssl ? { $if trace_ssl ? {
eprintln('${@METHOD} ---> res: ${res}') eprintln('${@METHOD} ---> res: ${res}')
} }
return res return res != 0
} }

View file

@ -460,5 +460,5 @@ fn @select(handle int, test Select, timeout time.Duration) !bool {
$if trace_ssl ? { $if trace_ssl ? {
eprintln('${@METHOD} ---> res: ${res}') eprintln('${@METHOD} ---> res: ${res}')
} }
return res return res != 0
} }

View file

@ -1,7 +1,6 @@
module net module net
import time import time
import io
import strings import strings
pub const ( pub const (
@ -147,12 +146,7 @@ pub fn (c TcpConn) read_ptr(buf_ptr &u8, len int) !int {
} }
pub fn (c TcpConn) read(mut buf []u8) !int { pub fn (c TcpConn) read(mut buf []u8) !int {
return c.read_ptr(buf.data, buf.len) or { return c.read_ptr(buf.data, buf.len)!
return io.NotExpected{
cause: 'unexpected error in `read_ptr` function'
code: -1
}
}
} }
pub fn (mut c TcpConn) read_deadline() !time.Time { pub fn (mut c TcpConn) read_deadline() !time.Time {

View file

@ -57,7 +57,7 @@ fn @select(handle int, test Select, timeout time.Duration) !bool {
} }
} }
return C.FD_ISSET(handle, &set) return C.FD_ISSET(handle, &set) != 0
} }
// wait_for_common wraps the common wait code // wait_for_common wraps the common wait code

View file

@ -74,9 +74,9 @@ fn (mut pv Picoev) poll_once(max_wait int) int {
if target.loop_id == pv.loop.id { if target.loop_id == pv.loop.id {
// vfmt off // vfmt off
read_events := ( read_events := (
(if C.FD_ISSET(target.fd, &readfds) { picoev_read } else { 0 }) (if C.FD_ISSET(target.fd, &readfds) != 0 { picoev_read } else { 0 })
| |
(if C.FD_ISSET(target.fd, &writefds) { picoev_write } else { 0 }) (if C.FD_ISSET(target.fd, &writefds) != 0 { picoev_write } else { 0 })
) )
// vfmt on // vfmt on
if read_events != 0 { if read_events != 0 {