Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/iomux_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ caml_iomux_poll_init(value v_fds, value v_maxfds)
}


value /* noalloc */
caml_iomux_poll_get_events(value v_fds, value v_index)
{
struct pollfd *pfd = pollfd_of_index(v_fds, v_index);

return (Val_int(pfd->events));
}

value /* noalloc */
caml_iomux_poll_get_revents(value v_fds, value v_index)
{
Expand Down
5 changes: 5 additions & 0 deletions lib/poll.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Raw = struct
external ppoll : buffer -> int -> int64 -> int list -> int = "caml_iomux_ppoll"
external set_index : buffer -> int -> int -> int -> unit = "caml_iomux_poll_set_index" [@@noalloc]
external init : buffer -> int -> unit = "caml_iomux_poll_init"
external get_events : buffer -> int -> int = "caml_iomux_poll_get_events" [@@noalloc]
external get_revents : buffer -> int -> int = "caml_iomux_poll_get_revents" [@@noalloc]
external get_fd : buffer -> int -> int = "caml_iomux_poll_get_fd" [@@noalloc]
end
Expand Down Expand Up @@ -106,6 +107,10 @@ let invalidate_index t index =
guard_index t index;
Raw.set_index t.buffer index (-1) 0

let get_events t index =
guard_index t index;
Raw.get_events t.buffer index

let get_revents t index =
guard_index t index;
Raw.get_revents t.buffer index
Expand Down
4 changes: 4 additions & 0 deletions lib/poll.mli
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ val invalidate_index : t -> int -> unit
invalidating [index]. The kernel will ignore that slot. We also
clear flags, just for kicks. *)

val get_events : t -> int -> Flags.t
(** [get_events t index] is the event flags to be listened for by the
file descriptor at [index]. *)

val get_revents : t -> int -> Flags.t
(** [get_revents t index] is the returned event flags set after a call
to {!poll} or {!ppoll}. *)
Expand Down
2 changes: 2 additions & 0 deletions test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ module T = struct
let nready = Poll.poll poll 1 Nowait in
check_int "nready" nready 1;
let fd = Poll.get_fd poll 0 in
let events = Poll.get_events poll 0 in
let revents = Poll.get_revents poll 0 in
check_bool "fd" true (r = fd);
check_bool "events" true (events = Poll.Flags.pollin);
check_bool "revents" true (Poll.Flags.mem revents Poll.Flags.pollin);
check_bool "revents-eq" true (revents = Poll.Flags.pollin);
Unix.close w;
Expand Down