Skip to content

Commit

Permalink
CP-32622: Replace select with polly in xn
Browse files Browse the repository at this point in the history
  • Loading branch information
snwoods committed Jan 5, 2023
1 parent fbfcc31 commit 344bd04
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
1 change: 1 addition & 0 deletions ocaml/xenopsd/cli/dune
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
astring
cmdliner
dune-build-info
polly
re
result
rpclib.core
Expand Down
53 changes: 32 additions & 21 deletions ocaml/xenopsd/cli/xn.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1175,27 +1175,38 @@ let raw_console_proxy sockaddr =
) else if !final then
finished := true
else
let r, _, _ = Unix.select [Unix.stdin; fd] [] [] (-1.) in
if List.mem Unix.stdin r then (
let b =
Unix.read Unix.stdin buf_remote !buf_remote_end
(block - !buf_remote_end)
in
let i = ref !buf_remote_end in
while
!i < !buf_remote_end + b
&& Char.code (Bytes.get buf_remote !i) <> 0x1d
do
incr i
done ;
if !i < !buf_remote_end + b then final := true ;
buf_remote_end := !i
) ;
if List.mem fd r then
let b =
Unix.read fd buf_local !buf_local_end (block - !buf_local_end)
in
buf_local_end := !buf_local_end + b
let epoll = Polly.create () in
List.iter
(fun fd -> Polly.add epoll fd Polly.Events.inp)
[Unix.stdin; fd] ;
Fun.protect
~finally:(fun () -> Polly.close epoll)
(fun () ->
ignore
@@ Polly.wait epoll 2 (-1) (fun _ file_desc _ ->
if Unix.stdin = file_desc then (
let b =
Unix.read Unix.stdin buf_remote !buf_remote_end
(block - !buf_remote_end)
in
let i = ref !buf_remote_end in
while
!i < !buf_remote_end + b
&& Char.code (Bytes.get buf_remote !i) <> 0x1d
do
incr i
done ;
if !i < !buf_remote_end + b then final := true ;
buf_remote_end := !i
) ;
if fd = file_desc then
let b =
Unix.read fd buf_local !buf_local_end
(block - !buf_local_end)
in
buf_local_end := !buf_local_end + b
)
)
done
in
let delay = ref 0.1 in
Expand Down

0 comments on commit 344bd04

Please sign in to comment.