Skip to content

Commit

Permalink
CP-32622: Replace select with polly in child
Browse files Browse the repository at this point in the history
  • Loading branch information
snwoods committed Jan 13, 2023
1 parent d9f10d5 commit ea9cb03
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
52 changes: 33 additions & 19 deletions ocaml/forkexecd/src/child.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,42 @@ let handle_comms_sock comms_sock state =
state

let handle_comms_no_fd_sock2 comms_sock fd_sock state =
debug "Selecting in handle_comms_no_fd_sock2" ;
let ready, _, _ = Unix.select [comms_sock; fd_sock] [] [] (-1.0) in
debug "Done" ;
if List.mem fd_sock ready then (
debug "fd sock" ;
let fd_sock2, _ = Unix.accept fd_sock in
{state with fd_sock2= Some fd_sock2}
) else (
debug "comms sock" ;
handle_comms_sock comms_sock state
debug "Using epoll in handle_comms_no_fd_sock2" ;
let epoll = Polly.create () in
List.iter
(fun fd -> Polly.add epoll fd Polly.Events.inp)
[comms_sock; fd_sock] ;
(* Although there are two fds, we set max_fds to 1 here as we only want this
function to trigger once so that we get one return value *)
Polly.wait_fold epoll 1 (-1) state (fun _ fd _ _ ->
debug "Done" ;
if fd_sock = fd then (
debug "fd sock" ;
let fd_sock2, _ = Unix.accept fd_sock in
{state with fd_sock2= Some fd_sock2}
) else (
debug "comms sock" ;
handle_comms_sock comms_sock state
)
)

let handle_comms_with_fd_sock2 comms_sock _fd_sock fd_sock2 state =
debug "Selecting in handle_comms_with_fd_sock2" ;
let ready, _, _ = Unix.select [comms_sock; fd_sock2] [] [] (-1.0) in
debug "Done" ;
if List.mem fd_sock2 ready then (
debug "fd sock2" ;
handle_fd_sock fd_sock2 state
) else (
debug "comms sock" ;
handle_comms_sock comms_sock state
debug "Using epoll in handle_comms_with_fd_sock2" ;
let epoll = Polly.create () in
List.iter
(fun fd -> Polly.add epoll fd Polly.Events.inp)
[comms_sock; fd_sock2] ;
(* Although there are two fds, we set max_fds to 1 here as we only want this
function to trigger once so that we get one return value *)
Polly.wait_fold epoll 1 (-1) state (fun _ fd _ _ ->
debug "Done" ;
if fd_sock2 = fd then (
debug "fd sock2" ;
handle_fd_sock fd_sock2 state
) else (
debug "comms sock" ;
handle_comms_sock comms_sock state
)
)

let handle_comms comms_sock fd_sock state =
Expand Down
1 change: 1 addition & 0 deletions ocaml/forkexecd/src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
astring
fd-send-recv
forkexec
polly
systemd
uuid
xapi-log
Expand Down

0 comments on commit ea9cb03

Please sign in to comment.