Change type of Timeval.tv_sec to posix.Time (#7646)

This commit is contained in:
Oscar Nihlgård 2018-04-18 21:24:28 +02:00 • committed by Andreas Rumpf
commit fdf1d12380
9 changed files with 28 additions and 15 deletions

View file

@ -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)

View file

@ -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:

View file

@ -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

View file

@ -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)