Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/lwt_ssl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,23 @@ let ssl_shutdown (fd, s) =
Plain -> Lwt.return_unit
| SSL s -> repeat_call fd (fun () -> Ssl.shutdown s)

let shutdown (fd, _) cmd = Lwt_unix.shutdown fd cmd
let shutdown (fd, _) cmd =
Lwt.finalize
(fun () ->
Lwt.catch
(fun () ->
Lwt_unix.shutdown fd cmd;
Lwt.return_unit)
(function
(* Occurs if the peer closes the connection first. *)
| Unix.Unix_error (Unix.ENOTCONN, _, _) -> Lwt.return_unit
| exn -> Lwt.reraise exn)[@ocaml.warning "-4"])
(fun () ->
Lwt_unix.close fd)

let close_notify = function
| (_, Plain) as s ->
shutdown s Unix.SHUTDOWN_SEND;
shutdown s Unix.SHUTDOWN_SEND >>= fun () ->
Lwt.return_true
| (fd, SSL s) ->
repeat_call fd (fun () -> Ssl.close_notify s)
Expand All @@ -181,7 +193,7 @@ let abort (fd, _) = Lwt_unix.abort fd

let shutdown_and_close s =
ssl_shutdown s >>= fun () ->
Lwt.wrap2 shutdown s Unix.SHUTDOWN_ALL >>= fun () ->
shutdown s Unix.SHUTDOWN_ALL >>= fun () ->
close s

let out_channel_of_descr ?buffer s =
Expand Down
2 changes: 1 addition & 1 deletion src/lwt_ssl.mli
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ val write_bytes : socket -> Lwt_bytes.t -> int -> int -> int Lwt.t
val wait_read : socket -> unit Lwt.t
val wait_write : socket -> unit Lwt.t

val shutdown : socket -> Unix.shutdown_command -> unit
val shutdown : socket -> Unix.shutdown_command -> unit Lwt.t
val close : socket -> unit Lwt.t

val in_channel_of_descr : ?buffer:Lwt_bytes.t -> socket -> Lwt_io.input_channel
Expand Down