Skip to content

Commit

Permalink
Merge pull request #985 from mefyl/master
Browse files Browse the repository at this point in the history
Enable to read which backend was picked by libev.
  • Loading branch information
raphael-proust authored Nov 8, 2024
2 parents 347c3ad + d1bee23 commit 5b59c71
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/unix/lwt_engine.ml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,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 @@ -162,6 +164,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 @@ -177,6 +180,8 @@ class libev ?(backend=Ev_backend.default) () = object
val loop = ev_init backend
method loop = loop

method backend = 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 @@ -135,6 +135,8 @@ sig
val devpoll : t
val port : t

val equal : t -> t -> bool

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

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

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

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

Expand Down Expand Up @@ -208,6 +213,7 @@ sig
class libev_1 : object
inherit t
val loop : ev_loop
method backend : Ev_backend.t
method loop : ev_loop
end
[@@ocaml.deprecated
Expand All @@ -222,6 +228,7 @@ sig
class libev_2 : ?backend:Ev_backend.t -> unit -> object
inherit t
val loop : ev_loop
method backend : Ev_backend.t
method loop : ev_loop
end
[@@ocaml.deprecated
Expand Down
20 changes: 20 additions & 0 deletions src/unix/lwt_libev_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,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 Expand Up @@ -224,6 +243,7 @@ CAMLprim value lwt_libev_timer_stop(value loop, value val_watcher) {

#include "lwt_unix.h"

LWT_NOT_AVAILABLE1(libev_backend)
LWT_NOT_AVAILABLE1(libev_init)
LWT_NOT_AVAILABLE1(libev_stop)
LWT_NOT_AVAILABLE2(libev_loop)
Expand Down

0 comments on commit 5b59c71

Please sign in to comment.