SSL_write 3 2002-07-30 0.9.9-dev OpenSSL

NAME

SSL_write - write bytes to a TLS/SSL connection.

LIBRARY

libcrypto, -lcrypto

SYNOPSIS


 #include 


 int SSL_write(SSL *ssl, const void *buf, int num);

DESCRIPTION

_S_S_L___w_r_i_t_e_(_) writes nnuumm bytes from the buffer bbuuff into the specified ssssll connection.

NOTES

If necessary, _S_S_L___w_r_i_t_e_(_) will negotiate a TLS/SSL session, if not already explicitly performed by _S_S_L___c_o_n_n_e_c_t(3) or _S_S_L___a_c_c_e_p_t(3). If the peer requests a re-negotiation, it will be performed transparently during the _S_S_L___w_r_i_t_e_(_) operation. The behaviour of _S_S_L___w_r_i_t_e_(_) depends on the underlying BIO.

For the transparent negotiation to succeed, the ssssll must have been initialized to client or server mode. This is being done by calling _S_S_L___s_e_t___c_o_n_n_e_c_t___s_t_a_t_e(3) or _S_S_L___s_e_t___a_c_c_e_p_t___s_t_a_t_e_(_) before the first call to an _S_S_L___r_e_a_d(3) or _S_S_L___w_r_i_t_e_(_) function.

If the underlying BIO is bblloocckkiinngg, _S_S_L___w_r_i_t_e_(_) will only return, once the write operation has been finished or an error occurred, except when a renegotiation take place, in which case a SSL_ERROR_WANT_READ may occur. This behaviour can be controlled with the SSL_MODE_AUTO_RETRY flag of the _S_S_L___C_T_X___s_e_t___m_o_d_e(3) call.

If the underlying BIO is nnoonn--bblloocckkiinngg, _S_S_L___w_r_i_t_e_(_) will also return, when the underlying BIO could not satisfy the needs of _S_S_L___w_r_i_t_e_(_) to continue the operation. In this case a call to _S_S_L___g_e_t___e_r_r_o_r(3) with the return value of _S_S_L___w_r_i_t_e_(_) will yield SSSSLL__EERRRROORR__WWAANNTT__RREEAADD or SSSSLL__EERRRROORR__WWAANNTT__WWRRIITTEE. As at any time a re-negotiation is possible, a call to _S_S_L___w_r_i_t_e_(_) can also cause read operations! The calling process then must repeat the call after taking appropriate action to satisfy the needs of _S_S_L___w_r_i_t_e_(_). The action depends on the underlying BIO. When using a non-blocking socket, nothing is to be done, but _s_e_l_e_c_t_(_) can be used to check for the required condition. When using a buffering BIO, like a BIO pair, data must be written into or retrieved out of the BIO before being able to continue.

_S_S_L___w_r_i_t_e_(_) will only return with success, when the complete contents of bbuuff of length nnuumm has been written. This default behaviour can be changed with the SSL_MODE_ENABLE_PARTIAL_WRITE option of _S_S_L___C_T_X___s_e_t___m_o_d_e(3). When this flag is set, _S_S_L___w_r_i_t_e_(_) will also return with success, when a partial write has been successfully completed. In this case the _S_S_L___w_r_i_t_e_(_) operation is considered completed. The bytes are sent and a new _S_S_L___w_r_i_t_e_(_) operation with a new buffer (with the already sent bytes removed) must be started. A partial write is performed with the size of a message block, which is 16kB for SSLv3/TLSv1.

WARNING

When an _S_S_L___w_r_i_t_e_(_) operation has to be repeated because of SSSSLL__EERRRROORR__WWAANNTT__RREEAADD or SSSSLL__EERRRROORR__WWAANNTT__WWRRIITTEE, it must be repeated with the same arguments.

When calling _S_S_L___w_r_i_t_e_(_) with num=0 bytes to be sent the behaviour is undefined.

RETURN VALUES

The following return values can occur:
>0 The write operation was successful, the return value is the number of
bytes actually written to the TLS/SSL connection.
0 The write operation was not successful. Probably the underlying connection
was closed. Call _S_S_L___g_e_t___e_r_r_o_r_(_) with the return value rreett to find out, whether an error occurred or the connection was shut down cleanly (SSL_ERROR_ZERO_RETURN).

SSLv2 (deprecated) does not support a shutdown alert protocol, so it can only be detected, whether the underlying connection was closed. It cannot be checked, why the closure happened.
<0 The write operation was not successful, because either an error occurred
or action must be taken by the calling process. Call _S_S_L___g_e_t___e_r_r_o_r_(_) with the return value rreett to find out the reason.

SEE ALSO

_S_S_L___g_e_t___e_r_r_o_r(3), _S_S_L___r_e_a_d(3), _S_S_L___C_T_X___s_e_t___m_o_d_e(3), _S_S_L___C_T_X___n_e_w(3), _S_S_L___c_o_n_n_e_c_t(3), _S_S_L___a_c_c_e_p_t(3) _S_S_L___s_e_t___c_o_n_n_e_c_t___s_t_a_t_e(3), _s_s_l(3), _o_p_e_n_s_s_l___b_i_o(3)