Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable to read which backend was picked by libev. #985

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions src/unix/lwt_engine.ml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ struct
let devpoll = EV_DEVPOLL
let port = EV_PORT

let equal = ( = )

let name = function
| EV_DEFAULT -> "EV_DEFAULT"
| EV_SELECT -> "EV_SELECT"
Expand All @@ -160,6 +162,7 @@ struct
end

external ev_init : Ev_backend.t -> ev_loop = "lwt_libev_init"
external ev_backend : ev_loop -> Ev_backend.t = "lwt_libev_backend"
external ev_stop : ev_loop -> unit = "lwt_libev_stop"
external ev_loop : ev_loop -> bool -> unit = "lwt_libev_loop"
external ev_unloop : ev_loop -> unit = "lwt_libev_unloop"
Expand All @@ -175,6 +178,8 @@ class libev ?(backend=Ev_backend.default) () = object
val loop = ev_init backend
method loop = loop

method backend = lazy (ev_backend loop)

method private cleanup = ev_stop loop

method iter block =
Expand Down
7 changes: 7 additions & 0 deletions src/unix/lwt_engine.mli
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ sig
val devpoll : t
val port : t

val equal : t -> t -> bool

val pp : Format.formatter -> t -> unit
end

Expand All @@ -137,6 +139,9 @@ end
class libev : ?backend:Ev_backend.t -> unit -> object
inherit t

method backend : Ev_backend.t Lazy.t
(** The backend picked by libev. *)

val loop : ev_loop
(** The libev loop used for this engine. *)

Expand Down Expand Up @@ -200,6 +205,7 @@ sig
class libev_1 : object
inherit t
val loop : ev_loop
method backend : Ev_backend.t Lazy.t
method loop : ev_loop
end
[@@ocaml.deprecated
Expand All @@ -214,6 +220,7 @@ sig
class libev_2 : ?backend:Ev_backend.t -> unit -> object
inherit t
val loop : ev_loop
method backend : Ev_backend.t Lazy.t
method loop : ev_loop
end
[@@ocaml.deprecated
Expand Down
19 changes: 19 additions & 0 deletions src/unix/lwt_libev_stubs.c
mefyl marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ CAMLprim value lwt_libev_init(value backend) {
return result;
}

CAMLprim value lwt_libev_backend(value loop) {
switch (ev_backend(Ev_loop_val(loop))) {
case EVBACKEND_SELECT:
return Val_int(val_EVBACKEND_SELECT);
case EVBACKEND_POLL:
return Val_int(val_EVBACKEND_POLL);
case EVBACKEND_EPOLL:
return Val_int(val_EVBACKEND_EPOLL);
case EVBACKEND_KQUEUE:
return Val_int(val_EVBACKEND_KQUEUE);
case EVBACKEND_DEVPOLL:
return Val_int(val_EVBACKEND_DEVPOLL);
case EVBACKEND_PORT:
return Val_int(val_EVBACKEND_PORT);
default:
assert(0);
}
}

CAMLprim value lwt_libev_stop(value loop) {
ev_loop_destroy(Ev_loop_val(loop));
return Val_unit;
Expand Down