Skip to content

Commit b40a307

Browse files
committed
Lwt_ssl.*_channel_of_decr now close the socket when the channel is closed
Ignore-this: a830f5819ec08fb996cc271d03267fce darcs-hash:20121123194144-c41ad-21f7ce5d97a32f642dec2cc0f421ab6ead727bab
1 parent 4aaf347 commit b40a307

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/ssl/lwt_ssl.ml

+19-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* 02111-1307, USA.
2222
*)
2323

24+
let (>>=) = Lwt.bind
25+
2426
type t =
2527
Plain
2628
| SSL of Ssl.socket
@@ -150,12 +152,6 @@ let wait_write (fd, s) =
150152
Plain -> Lwt_unix.wait_write fd
151153
| SSL _ -> Lwt_unix.yield ()
152154

153-
let out_channel_of_descr s =
154-
Lwt_io.make ~mode:Lwt_io.output (fun buf pos len -> write_bytes s buf pos len)
155-
156-
let in_channel_of_descr s =
157-
Lwt_io.make ~mode:Lwt_io.input (fun buf pos len -> read_bytes s buf pos len)
158-
159155
let ssl_shutdown (fd, s) =
160156
match s with
161157
Plain -> Lwt.return ()
@@ -167,6 +163,23 @@ let close (fd, _) = Lwt_unix.close fd
167163

168164
let abort (fd, _) = Lwt_unix.abort fd
169165

166+
let shutdown_and_close s =
167+
ssl_shutdown s >>= fun () ->
168+
Lwt.wrap2 shutdown s Unix.SHUTDOWN_ALL >>= fun () ->
169+
close s
170+
171+
let out_channel_of_descr s =
172+
Lwt_io.make
173+
~mode:Lwt_io.output
174+
~close:(fun () -> shutdown_and_close s)
175+
(fun buf pos len -> write_bytes s buf pos len)
176+
177+
let in_channel_of_descr s =
178+
Lwt_io.make
179+
~mode:Lwt_io.input
180+
~close:(fun () -> shutdown_and_close s)
181+
(fun buf pos len -> read_bytes s buf pos len)
182+
170183
let get_fd (fd,socket) =
171184
match socket with
172185
| Plain -> Lwt_unix.unix_file_descr fd

0 commit comments

Comments
 (0)