File tree Expand file tree Collapse file tree 3 files changed +23
-7
lines changed Expand file tree Collapse file tree 3 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -276,7 +276,7 @@ external accept : socket -> unit = "ocaml_ssl_accept"
276
276
277
277
external flush : socket -> unit = " ocaml_ssl_flush"
278
278
279
- external shutdown : socket -> unit = " ocaml_ssl_shutdown"
279
+ external shutdown : socket -> bool = " ocaml_ssl_shutdown"
280
280
281
281
let open_connection_with_context context sockaddr =
282
282
let domain =
@@ -296,6 +296,12 @@ let open_connection_with_context context sockaddr =
296
296
let open_connection ssl_method sockaddr =
297
297
open_connection_with_context (create_context ssl_method Client_context ) sockaddr
298
298
299
+ let close_notify = shutdown
300
+
301
+ let rec shutdown sock =
302
+ if not (close_notify sock)
303
+ then shutdown sock
304
+
299
305
let shutdown_connection = shutdown
300
306
301
307
let output_string ssl s =
Original file line number Diff line number Diff line change @@ -421,7 +421,13 @@ val accept : socket -> unit
421
421
(* * Flush an SSL connection. *)
422
422
val flush : socket -> unit
423
423
424
- (* * Close an SSL connection. *)
424
+ (* * send close notify to the peer. This is SSL_shutdown(3).
425
+ * returns [true] if shutdown is finished, [false] in case [close_notify]
426
+ * needs to be called a second time. *)
427
+ val close_notify : socket -> bool
428
+
429
+ (* * Close a SSL connection.
430
+ * Send close notify to the peer and wait for close notify from peer. *)
425
431
val shutdown : socket -> unit
426
432
427
433
Original file line number Diff line number Diff line change @@ -1660,12 +1660,16 @@ CAMLprim value ocaml_ssl_shutdown(value socket)
1660
1660
1661
1661
caml_enter_blocking_section ();
1662
1662
ret = SSL_shutdown (ssl );
1663
- if (!ret )
1664
- SSL_shutdown (ssl );
1665
1663
caml_leave_blocking_section ();
1666
- /* close(SSL_get_fd(SSL_val(socket))); */
1667
-
1668
- CAMLreturn (Val_unit );
1664
+ switch (ret ) {
1665
+ case 0 :
1666
+ case 1 :
1667
+ /* close(SSL_get_fd(SSL_val(socket))); */
1668
+ CAMLreturn (Val_int (ret ));
1669
+ default :
1670
+ ret = SSL_get_error (ssl , ret );
1671
+ caml_raise_with_arg (* caml_named_value ("ssl_exn_connection_error" ), Val_int (ret ));
1672
+ }
1669
1673
}
1670
1674
1671
1675
/* ======================================================== */
You can’t perform that action at this time.
0 commit comments