1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

time: use Duration(C.INT64_MAX) as infinite (#10539)

This commit is contained in:
Uwe Krüger
2021-06-22 11:17:44 +02:00
committed by GitHub
parent dd6591b2f5
commit 72358833e0
10 changed files with 49 additions and 24 deletions

View File

@@ -14,7 +14,7 @@ pub const no_timeout = time.Duration(0)
// infinite_timeout should be given to functions when an infinite_timeout is wanted (i.e. functions
// only ever return with data)
pub const infinite_timeout = time.Duration(-1)
pub const infinite_timeout = time.infinite
// Shutdown shutsdown a socket and closes it
fn shutdown(handle int) ? {
@@ -34,7 +34,7 @@ fn @select(handle int, test Select, timeout time.Duration) ?bool {
C.FD_ZERO(&set)
C.FD_SET(handle, &set)
seconds := timeout.milliseconds() / 1000
seconds := timeout / time.second
microseconds := time.Duration(timeout - (seconds * time.second)).microseconds()
mut tt := C.timeval{
@@ -93,9 +93,8 @@ fn select_with_retry(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) ? {
if deadline.unix == 0 {
// only accept infinite_timeout as a valid
// negative timeout - it is handled in @select however
if timeout < 0 && timeout != net.infinite_timeout {
// do not accept negative timeout
if timeout < 0 {
return err_timed_out
}
ready := select_with_retry(handle, test, timeout) ?

View File

@@ -29,8 +29,8 @@ fn @select(handle int, test Select, timeout time.Duration) ?bool {
C.FD_ZERO(&set)
C.FD_SET(handle, &set)
seconds := timeout.milliseconds() / 1000
microseconds := timeout - (seconds * time.second)
seconds := timeout / time.second
microseconds := time.Duration(timeout - (seconds * time.second)).microseconds()
mut tt := C.timeval{
tv_sec: u64(seconds)
@@ -63,9 +63,8 @@ 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) ? {
if deadline.unix == 0 {
// only accept infinite_timeout as a valid
// negative timeout - it is handled in @select however
if timeout < 0 && timeout != unix.infinite_timeout {
// do not accept negative timeout
if timeout < 0 {
return net.err_timed_out
}
ready := @select(handle, test, timeout) ?
@@ -117,7 +116,7 @@ const (
// infinite_timeout should be given to functions when an infinite_timeout is wanted (i.e. functions
// only ever return with data)
const (
infinite_timeout = time.Duration(-1)
infinite_timeout = time.infinite
)
[inline]