diff --git a/ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/threadext.ml b/ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/threadext.ml index b255239dd4d..1ca5e916ef4 100644 --- a/ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/threadext.ml +++ b/ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/threadext.ml @@ -111,3 +111,23 @@ module Delay = struct (* If the wait hasn't happened yet then store up the signal *) ) end + +let wait_timed_read fd timeout = + match Xapi_stdext_unix.Unixext.select [fd] [] [] timeout with + | [], _, _ -> + false + | [fd'], _, _ -> + assert (fd' = fd) ; + true + | _ -> + assert false + +let wait_timed_write fd timeout = + match Xapi_stdext_unix.Unixext.select [] [fd] [] timeout with + | _, [], _ -> + false + | _, [fd'], _ -> + assert (fd' = fd) ; + true + | _ -> + assert false diff --git a/ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/threadext.mli b/ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/threadext.mli index 8349ab71366..057aedfa700 100644 --- a/ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/threadext.mli +++ b/ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/threadext.mli @@ -33,3 +33,7 @@ module Delay : sig val signal : t -> unit (** Sends a signal to a waiting thread. See 'wait' *) end + +val wait_timed_read : Unix.file_descr -> float -> bool + +val wait_timed_write : Unix.file_descr -> float -> bool