def _shutdown(self, manual):
if self._ssl is None:<EOL><INDENT>return<EOL><DEDENT>while True:<EOL><INDENT>result = libssl.SSL_shutdown(self._ssl)<EOL>try:<EOL><INDENT>self._raw_write()<EOL><DEDENT>except (TLSDisconnectError):<EOL><INDENT>pass<EOL><DEDENT>if result >= <NUM_LIT:0>:<EOL><INDENT>break<EOL><DEDENT>if result < <NUM_LIT:0>:<EOL><INDENT>error = libssl.SSL_get_error(self._ssl, result)<EOL>if error == LibsslConst.SSL_ERROR_WANT_READ:<EOL><INDENT>if self._raw_read() != b'<STR_LIT>':<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>elif error == LibsslConst.SSL_ERROR_WANT_WRITE:<EOL><INDENT>self._raw_write()<EOL>continue<EOL><DEDENT>else:<EOL><INDENT>handle_openssl_error(<NUM_LIT:0>, TLSError)<EOL><DEDENT><DEDENT><DEDENT>if manual:<EOL><INDENT>self._local_closed = True<EOL><DEDENT>libssl.SSL_free(self._ssl)<EOL>self._ssl = None<EOL>self._rbio = None<EOL>self._wbio = None<EOL>try:<EOL><INDENT>self._socket.shutdown(socket_.SHUT_RDWR)<EOL><DEDENT>except (socket_.error):<EOL><INDENT>pass<EOL><DEDENT>
Shuts down the TLS session and then shuts down the underlying socket

:param manual:
    A boolean if the connection was manually shutdown