diff --git a/src/stack-unix/tcpv4_socket.ml b/src/stack-unix/tcpv4_socket.ml index 9f150c9e1..f1a0ae7fa 100644 --- a/src/stack-unix/tcpv4_socket.ml +++ b/src/stack-unix/tcpv4_socket.ml @@ -14,7 +14,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -open Lwt +open Lwt.Infix type ipaddr = Ipaddr.V4.t type flow = Lwt_unix.file_descr @@ -26,13 +26,13 @@ type t = { include Tcp_socket -let connect id = +let connect addr = let t = - match id with + match addr with | None -> { interface=None } | Some ip -> { interface=Some (Ipaddr_unix.V4.to_inet_addr ip) } in - return t + Lwt.return t let dst fd = match Lwt_unix.getpeername fd with @@ -54,7 +54,7 @@ let create_connection ?keepalive _t (dst,dst_port) = | None -> () | Some { Mirage_protocols.Keepalive.after; interval; probes } -> Tcp_socket_options.enable_keepalive ~fd ~after ~interval ~probes ); - return (Ok fd)) + Lwt.return (Ok fd)) (fun exn -> Lwt.catch (fun () -> Lwt_unix.close fd) (fun _ -> Lwt.return_unit) >>= fun () -> - return (Error (`Exn exn))) + Lwt.return (Error (`Exn exn))) diff --git a/src/stack-unix/tcpv6_socket.ml b/src/stack-unix/tcpv6_socket.ml index 45f40c440..498e591fd 100644 --- a/src/stack-unix/tcpv6_socket.ml +++ b/src/stack-unix/tcpv6_socket.ml @@ -25,6 +25,8 @@ type t = { interface: Unix.inet_addr option; (* source ip to bind to *) } +include Tcp_socket + let connect addr = let t = match addr with @@ -50,12 +52,10 @@ let create_connection ?keepalive _t (dst,dst_port) = (Lwt_unix.ADDR_INET ((Ipaddr_unix.V6.to_inet_addr dst), dst_port)) >>= fun () -> ( match keepalive with - | None -> () - | Some { Mirage_protocols.Keepalive.after; interval; probes } -> - Tcp_socket_options.enable_keepalive ~fd ~after ~interval ~probes ); + | None -> () + | Some { Mirage_protocols.Keepalive.after; interval; probes } -> + Tcp_socket_options.enable_keepalive ~fd ~after ~interval ~probes ); Lwt.return (Ok fd)) (fun exn -> Lwt.catch (fun () -> Lwt_unix.close fd) (fun _ -> Lwt.return_unit) >>= fun () -> Lwt.return (Error (`Exn exn))) - -include Tcp_socket diff --git a/src/stack-unix/udpv6_socket.ml b/src/stack-unix/udpv6_socket.ml index 922f31f30..5b392c925 100644 --- a/src/stack-unix/udpv6_socket.ml +++ b/src/stack-unix/udpv6_socket.ml @@ -15,15 +15,13 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -open Lwt +open Lwt.Infix -type buffer = Cstruct.t type ipaddr = Ipaddr.V6.t type flow = Lwt_unix.file_descr -type +'a io = 'a Lwt.t type ip = Ipaddr.V6.t option (* source ip and port *) type ipinput = unit Lwt.t -type callback = src:ipaddr -> dst:ipaddr -> src_port:int -> buffer -> unit io +type callback = src:ipaddr -> dst:ipaddr -> src_port:int -> Cstruct.t -> unit Lwt.t type t = { interface: Unix.inet_addr; (* source ip to bind to *) @@ -35,12 +33,12 @@ let get_udpv6_listening_fd {listen_fds;interface} port = Lwt.return @@ Hashtbl.find listen_fds (interface,port) with Not_found -> let fd = Lwt_unix.(socket PF_INET6 SOCK_DGRAM 0) in - Lwt_unix.bind fd (Lwt_unix.ADDR_INET (interface,port)) + Lwt_unix.bind fd (Lwt_unix.ADDR_INET (interface, port)) >>= fun () -> - Hashtbl.add listen_fds (interface,port) fd; + Hashtbl.add listen_fds (interface, port) fd; Lwt.return fd -(** IO operation errors *) + type error = [`Sendto_failed] let pp_error ppf = function @@ -54,10 +52,9 @@ let connect (id:ip) = | None -> Ipaddr_unix.V6.to_inet_addr Ipaddr.V6.unspecified | Some ip -> Ipaddr_unix.V6.to_inet_addr ip in { interface; listen_fds } - in return t + in Lwt.return t -let disconnect _ = - return_unit +let disconnect _ = Lwt.return_unit let id { interface; _ } = Some (Ipaddr_unix.V6.of_inet_addr_exn interface)