From 0f229874a249c255c349168b015c3762572ec01a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Pei=C3=9Fl?= Date: Mon, 10 Oct 2022 18:30:58 +0200 Subject: [PATCH] net.mbedtls: add explicit closing of the tcp connection in the shutdown method (#16027) --- vlib/net/mbedtls/ssl_connection.v | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vlib/net/mbedtls/ssl_connection.v b/vlib/net/mbedtls/ssl_connection.v index ff887ba9dc..3a3b2255d9 100644 --- a/vlib/net/mbedtls/ssl_connection.v +++ b/vlib/net/mbedtls/ssl_connection.v @@ -37,6 +37,8 @@ mut: handle int duration time.Duration opened bool + + owns_socket bool } [params] @@ -77,6 +79,15 @@ pub fn (mut s SSLConn) shutdown() ? { } C.mbedtls_ssl_free(&s.ssl) C.mbedtls_ssl_config_free(&s.conf) + if s.owns_socket { + $if windows { + C.shutdown(s.handle, C.SD_BOTH) + net.socket_error(C.closesocket(s.handle))? + } $else { + C.shutdown(s.handle, C.SHUT_RDWR) + net.socket_error(C.close(s.handle))? + } + } } // connect to server using mbedtls @@ -173,6 +184,7 @@ pub fn (mut s SSLConn) connect(mut tcp_conn net.TcpConn, hostname string) ? { // dial opens an ssl connection on hostname:port pub fn (mut s SSLConn) dial(hostname string, port int) ? { + s.owns_socket = true if s.opened { return error('ssl connection already open') }