diff options
-rw-r--r-- | portal/tcp/portal.ml | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/portal/tcp/portal.ml b/portal/tcp/portal.ml index f01e6ad..c88ac98 100644 --- a/portal/tcp/portal.ml +++ b/portal/tcp/portal.ml @@ -25,7 +25,15 @@ let tcp_socket (domain : string) : Lwt_unix.file_descr Lwt.t = let open Lwt_unix in let get_socket {ai_addr; ai_family; _} = let sock = socket ai_family SOCK_STREAM 0 - in let+ () = Lwt_unix.connect sock ai_addr + in + let rec try_connect retries : unit Lwt.t = + try%lwt Lwt_unix.connect sock ai_addr + with Unix.Unix_error (Unix.ENETUNREACH, _, _) as exn -> + if retries = 0 + then Lwt.fail exn + else let* () = Lwt_unix.sleep 0.05 + in try_connect (retries-1) + in let+ () = try_connect 3 in sock and port_number = xmpp_port domain |> string_of_int in let* addrinfos = getaddrinfo domain port_number [AI_SOCKTYPE SOCK_STREAM] |