From d5487e2732cec432d920221ad02cf142a934c5b3 Mon Sep 17 00:00:00 2001 From: Romain Beauxis Date: Sun, 4 Feb 2024 15:50:50 -0600 Subject: [PATCH] Better. --- src/cry.ml | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/cry.ml b/src/cry.ml index fe19cac..8d51eeb 100644 --- a/src/cry.ml +++ b/src/cry.ml @@ -34,18 +34,16 @@ let poll = let timeout = Int64.add int frac in Poll.Timeout.after timeout in + Poll.clear poll; List.iter (fun fd -> Poll.set poll fd Poll.Event.read) r; List.iter (fun fd -> Poll.set poll fd Poll.Event.write) w; - Fun.protect - (fun () -> - ignore (Poll.wait poll timeout); - let r = ref [] in - let w = ref [] in - Poll.iter_ready poll ~f:(fun fd -> function - | { Poll.Event.readable = true; _ } -> r := fd :: !r - | _ -> w := fd :: !w); - (!r, !w)) - ~finally:(fun () -> Poll.clear poll) + ignore (Poll.wait poll timeout); + let r = ref [] in + let w = ref [] in + Poll.iter_ready poll ~f:(fun fd event -> + if event.Poll.Event.readable then r := fd :: !r; + if event.Poll.Event.writable then w := fd :: !w); + (!r, !w) type error = | Create of exn