Skip to content

Commit ea9cb03

Browse files
committed
CP-32622: Replace select with polly in child
1 parent d9f10d5 commit ea9cb03

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

ocaml/forkexecd/src/child.ml

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,42 @@ let handle_comms_sock comms_sock state =
5959
state
6060

6161
let handle_comms_no_fd_sock2 comms_sock fd_sock state =
62-
debug "Selecting in handle_comms_no_fd_sock2" ;
63-
let ready, _, _ = Unix.select [comms_sock; fd_sock] [] [] (-1.0) in
64-
debug "Done" ;
65-
if List.mem fd_sock ready then (
66-
debug "fd sock" ;
67-
let fd_sock2, _ = Unix.accept fd_sock in
68-
{state with fd_sock2= Some fd_sock2}
69-
) else (
70-
debug "comms sock" ;
71-
handle_comms_sock comms_sock state
62+
debug "Using epoll in handle_comms_no_fd_sock2" ;
63+
let epoll = Polly.create () in
64+
List.iter
65+
(fun fd -> Polly.add epoll fd Polly.Events.inp)
66+
[comms_sock; fd_sock] ;
67+
(* Although there are two fds, we set max_fds to 1 here as we only want this
68+
function to trigger once so that we get one return value *)
69+
Polly.wait_fold epoll 1 (-1) state (fun _ fd _ _ ->
70+
debug "Done" ;
71+
if fd_sock = fd then (
72+
debug "fd sock" ;
73+
let fd_sock2, _ = Unix.accept fd_sock in
74+
{state with fd_sock2= Some fd_sock2}
75+
) else (
76+
debug "comms sock" ;
77+
handle_comms_sock comms_sock state
78+
)
7279
)
7380

7481
let handle_comms_with_fd_sock2 comms_sock _fd_sock fd_sock2 state =
75-
debug "Selecting in handle_comms_with_fd_sock2" ;
76-
let ready, _, _ = Unix.select [comms_sock; fd_sock2] [] [] (-1.0) in
77-
debug "Done" ;
78-
if List.mem fd_sock2 ready then (
79-
debug "fd sock2" ;
80-
handle_fd_sock fd_sock2 state
81-
) else (
82-
debug "comms sock" ;
83-
handle_comms_sock comms_sock state
82+
debug "Using epoll in handle_comms_with_fd_sock2" ;
83+
let epoll = Polly.create () in
84+
List.iter
85+
(fun fd -> Polly.add epoll fd Polly.Events.inp)
86+
[comms_sock; fd_sock2] ;
87+
(* Although there are two fds, we set max_fds to 1 here as we only want this
88+
function to trigger once so that we get one return value *)
89+
Polly.wait_fold epoll 1 (-1) state (fun _ fd _ _ ->
90+
debug "Done" ;
91+
if fd_sock2 = fd then (
92+
debug "fd sock2" ;
93+
handle_fd_sock fd_sock2 state
94+
) else (
95+
debug "comms sock" ;
96+
handle_comms_sock comms_sock state
97+
)
8498
)
8599

86100
let handle_comms comms_sock fd_sock state =

ocaml/forkexecd/src/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
astring
66
fd-send-recv
77
forkexec
8+
polly
89
systemd
910
uuid
1011
xapi-log

0 commit comments

Comments
 (0)