fix getRelativeTimeout (assuming microseconds was wrong)

This commit is contained in:
Christian Ulrich 2020-11-08 01:22:53 +01:00
parent e936bc49d9
commit 6e7ab9369d
No known key found for this signature in database
GPG Key ID: 8241BE099775A097
1 changed files with 3 additions and 5 deletions

View File

@ -43,8 +43,8 @@ proc PEM_read_PrivateKey(fp: File, x: ptr EVP_PKEY,
proc EVP_PKEY_free(key: EVP_PKEY) {.importc, dynlib: DLLSSLName, cdecl.}
proc getRelativeTimeout(ctx: QuicP2PContext): int32 =
## Obtain the absolute int64 timeout (in microseconds) from quicly and convert
## it to the relative int32 timeout (in milliseconds) expected by poll.
## Obtain the absolute int64 timeout from quicly and convert it to the
## relative int32 timeout expected by poll.
result = 0
var nextTimeout = int64.high
var now = ctx.quiclyCtx.now.cb(ctx.quiclyCtx.now)
@ -53,9 +53,7 @@ proc getRelativeTimeout(ctx: QuicP2PContext): int32 =
if connTimeout < nextTimeout:
nextTimeout = connTimeout
if now < nextTimeout:
# calculate time until nextTimeout and convert from microseconds to
# milliseconds
let delta = (nextTimeout - now) div 1_000
let delta = nextTimeout - now
result = min(delta, int32.high).int32
proc onStopSending(stream: ptr quicly_stream_t, err: cint) {.cdecl.} =