Skip to content

Commit

Permalink
CP-47536: convert block_device_io to use SO_RCVTIMEO instead of select
Browse files Browse the repository at this point in the history
TODO: needs tests

Signed-off-by: Edwin Török <[email protected]>
  • Loading branch information
edwintorok committed May 29, 2024
1 parent afe3b91 commit 00ec519
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions ocaml/database/block_device_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,18 @@ let accept_conn s latest_response_time =
match Unixext.Timer.remaining latest_response_time with
| Excess _ ->
raise Unixext.Timeout
| Spare timeout ->
| Spare timeout -> (
(* Await an incoming connection... *)
let ready_to_read, _, _ =
Unix.select [s] [] [] (Mtime.Span.to_float_ns timeout *. 1e-9)
in
R.info "Finished selecting" ;
if List.mem s ready_to_read then
let timeout = Mtime.Span.to_float_ns timeout *. 1e-9 in
Unix.setsockopt_float s Unix.SO_RCVTIMEO timeout ;
let finally () = Unix.setsockopt_float s Unix.SO_RCVTIMEO timeout in
Fun.protect ~finally @@ fun () ->
try
(* We've received a connection. Accept it and return the socket. *)
fst (Unix.accept s)
else (* We must have timed out *)
with Unix.(Unix_error ((EAGAIN | EWOULDBLOCK), _, _)) ->
raise Unixext.Timeout
)

(* Listen on a given socket. Accept a single connection and transfer all the data from it to dest_fd, or raise Timeout if target_response_time happens first. *)
(* Raises NotEnoughSpace if the next write would exceed the available_space. *)
Expand Down

0 comments on commit 00ec519

Please sign in to comment.