def write(self, data):
data_len = len(data)<EOL>while data_len:<EOL><INDENT>if self._ssl is None:<EOL><INDENT>self._raise_closed()<EOL><DEDENT>result = libssl.SSL_write(self._ssl, data, data_len)<EOL>self._raw_write()<EOL>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>raise_disconnection()<EOL><DEDENT>elif error == LibsslConst.SSL_ERROR_WANT_WRITE:<EOL><INDENT>self._raw_write()<EOL>continue<EOL><DEDENT>elif error == LibsslConst.SSL_ERROR_ZERO_RETURN:<EOL><INDENT>self._gracefully_closed = True<EOL>self._shutdown(False)<EOL>self._raise_closed()<EOL><DEDENT>else:<EOL><INDENT>handle_openssl_error(<NUM_LIT:0>, TLSError)<EOL><DEDENT><DEDENT>data = data[result:]<EOL>data_len = len(data)<EOL><DEDENT>
Writes data to the TLS-wrapped socket

:param data:
    A byte string to write to the socket

:raises:
    socket.socket - when a non-TLS socket error occurs
    oscrypto.errors.TLSError - when a TLS-related error occurs
    ValueError - when any of the parameters contain an invalid value
    TypeError - when any of the parameters are of the wrong type
    OSError - when an error is returned by the OS crypto library