@@ -59,28 +59,42 @@ let handle_comms_sock comms_sock state =
5959 state
6060
6161let 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
7481let 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
86100let handle_comms comms_sock fd_sock state =
0 commit comments