Skip to content

Commit d86f1b8

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

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

ocaml/xenopsd/cli/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
astring
1010
cmdliner
1111
dune-build-info
12+
polly
1213
re
1314
result
1415
rpclib.core

ocaml/xenopsd/cli/xn.ml

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,27 +1176,38 @@ let raw_console_proxy sockaddr =
11761176
) else if !final then
11771177
finished := true
11781178
else
1179-
let r, _, _ = Unix.select [Unix.stdin; fd] [] [] (-1.) in
1180-
if List.mem Unix.stdin r then (
1181-
let b =
1182-
Unix.read Unix.stdin buf_remote !buf_remote_end
1183-
(block - !buf_remote_end)
1184-
in
1185-
let i = ref !buf_remote_end in
1186-
while
1187-
!i < !buf_remote_end + b
1188-
&& Char.code (Bytes.get buf_remote !i) <> 0x1d
1189-
do
1190-
incr i
1191-
done ;
1192-
if !i < !buf_remote_end + b then final := true ;
1193-
buf_remote_end := !i
1194-
) ;
1195-
if List.mem fd r then
1196-
let b =
1197-
Unix.read fd buf_local !buf_local_end (block - !buf_local_end)
1198-
in
1199-
buf_local_end := !buf_local_end + b
1179+
let epoll = Polly.create () in
1180+
List.iter
1181+
(fun fd -> Polly.add epoll fd Polly.Events.inp)
1182+
[Unix.stdin; fd] ;
1183+
Fun.protect
1184+
~finally:(fun () -> Polly.close epoll)
1185+
(fun () ->
1186+
ignore
1187+
@@ Polly.wait epoll 2 (-1) (fun _ file_desc _ ->
1188+
if Unix.stdin = file_desc then (
1189+
let b =
1190+
Unix.read Unix.stdin buf_remote !buf_remote_end
1191+
(block - !buf_remote_end)
1192+
in
1193+
let i = ref !buf_remote_end in
1194+
while
1195+
!i < !buf_remote_end + b
1196+
&& Char.code (Bytes.get buf_remote !i) <> 0x1d
1197+
do
1198+
incr i
1199+
done ;
1200+
if !i < !buf_remote_end + b then final := true ;
1201+
buf_remote_end := !i
1202+
) ;
1203+
if fd = file_desc then
1204+
let b =
1205+
Unix.read fd buf_local !buf_local_end
1206+
(block - !buf_local_end)
1207+
in
1208+
buf_local_end := !buf_local_end + b
1209+
)
1210+
)
12001211
done
12011212
in
12021213
let delay = ref 0.1 in

0 commit comments

Comments
 (0)