From 9208739bcc40db3ad9d8b6e6032d36393a59ad1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Mon, 22 Jul 2024 13:14:46 +0100 Subject: [PATCH] CP-32622: Thread.wait_timed_read/wait_timed_write MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Edwin Török --- .../lib/xapi-stdext-threads/threadext.ml | 20 +++++++++++++++++++ .../lib/xapi-stdext-threads/threadext.mli | 4 ++++ 2 files changed, 24 insertions(+) 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