Skip to content

Commit 4e80d42

Browse files
committed
CP-32622: Replace: Unix.select and Thread.wait_timed_* with Unixext equivalents
Also add xapi-stdext-unix or xapi-stext-threads as needed to dune. Signed-off-by: Edwin Török <[email protected]>
1 parent 500f633 commit 4e80d42

File tree

17 files changed

+31
-13
lines changed

17 files changed

+31
-13
lines changed

ocaml/database/block_device_io.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ let accept_conn s latest_response_time =
328328
let now = Unix.gettimeofday () in
329329
let timeout = latest_response_time -. now in
330330
(* Await an incoming connection... *)
331-
let ready_to_read, _, _ = Unix.select [s] [] [] timeout in
331+
let ready_to_read, _, _ = Xapi_stdext_unix.Unixext.select [s] [] [] timeout in
332332
R.info "Finished selecting" ;
333333
if List.mem s ready_to_read then
334334
(* We've received a connection. Accept it and return the socket. *)

ocaml/database/master_connection.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ let open_secure_connection () =
171171
~write_to_log:(fun x -> debug "stunnel: %s\n" x)
172172
~verify_cert host port
173173
@@ fun st_proc ->
174-
let fd_closed = Thread.wait_timed_read Unixfd.(!(st_proc.Stunnel.fd)) 5. in
174+
let fd_closed =
175+
Xapi_stdext_threads.Threadext.wait_timed_read
176+
Unixfd.(!(st_proc.Stunnel.fd))
177+
5.
178+
in
175179
let proc_quit =
176180
try
177181
Unix.kill (Stunnel.getpid st_proc.Stunnel.pid) 0 ;

ocaml/forkexecd/src/child.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ let handle_comms_sock comms_sock state =
6161

6262
let handle_comms_no_fd_sock2 comms_sock fd_sock state =
6363
debug "Selecting in handle_comms_no_fd_sock2" ;
64-
let ready, _, _ = Unix.select [comms_sock; fd_sock] [] [] (-1.0) in
64+
let ready, _, _ =
65+
Xapi_stdext_unix.Unixext.select [comms_sock; fd_sock] [] [] (-1.0)
66+
in
6567
debug "Done" ;
6668
if List.mem fd_sock ready then (
6769
debug "fd sock" ;
@@ -74,7 +76,9 @@ let handle_comms_no_fd_sock2 comms_sock fd_sock state =
7476

7577
let handle_comms_with_fd_sock2 comms_sock _fd_sock fd_sock2 state =
7678
debug "Selecting in handle_comms_with_fd_sock2" ;
77-
let ready, _, _ = Unix.select [comms_sock; fd_sock2] [] [] (-1.0) in
79+
let ready, _, _ =
80+
Xapi_stdext_unix.Unixext.select [comms_sock; fd_sock2] [] [] (-1.0)
81+
in
7882
debug "Done" ;
7983
if List.mem fd_sock2 ready then (
8084
debug "fd sock2" ;

ocaml/libs/ezxenstore/core/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
(re_export xenstore)
1010
(re_export xenstore_transport)
1111
threads.posix
12+
xapi-stdext-unix
1213
(re_export xenstore.unix))
1314
)

ocaml/libs/ezxenstore/core/watch.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let wait_for ~xs ?(timeout = 300.) (x : 'a t) =
5050
let thread =
5151
Thread.create
5252
(fun () ->
53-
let r, _, _ = Unix.select [p1] [] [] timeout in
53+
let r, _, _ = Xapi_stdext_unix.Unixext.select [p1] [] [] timeout in
5454
if r <> [] then
5555
()
5656
else

ocaml/libs/http-lib/buf_io.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ let is_full ic = ic.cur = 0 && ic.max = Bytes.length ic.buf
7474
let fill_buf ~buffered ic timeout =
7575
let buf_size = Bytes.length ic.buf in
7676
let fill_no_exc timeout len =
77-
let l, _, _ = Unix.select [ic.fd] [] [] timeout in
77+
let l, _, _ = Xapi_stdext_unix.Unixext.select [ic.fd] [] [] timeout in
7878
if l <> [] then (
7979
let n = Unix.read ic.fd ic.buf ic.max len in
8080
ic.max <- n + ic.max ;

ocaml/libs/xapi-stdext/lib/xapi-stdext-unix/unixext.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ val domain_of_addr : string -> Unix.socket_domain option
257257

258258
val test_open : int -> unit
259259
(** [test_open n] opens n file descriptors. This is useful for testing that the application makes no calls
260-
to [Unix.select] that use file descriptors, because such calls will then immediately fail.
260+
to [Xapi_stdext_unix.Unixext.select] that use file descriptors, because such calls will then immediately fail.
261261
262262
This assumes that [ulimit -n] has been suitably increased in the test environment.
263263

ocaml/message-switch/unix/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
rpclib.json
1313
threads.posix
1414
xapi-stdext-threads
15+
xapi-stdext-unix
1516
)
1617
(preprocess (per_module ((pps ppx_deriving_rpc) Protocol_unix_scheduler)))
1718
)

ocaml/networkd/lib/jsonrpc_client.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ let timeout_read fd timeout =
4343
in
4444
let rec inner max_time max_bytes =
4545
let ready_to_read, _, _ =
46-
try Unix.select [fd] [] [] (to_s max_time)
46+
try Xapi_stdext_unix.Unixext.select [fd] [] [] (to_s max_time)
4747
with
4848
(* in case the unix.select call fails in situation like interrupt *)
4949
| Unix.Unix_error (Unix.EINTR, _, _) ->
@@ -96,7 +96,7 @@ let timeout_write filedesc total_length data response_time =
9696
in
9797
let rec inner_write offset max_time =
9898
let _, ready_to_write, _ =
99-
try Unix.select [] [filedesc] [] (to_s max_time)
99+
try Xapi_stdext_unix.Unixext.select [] [filedesc] [] (to_s max_time)
100100
with
101101
(* in case the unix.select call fails in situation like interrupt *)
102102
| Unix.Unix_error (Unix.EINTR, _, _) ->

ocaml/xapi-idl/lib/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
xapi-open-uri
3333
xapi-stdext-pervasives
3434
xapi-stdext-threads
35+
xapi-stdext-unix
3536
xapi-inventory
3637
xmlm
3738
)

0 commit comments

Comments
 (0)