Skip to content

Commit

Permalink
Better.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Feb 4, 2024
1 parent 3c26258 commit d5487e2
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/cry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d5487e2

Please sign in to comment.