From fed0c2ea26665d183818b07a884d3b48c1a60e36 Mon Sep 17 00:00:00 2001 From: James Duran Date: Wed, 7 Jun 2023 21:55:08 -0700 Subject: [PATCH] Fix Timeval for darwin and linux --- core/net/socket_darwin.odin | 8 ++++---- core/net/socket_linux.odin | 8 ++++---- core/os/os_darwin.odin | 2 +- core/os/os_linux.odin | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/net/socket_darwin.odin b/core/net/socket_darwin.odin index f00be9915..081892afd 100644 --- a/core/net/socket_darwin.odin +++ b/core/net/socket_darwin.odin @@ -268,9 +268,9 @@ _set_option :: proc(s: Any_Socket, option: Socket_Option, value: any, loc := #ca t, ok := value.(time.Duration) if !ok do panic("set_option() value must be a time.Duration here", loc) - nanos := time.duration_nanoseconds(t) - timeval_value.nanoseconds = int(nanos % 1e9) - timeval_value.seconds = (nanos - i64(timeval_value.nanoseconds)) / 1e9 + micros := i64(time.duration_microseconds(t)) + timeval_value.microseconds = int(micros % 1e6) + timeval_value.seconds = (micros - i64(timeval_value.microseconds)) / 1e6 ptr = &timeval_value len = size_of(timeval_value) @@ -368,4 +368,4 @@ _sockaddr_to_endpoint :: proc(native_addr: ^os.SOCKADDR_STORAGE_LH) -> (ep: Endp panic("native_addr is neither IP4 or IP6 address") } return -} \ No newline at end of file +} diff --git a/core/net/socket_linux.odin b/core/net/socket_linux.odin index 690e09ab7..b7141e8ba 100644 --- a/core/net/socket_linux.odin +++ b/core/net/socket_linux.odin @@ -283,9 +283,9 @@ _set_option :: proc(s: Any_Socket, option: Socket_Option, value: any, loc := #ca t, ok := value.(time.Duration) if !ok do panic("set_option() value must be a time.Duration here", loc) - nanos := time.duration_nanoseconds(t) - timeval_value.nanoseconds = int(nanos % 1e9) - timeval_value.seconds = (nanos - i64(timeval_value.nanoseconds)) / 1e9 + micros := i64(time.duration_microseconds(t)) + timeval_value.microseconds = int(micros % 1e6) + timeval_value.seconds = (micros - i64(timeval_value.microseconds)) / 1e6 ptr = &timeval_value len = size_of(timeval_value) @@ -404,4 +404,4 @@ _sockaddr_basic_to_endpoint :: proc(native_addr: ^os.SOCKADDR) -> (ep: Endpoint) panic("native_addr is neither IP4 or IP6 address") } return -} \ No newline at end of file +} diff --git a/core/os/os_darwin.odin b/core/os/os_darwin.odin index a2d68aeed..adb438f60 100644 --- a/core/os/os_darwin.odin +++ b/core/os/os_darwin.odin @@ -355,7 +355,7 @@ in6_addr :: struct #packed { Timeval :: struct { seconds: i64, - nanoseconds: int, + microseconds: int, } Linger :: struct { diff --git a/core/os/os_linux.odin b/core/os/os_linux.odin index 3dc48087a..7a0a4b1dd 100644 --- a/core/os/os_linux.odin +++ b/core/os/os_linux.odin @@ -241,7 +241,7 @@ socklen_t :: c.int Timeval :: struct { seconds: i64, - nanoseconds: int, + microseconds: int, } // "Argv" arguments converted to Odin strings @@ -1086,4 +1086,4 @@ fcntl :: proc(fd: int, cmd: int, arg: int) -> (int, Errno) { return 0, _get_errno(result) } return result, ERROR_NONE -} \ No newline at end of file +}