Skip to content

Commit f4c2087

Browse files
committed
CP-32622: Replace select with polly in xsh
Signed-off-by: Steven Woods <[email protected]>
1 parent d86f1b8 commit f4c2087

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-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: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,25 @@ 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+
(* Note: only one fd is handled *)
72+
if aout = fd then
73+
write_from b' a'
74+
else if bout = fd then
75+
write_from a' b'
76+
else if ain = fd then
77+
read_into a'
78+
else
79+
read_into b'
80+
)
81+
)
6982
done
7083
with _ -> (
7184
(try Unix.clear_nonblock ain with _ -> ()) ;

0 commit comments

Comments
 (0)