Browse Source

Fix Timeval for darwin and linux

James Duran 2 years ago
parent
commit
fed0c2ea26
4 changed files with 11 additions and 11 deletions
  1. 4 4
      core/net/socket_darwin.odin
  2. 4 4
      core/net/socket_linux.odin
  3. 1 1
      core/os/os_darwin.odin
  4. 2 2
      core/os/os_linux.odin

+ 4 - 4
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
-}
+}

+ 4 - 4
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
-}
+}

+ 1 - 1
core/os/os_darwin.odin

@@ -355,7 +355,7 @@ in6_addr :: struct #packed {
 
 Timeval :: struct {
 	seconds: i64,
-	nanoseconds: int,
+	microseconds: int,
 }
 
 Linger :: struct {

+ 2 - 2
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
-}
+}