Skip to content

Commit

Permalink
Make sure close always closes the socket.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Aug 29, 2023
1 parent f9bf5ac commit 58e4094
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
1.0.2 (unreleased)
======
* Use `poll` for select when available.
* Make sure `close` call always closes the socket.

1.0.1 (2023-07-01)
=====
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.1"
version: "1.0.2"
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
17 changes: 8 additions & 9 deletions src/cry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ let poll r w e timeout =
let r, w, e = poll r w e timeout in
(Array.to_list r, Array.to_list w, Array.to_list e)

let select =
match Sys.os_type with
| "Unix" -> poll
| _ -> Unix.select
let select = match Sys.os_type with "Unix" -> poll | _ -> Unix.select

type error =
| Create of exn
Expand Down Expand Up @@ -341,11 +338,13 @@ let write_data ~timeout ?(offset = 0) ?length (socket : socket) request =
let close x =
try
let c = get_connection_data x in
if x.chunked then write_data ~timeout:x.timeout c.socket "0\r\n\r\n";
c.socket#close;
x.chunked <- false;
x.icy_cap <- false;
x.status <- PrivDisconnected
Fun.protect
~finally:(fun () -> c.socket#close)
(fun () ->
if x.chunked then write_data ~timeout:x.timeout c.socket "0\r\n\r\n";
x.chunked <- false;
x.icy_cap <- false;
x.status <- PrivDisconnected)
with
| Error _ as e -> raise e
| e -> raise (Error (Close e))
Expand Down

0 comments on commit 58e4094

Please sign in to comment.