Change type of Timeval.tv_sec to posix.Time (#7646)
This commit is contained in:
parent
b9cafe5752
commit
fdf1d12380
9 changed files with 28 additions and 15 deletions
|
|
@ -27,6 +27,7 @@
|
||||||
- ``proc `-`*(a, b: Time): int64`` in the ``times`` module has changed return type
|
- ``proc `-`*(a, b: Time): int64`` in the ``times`` module has changed return type
|
||||||
to ``times.Duration`` in order to support higher time resolutions.
|
to ``times.Duration`` in order to support higher time resolutions.
|
||||||
The proc is no longer deprecated.
|
The proc is no longer deprecated.
|
||||||
|
- ``posix.Timeval.tv_sec`` has changed type to ``posix.Time``.
|
||||||
|
|
||||||
#### Breaking changes in the compiler
|
#### Breaking changes in the compiler
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,8 +101,8 @@ when defined(windows):
|
||||||
from winlean import TimeVal, SocketHandle, FD_SET, FD_ZERO, TFdSet,
|
from winlean import TimeVal, SocketHandle, FD_SET, FD_ZERO, TFdSet,
|
||||||
FD_ISSET, select
|
FD_ISSET, select
|
||||||
else:
|
else:
|
||||||
from posix import TimeVal, SocketHandle, FD_SET, FD_ZERO, TFdSet,
|
from posix import TimeVal, Time, Suseconds, SocketHandle, FD_SET, FD_ZERO,
|
||||||
FD_ISSET, select
|
TFdSet, FD_ISSET, select
|
||||||
|
|
||||||
type
|
type
|
||||||
DelegateObj* = object
|
DelegateObj* = object
|
||||||
|
|
@ -556,6 +556,10 @@ proc send*(sock: AsyncSocket, data: string) =
|
||||||
proc timeValFromMilliseconds(timeout = 500): Timeval =
|
proc timeValFromMilliseconds(timeout = 500): Timeval =
|
||||||
if timeout != -1:
|
if timeout != -1:
|
||||||
var seconds = timeout div 1000
|
var seconds = timeout div 1000
|
||||||
|
when defined(posix):
|
||||||
|
result.tv_sec = seconds.Time
|
||||||
|
result.tv_usec = ((timeout - seconds * 1000) * 1000).Suseconds
|
||||||
|
else:
|
||||||
result.tv_sec = seconds.int32
|
result.tv_sec = seconds.int32
|
||||||
result.tv_usec = ((timeout - seconds * 1000) * 1000).int32
|
result.tv_usec = ((timeout - seconds * 1000) * 1000).int32
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -953,6 +953,10 @@ when defined(ssl):
|
||||||
proc timeValFromMilliseconds(timeout = 500): Timeval =
|
proc timeValFromMilliseconds(timeout = 500): Timeval =
|
||||||
if timeout != -1:
|
if timeout != -1:
|
||||||
var seconds = timeout div 1000
|
var seconds = timeout div 1000
|
||||||
|
when defined(posix):
|
||||||
|
result.tv_sec = seconds.Time
|
||||||
|
result.tv_usec = ((timeout - seconds * 1000) * 1000).Suseconds
|
||||||
|
else:
|
||||||
result.tv_sec = seconds.int32
|
result.tv_sec = seconds.int32
|
||||||
result.tv_usec = ((timeout - seconds * 1000) * 1000).int32
|
result.tv_usec = ((timeout - seconds * 1000) * 1000).int32
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -351,8 +351,8 @@ type
|
||||||
|
|
||||||
Timeval* {.importc: "struct timeval", header: "<sys/select.h>",
|
Timeval* {.importc: "struct timeval", header: "<sys/select.h>",
|
||||||
final, pure.} = object ## struct timeval
|
final, pure.} = object ## struct timeval
|
||||||
tv_sec*: clong ## Seconds.
|
tv_sec*: Time ## Seconds.
|
||||||
tv_usec*: clong ## Microseconds.
|
tv_usec*: Suseconds ## Microseconds.
|
||||||
TFdSet* {.importc: "fd_set", header: "<sys/select.h>",
|
TFdSet* {.importc: "fd_set", header: "<sys/select.h>",
|
||||||
final, pure.} = object
|
final, pure.} = object
|
||||||
abi: array[1024 div (8 * sizeof(clong)), clong]
|
abi: array[1024 div (8 * sizeof(clong)), clong]
|
||||||
|
|
|
||||||
|
|
@ -335,8 +335,8 @@ type
|
||||||
|
|
||||||
Timeval* {.importc: "struct timeval", header: "<sys/select.h>",
|
Timeval* {.importc: "struct timeval", header: "<sys/select.h>",
|
||||||
final, pure.} = object ## struct timeval
|
final, pure.} = object ## struct timeval
|
||||||
tv_sec*: int ## Seconds.
|
tv_sec*: Time ## Seconds.
|
||||||
tv_usec*: int ## Microseconds.
|
tv_usec*: Suseconds ## Microseconds.
|
||||||
TFdSet* {.importc: "fd_set", header: "<sys/select.h>",
|
TFdSet* {.importc: "fd_set", header: "<sys/select.h>",
|
||||||
final, pure.} = object
|
final, pure.} = object
|
||||||
Mcontext* {.importc: "mcontext_t", header: "<ucontext.h>",
|
Mcontext* {.importc: "mcontext_t", header: "<ucontext.h>",
|
||||||
|
|
|
||||||
|
|
@ -616,8 +616,12 @@ proc setBlocking*(s: SocketHandle, blocking: bool) =
|
||||||
proc timeValFromMilliseconds(timeout = 500): Timeval =
|
proc timeValFromMilliseconds(timeout = 500): Timeval =
|
||||||
if timeout != -1:
|
if timeout != -1:
|
||||||
var seconds = timeout div 1000
|
var seconds = timeout div 1000
|
||||||
|
when useWinVersion:
|
||||||
result.tv_sec = seconds.int32
|
result.tv_sec = seconds.int32
|
||||||
result.tv_usec = ((timeout - seconds * 1000) * 1000).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) =
|
proc createFdSet(fd: var TFdSet, s: seq[SocketHandle], m: var int) =
|
||||||
FD_ZERO(fd)
|
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
|
## Sets the `file`'s last modification time. `OSError` is raised in case of
|
||||||
## an error.
|
## an error.
|
||||||
when defined(posix):
|
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]
|
var timevals = [Timeval(tv_sec: unixt), Timeval(tv_sec: unixt)] # [last access, last modification]
|
||||||
if utimes(file, timevals.addr) != 0: raiseOSError(osLastError())
|
if utimes(file, timevals.addr) != 0: raiseOSError(osLastError())
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1289,7 +1289,7 @@ elif not defined(useNimRtl):
|
||||||
|
|
||||||
proc select(readfds: var seq[Process], timeout = 500): int =
|
proc select(readfds: var seq[Process], timeout = 500): int =
|
||||||
var tv: Timeval
|
var tv: Timeval
|
||||||
tv.tv_sec = 0
|
tv.tv_sec = posix.Time(0)
|
||||||
tv.tv_usec = timeout * 1000
|
tv.tv_usec = timeout * 1000
|
||||||
|
|
||||||
var rd: TFdSet
|
var rd: TFdSet
|
||||||
|
|
|
||||||
|
|
@ -1752,7 +1752,7 @@ when not defined(JS):
|
||||||
when defined(posix):
|
when defined(posix):
|
||||||
var a: Timeval
|
var a: Timeval
|
||||||
gettimeofday(a)
|
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):
|
elif defined(windows):
|
||||||
var f: winlean.FILETIME
|
var f: winlean.FILETIME
|
||||||
getSystemTimeAsFileTime(f)
|
getSystemTimeAsFileTime(f)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue