Skip to content

Commit 4a79673

Browse files
committed
CP-32622: Replace select with polly in xsh
1 parent 344bd04 commit 4a79673

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

ocaml/xsh/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
(package xapi)
66
(libraries
77
dune-build-info
8+
polly
89
stunnel
910
safe-resources
1011
xapi-consts

ocaml/xsh/xsh.ml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,24 @@ let proxy (ain : Unix.file_descr) (aout : Unix.file_descr) (bin : Unixfd.t)
6060
(if can_write a' then [bout] else [])
6161
@ if can_write b' then [aout] else []
6262
in
63-
let r, w, _ = Unix.select r w [] (-1.0) in
64-
(* Do the writing before the reading *)
65-
List.iter
66-
(fun fd -> if aout = fd then write_from b' a' else write_from a' b')
67-
w ;
68-
List.iter (fun fd -> if ain = fd then read_into a' else read_into b') r
63+
let epoll = Polly.create () in
64+
List.iter (fun fd -> Polly.add epoll fd Polly.Events.inp) r ;
65+
List.iter (fun fd -> Polly.add epoll fd Polly.Events.out) w ;
66+
Fun.protect
67+
~finally:(fun () -> Polly.close epoll)
68+
(fun () ->
69+
ignore
70+
@@ Polly.wait epoll 4 (-1) (fun _ fd _ ->
71+
if aout = fd then
72+
write_from b' a'
73+
else if bout = fd then
74+
write_from a' b'
75+
else if ain = fd then
76+
read_into a'
77+
else
78+
read_into b'
79+
)
80+
)
6981
done
7082
with _ -> (
7183
(try Unix.clear_nonblock ain with _ -> ()) ;

0 commit comments

Comments
 (0)