Skip to content

Commit

Permalink
luv: implement luv reuseport and reuseaddr
Browse files Browse the repository at this point in the history
  • Loading branch information
bikallem committed Nov 4, 2022
1 parent a70865e commit 7b0f516
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib_eio_luv/eio_luv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -747,11 +747,15 @@ class virtual ['a] listening_socket ~backlog sock = object (self)
)
end

(* TODO: implement, or maybe remove from the Eio API.
Luv makes TCP sockets reuse_addr by default, and maybe that's fine everywhere.
Extracting the FD will require https://github.com/aantron/luv/issues/120 *)
let luv_reuse_addr _sock _v = ()
let luv_reuse_port _sock _v = ()
let luv_reuse_addr sock v =
match Handle.to_unix_opt `Peek sock with
| Some fd -> Unix.setsockopt fd Unix.SO_REUSEADDR v
| None -> ()

let luv_reuse_port sock v =
match Handle.to_unix_opt `Peek sock with
| Some fd -> Unix.setsockopt fd Unix.SO_REUSEPORT v
| None -> ()

let luv_addr_of_eio host port =
let host = Unix.string_of_inet_addr (Eio_unix.Ipaddr.to_unix host) in
Expand Down Expand Up @@ -877,8 +881,8 @@ let net = object
begin match saddr with
| `Udp (host, port) ->
let addr = luv_addr_of_eio host port in
luv_reuse_addr sock reuse_addr;
luv_reuse_port sock reuse_port;
luv_reuse_addr dg_sock reuse_addr;
luv_reuse_port dg_sock reuse_port;
Luv.UDP.bind sock addr |> or_raise
| `UdpV4 | `UdpV6 -> ()
end;
Expand Down

0 comments on commit 7b0f516

Please sign in to comment.