Skip to content

Commit

Permalink
Safer timeout computation.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Feb 4, 2024
1 parent a4e8307 commit 7f2f464
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/cry.ml
Expand Up @@ -25,7 +25,12 @@ let poll r w timeout =
match timeout with
| x when x < 0. -> Poll.Timeout.never
| 0. -> Poll.Timeout.immediate
| x -> Poll.Timeout.after (Int64.of_float (x *. 1_000_000_000.))
| x ->
let frac, int = modf x in
let int = Int64.mul (Int64.of_float int) 1_000_000_000L in
let frac = Int64.of_float (frac *. 1_000_000_000.) in
let timeout = Int64.add int frac in
Poll.Timeout.after timeout
in
let poll = Poll.create () in
List.iter (fun fd -> Poll.set poll fd Poll.Event.read) r;
Expand Down

0 comments on commit 7f2f464

Please sign in to comment.