diff --git a/src/unix/lwt_engine.ml b/src/unix/lwt_engine.ml index 0e2cf7e6c..17618e133 100644 --- a/src/unix/lwt_engine.ml +++ b/src/unix/lwt_engine.ml @@ -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" @@ -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" @@ -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 = diff --git a/src/unix/lwt_engine.mli b/src/unix/lwt_engine.mli index bd696c9bf..fbdd7d199 100644 --- a/src/unix/lwt_engine.mli +++ b/src/unix/lwt_engine.mli @@ -135,6 +135,8 @@ sig val devpoll : t val port : t + val equal : t -> t -> bool + val pp : Format.formatter -> t -> unit end @@ -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. *) @@ -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 @@ -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 diff --git a/src/unix/lwt_libev_stubs.c b/src/unix/lwt_libev_stubs.c index 22af6d60f..e817fee34 100644 --- a/src/unix/lwt_libev_stubs.c +++ b/src/unix/lwt_libev_stubs.c @@ -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; @@ -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)