mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: change optional to result of io (#16075)
This commit is contained in:
@ -12,18 +12,18 @@ fn C.SUN_LEN(ptr &C.sockaddr_un) int
|
||||
fn C.strncpy(&char, &char, int)
|
||||
|
||||
// Shutdown shutsdown a socket and closes it
|
||||
fn shutdown(handle int) ? {
|
||||
fn shutdown(handle int) ! {
|
||||
$if windows {
|
||||
C.shutdown(handle, C.SD_BOTH)
|
||||
net.socket_error(C.closesocket(handle))?
|
||||
net.socket_error(C.closesocket(handle))!
|
||||
} $else {
|
||||
C.shutdown(handle, C.SHUT_RDWR)
|
||||
net.socket_error(C.close(handle))?
|
||||
net.socket_error(C.close(handle))!
|
||||
}
|
||||
}
|
||||
|
||||
// Select waits for an io operation (specified by parameter `test`) to be available
|
||||
fn @select(handle int, test Select, timeout time.Duration) ?bool {
|
||||
fn @select(handle int, test Select, timeout time.Duration) !bool {
|
||||
set := C.fd_set{}
|
||||
|
||||
C.FD_ZERO(&set)
|
||||
@ -47,13 +47,13 @@ fn @select(handle int, test Select, timeout time.Duration) ?bool {
|
||||
|
||||
match test {
|
||||
.read {
|
||||
net.socket_error(C.@select(handle + 1, &set, C.NULL, C.NULL, timeval_timeout))?
|
||||
net.socket_error(C.@select(handle + 1, &set, C.NULL, C.NULL, timeval_timeout))!
|
||||
}
|
||||
.write {
|
||||
net.socket_error(C.@select(handle + 1, C.NULL, &set, C.NULL, timeval_timeout))?
|
||||
net.socket_error(C.@select(handle + 1, C.NULL, &set, C.NULL, timeval_timeout))!
|
||||
}
|
||||
.except {
|
||||
net.socket_error(C.@select(handle + 1, C.NULL, C.NULL, &set, timeval_timeout))?
|
||||
net.socket_error(C.@select(handle + 1, C.NULL, C.NULL, &set, timeval_timeout))!
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,13 +61,13 @@ fn @select(handle int, test Select, timeout time.Duration) ?bool {
|
||||
}
|
||||
|
||||
// wait_for_common wraps the common wait code
|
||||
fn wait_for_common(handle int, deadline time.Time, timeout time.Duration, test Select) ? {
|
||||
fn wait_for_common(handle int, deadline time.Time, timeout time.Duration, test Select) ! {
|
||||
if deadline.unix == 0 {
|
||||
// do not accept negative timeout
|
||||
if timeout < 0 {
|
||||
return net.err_timed_out
|
||||
}
|
||||
ready := @select(handle, test, timeout)?
|
||||
ready := @select(handle, test, timeout)!
|
||||
if ready {
|
||||
return
|
||||
}
|
||||
@ -82,7 +82,7 @@ fn wait_for_common(handle int, deadline time.Time, timeout time.Duration, test S
|
||||
return net.err_timed_out
|
||||
}
|
||||
|
||||
ready := @select(handle, test, d_timeout)?
|
||||
ready := @select(handle, test, d_timeout)!
|
||||
if ready {
|
||||
return
|
||||
}
|
||||
@ -90,12 +90,12 @@ fn wait_for_common(handle int, deadline time.Time, timeout time.Duration, test S
|
||||
}
|
||||
|
||||
// wait_for_write waits for a write io operation to be available
|
||||
fn wait_for_write(handle int, deadline time.Time, timeout time.Duration) ? {
|
||||
fn wait_for_write(handle int, deadline time.Time, timeout time.Duration) ! {
|
||||
return wait_for_common(handle, deadline, timeout, .write)
|
||||
}
|
||||
|
||||
// wait_for_read waits for a read io operation to be available
|
||||
fn wait_for_read(handle int, deadline time.Time, timeout time.Duration) ? {
|
||||
fn wait_for_read(handle int, deadline time.Time, timeout time.Duration) ! {
|
||||
return wait_for_common(handle, deadline, timeout, .read)
|
||||
}
|
||||
|
||||
@ -120,9 +120,9 @@ const (
|
||||
)
|
||||
|
||||
[inline]
|
||||
fn wrap_read_result(result int) ?int {
|
||||
fn wrap_read_result(result int) !int {
|
||||
if result != 0 {
|
||||
return result
|
||||
}
|
||||
return none
|
||||
return error('none')
|
||||
}
|
||||
|
Reference in New Issue
Block a user