mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 09:54:49 +00:00
Change type of Timeval.tv_sec to posix.Time (#7646)
This commit is contained in:
committed by
Andreas Rumpf
parent
b9cafe5752
commit
fdf1d12380
@@ -27,6 +27,7 @@
|
||||
- ``proc `-`*(a, b: Time): int64`` in the ``times`` module has changed return type
|
||||
to ``times.Duration`` in order to support higher time resolutions.
|
||||
The proc is no longer deprecated.
|
||||
- ``posix.Timeval.tv_sec`` has changed type to ``posix.Time``.
|
||||
|
||||
#### Breaking changes in the compiler
|
||||
|
||||
|
||||
@@ -101,8 +101,8 @@ when defined(windows):
|
||||
from winlean import TimeVal, SocketHandle, FD_SET, FD_ZERO, TFdSet,
|
||||
FD_ISSET, select
|
||||
else:
|
||||
from posix import TimeVal, SocketHandle, FD_SET, FD_ZERO, TFdSet,
|
||||
FD_ISSET, select
|
||||
from posix import TimeVal, Time, Suseconds, SocketHandle, FD_SET, FD_ZERO,
|
||||
TFdSet, FD_ISSET, select
|
||||
|
||||
type
|
||||
DelegateObj* = object
|
||||
@@ -556,8 +556,12 @@ proc send*(sock: AsyncSocket, data: string) =
|
||||
proc timeValFromMilliseconds(timeout = 500): Timeval =
|
||||
if timeout != -1:
|
||||
var seconds = timeout div 1000
|
||||
result.tv_sec = seconds.int32
|
||||
result.tv_usec = ((timeout - seconds * 1000) * 1000).int32
|
||||
when defined(posix):
|
||||
result.tv_sec = seconds.Time
|
||||
result.tv_usec = ((timeout - seconds * 1000) * 1000).Suseconds
|
||||
else:
|
||||
result.tv_sec = seconds.int32
|
||||
result.tv_usec = ((timeout - seconds * 1000) * 1000).int32
|
||||
|
||||
proc createFdSet(fd: var TFdSet, s: seq[Delegate], m: var int) =
|
||||
FD_ZERO(fd)
|
||||
|
||||
@@ -953,8 +953,12 @@ when defined(ssl):
|
||||
proc timeValFromMilliseconds(timeout = 500): Timeval =
|
||||
if timeout != -1:
|
||||
var seconds = timeout div 1000
|
||||
result.tv_sec = seconds.int32
|
||||
result.tv_usec = ((timeout - seconds * 1000) * 1000).int32
|
||||
when defined(posix):
|
||||
result.tv_sec = seconds.Time
|
||||
result.tv_usec = ((timeout - seconds * 1000) * 1000).Suseconds
|
||||
else:
|
||||
result.tv_sec = seconds.int32
|
||||
result.tv_usec = ((timeout - seconds * 1000) * 1000).int32
|
||||
|
||||
proc createFdSet(fd: var TFdSet, s: seq[Socket], m: var int) =
|
||||
FD_ZERO(fd)
|
||||
|
||||
@@ -351,8 +351,8 @@ type
|
||||
|
||||
Timeval* {.importc: "struct timeval", header: "<sys/select.h>",
|
||||
final, pure.} = object ## struct timeval
|
||||
tv_sec*: clong ## Seconds.
|
||||
tv_usec*: clong ## Microseconds.
|
||||
tv_sec*: Time ## Seconds.
|
||||
tv_usec*: Suseconds ## Microseconds.
|
||||
TFdSet* {.importc: "fd_set", header: "<sys/select.h>",
|
||||
final, pure.} = object
|
||||
abi: array[1024 div (8 * sizeof(clong)), clong]
|
||||
|
||||
@@ -335,8 +335,8 @@ type
|
||||
|
||||
Timeval* {.importc: "struct timeval", header: "<sys/select.h>",
|
||||
final, pure.} = object ## struct timeval
|
||||
tv_sec*: int ## Seconds.
|
||||
tv_usec*: int ## Microseconds.
|
||||
tv_sec*: Time ## Seconds.
|
||||
tv_usec*: Suseconds ## Microseconds.
|
||||
TFdSet* {.importc: "fd_set", header: "<sys/select.h>",
|
||||
final, pure.} = object
|
||||
Mcontext* {.importc: "mcontext_t", header: "<ucontext.h>",
|
||||
|
||||
@@ -616,8 +616,12 @@ proc setBlocking*(s: SocketHandle, blocking: bool) =
|
||||
proc timeValFromMilliseconds(timeout = 500): Timeval =
|
||||
if timeout != -1:
|
||||
var seconds = timeout div 1000
|
||||
result.tv_sec = seconds.int32
|
||||
result.tv_usec = ((timeout - seconds * 1000) * 1000).int32
|
||||
when useWinVersion:
|
||||
result.tv_sec = seconds.int32
|
||||
result.tv_usec = ((timeout - seconds * 1000) * 1000).int32
|
||||
else:
|
||||
result.tv_sec = seconds.Time
|
||||
result.tv_usec = ((timeout - seconds * 1000) * 1000).Suseconds
|
||||
|
||||
proc createFdSet(fd: var TFdSet, s: seq[SocketHandle], m: var int) =
|
||||
FD_ZERO(fd)
|
||||
|
||||
@@ -1660,7 +1660,7 @@ proc setLastModificationTime*(file: string, t: times.Time) =
|
||||
## Sets the `file`'s last modification time. `OSError` is raised in case of
|
||||
## an error.
|
||||
when defined(posix):
|
||||
let unixt = t.toUnix.int
|
||||
let unixt = posix.Time(t.toUnix)
|
||||
var timevals = [Timeval(tv_sec: unixt), Timeval(tv_sec: unixt)] # [last access, last modification]
|
||||
if utimes(file, timevals.addr) != 0: raiseOSError(osLastError())
|
||||
else:
|
||||
|
||||
@@ -1289,7 +1289,7 @@ elif not defined(useNimRtl):
|
||||
|
||||
proc select(readfds: var seq[Process], timeout = 500): int =
|
||||
var tv: Timeval
|
||||
tv.tv_sec = 0
|
||||
tv.tv_sec = posix.Time(0)
|
||||
tv.tv_usec = timeout * 1000
|
||||
|
||||
var rd: TFdSet
|
||||
|
||||
@@ -1752,7 +1752,7 @@ when not defined(JS):
|
||||
when defined(posix):
|
||||
var a: Timeval
|
||||
gettimeofday(a)
|
||||
result = toFloat(a.tv_sec) + toFloat(a.tv_usec)*0.00_0001
|
||||
result = toBiggestFloat(a.tv_sec.int64) + toFloat(a.tv_usec)*0.00_0001
|
||||
elif defined(windows):
|
||||
var f: winlean.FILETIME
|
||||
getSystemTimeAsFileTime(f)
|
||||
|
||||
Reference in New Issue
Block a user