diff --git a/CHANGES b/CHANGES index aed4890..435af42 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +1.0.3 (unreleased) +===== +* Raise a proper error when non-blocking connection + fails. + 1.0.2 (2024-01-08) ====== * Use `poll` for select when available. diff --git a/cry.opam b/cry.opam index 3316d79..6577ad0 100644 --- a/cry.opam +++ b/cry.opam @@ -1,6 +1,6 @@ # This file is generated by dune, edit dune-project instead opam-version: "2.0" -version: "1.0.2" +version: "1.0.3" synopsis: "OCaml client for the various icecast & shoutcast source protocols" description: "The cry library is an implementation of the various icecast & shoutcast protocols to connect to streaming servers such as icecast" diff --git a/dune-project b/dune-project index b202341..a762060 100644 --- a/dune-project +++ b/dune-project @@ -1,5 +1,5 @@ (lang dune 2.8) -(version 1.0.2) +(version 1.0.3) (name cry) (source (github savonet/ocaml-cry)) (license GPL-2.0-only) diff --git a/src/cry.ml b/src/cry.ml index 7c6b223..e68200f 100644 --- a/src/cry.ml +++ b/src/cry.ml @@ -163,14 +163,15 @@ let connect_sockaddr ?bind_address ?timeout sockaddr = Printexc.raise_with_backtrace exn bt); let do_timeout = timeout <> None in let check_timeout () = - match timeout with - | Some timeout -> - (* Block in a select call for [timeout] seconds. *) - let _, w, _ = select [] [socket] [] timeout in - if w = [] then raise Timeout; + let timeout = Option.get timeout in + (* Block in a select call for [timeout] seconds. *) + let _, w, _ = select [] [socket] [] timeout in + if w = [] then raise Timeout; + match Unix.getsockopt_error socket with + | Some err -> raise (Unix.Unix_error (err, "connect", "")) + | None -> Unix.clear_nonblock socket; socket - | None -> assert false in let finish () = try