From: Prashanth Mundkur Date: Thu, 4 Jun 2009 18:44:52 +0000 (-0700) Subject: Added a getter for number of conns and timers. X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=7697d3925e98e6c16a2a18f593cd6b7ea75f621c;p=xenclient%2Ftoolstack.git Added a getter for number of conns and timers. --- diff --git a/libs/stdext/eventloop.ml b/libs/stdext/eventloop.ml index 9c68fc8..33d98cd 100644 --- a/libs/stdext/eventloop.ml +++ b/libs/stdext/eventloop.ml @@ -87,6 +87,11 @@ module Timers = struct ) t.by_handle es; List.map (fun e -> e.value) es with Not_found -> [] + + let num_timers t = + let cnt = ref 0 in + Timers_by_handle.iter (fun _ _ -> incr cnt) t.by_handle; + !cnt end type timer_callbacks = @@ -366,3 +371,10 @@ let dispatch t interval = ); dispatch_timers t ctime + +let num_connections t = + let cnt = ref 0 in + ConnMap.iter (fun _ _ -> incr cnt) t.conns; + !cnt + +let num_timers t = Timers.num_timers t.timers diff --git a/libs/stdext/eventloop.mli b/libs/stdext/eventloop.mli index 0bf9256..fbd238e 100644 --- a/libs/stdext/eventloop.mli +++ b/libs/stdext/eventloop.mli @@ -36,6 +36,8 @@ type conn_callbacks = (* this is to allow collections indexed by connection handles. *) val handle_compare : handle -> handle -> int +(* Connection Management *) + (* by default, connections are disabled for the send_done callback, and enabled for all others. *) val register_conn : t -> Unix.file_descr -> ?enable_send_done:bool -> ?enable_recv:bool -> conn_callbacks -> handle val remove_conn : t -> handle -> unit @@ -55,7 +57,8 @@ val has_pending_send : t -> handle -> bool val set_callbacks : t -> handle -> conn_callbacks -> unit -(* timers *) + +(* Timers *) type timer @@ -68,9 +71,18 @@ type timer_callbacks = val start_timer : t -> float (* in seconds *) -> timer_callbacks -> timer val cancel_timer : t -> timer -> unit -(* event dispatch *) + +(* Event Dispatch *) (* dispatch t intvl will block at most for intvl seconds, and dispatch any retrieved events and expired timers. *) val dispatch : t -> float -> unit + + +(* Event loop management *) + +val num_connections : t -> int +val num_timers : t -> int + +