Skip to content

Commit

Permalink
Raise a proper error when non-blocking connection fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Jan 10, 2024
1 parent 2009c7b commit 8afc835
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion cry.opam
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
13 changes: 7 additions & 6 deletions src/cry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8afc835

Please sign in to comment.