xref: /minix3/crypto/external/bsd/openssl/dist/doc/ssl/SSL_write.pod (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1ebfedea0SLionel Sambuc=pod
2ebfedea0SLionel Sambuc
3ebfedea0SLionel Sambuc=head1 NAME
4ebfedea0SLionel Sambuc
5ebfedea0SLionel SambucSSL_write - write bytes to a TLS/SSL connection.
6ebfedea0SLionel Sambuc
7ebfedea0SLionel Sambuc=head1 SYNOPSIS
8ebfedea0SLionel Sambuc
9ebfedea0SLionel Sambuc #include <openssl/ssl.h>
10ebfedea0SLionel Sambuc
11ebfedea0SLionel Sambuc int SSL_write(SSL *ssl, const void *buf, int num);
12ebfedea0SLionel Sambuc
13ebfedea0SLionel Sambuc=head1 DESCRIPTION
14ebfedea0SLionel Sambuc
15ebfedea0SLionel SambucSSL_write() writes B<num> bytes from the buffer B<buf> into the specified
16ebfedea0SLionel SambucB<ssl> connection.
17ebfedea0SLionel Sambuc
18ebfedea0SLionel Sambuc=head1 NOTES
19ebfedea0SLionel Sambuc
20ebfedea0SLionel SambucIf necessary, SSL_write() will negotiate a TLS/SSL session, if
21ebfedea0SLionel Sambucnot already explicitly performed by L<SSL_connect(3)|SSL_connect(3)> or
22ebfedea0SLionel SambucL<SSL_accept(3)|SSL_accept(3)>. If the
23ebfedea0SLionel Sambucpeer requests a re-negotiation, it will be performed transparently during
24ebfedea0SLionel Sambucthe SSL_write() operation. The behaviour of SSL_write() depends on the
25ebfedea0SLionel Sambucunderlying BIO.
26ebfedea0SLionel Sambuc
27ebfedea0SLionel SambucFor the transparent negotiation to succeed, the B<ssl> must have been
28ebfedea0SLionel Sambucinitialized to client or server mode. This is being done by calling
29ebfedea0SLionel SambucL<SSL_set_connect_state(3)|SSL_set_connect_state(3)> or SSL_set_accept_state()
30ebfedea0SLionel Sambucbefore the first call to an L<SSL_read(3)|SSL_read(3)> or SSL_write() function.
31ebfedea0SLionel Sambuc
32ebfedea0SLionel SambucIf the underlying BIO is B<blocking>, SSL_write() will only return, once the
33ebfedea0SLionel Sambucwrite operation has been finished or an error occurred, except when a
34ebfedea0SLionel Sambucrenegotiation take place, in which case a SSL_ERROR_WANT_READ may occur.
35ebfedea0SLionel SambucThis behaviour can be controlled with the SSL_MODE_AUTO_RETRY flag of the
36ebfedea0SLionel SambucL<SSL_CTX_set_mode(3)|SSL_CTX_set_mode(3)> call.
37ebfedea0SLionel Sambuc
38ebfedea0SLionel SambucIf the underlying BIO is B<non-blocking>, SSL_write() will also return,
39ebfedea0SLionel Sambucwhen the underlying BIO could not satisfy the needs of SSL_write()
40ebfedea0SLionel Sambucto continue the operation. In this case a call to
41ebfedea0SLionel SambucL<SSL_get_error(3)|SSL_get_error(3)> with the
42ebfedea0SLionel Sambucreturn value of SSL_write() will yield B<SSL_ERROR_WANT_READ> or
43ebfedea0SLionel SambucB<SSL_ERROR_WANT_WRITE>. As at any time a re-negotiation is possible, a
44ebfedea0SLionel Sambuccall to SSL_write() can also cause read operations! The calling process
45ebfedea0SLionel Sambucthen must repeat the call after taking appropriate action to satisfy the
46ebfedea0SLionel Sambucneeds of SSL_write(). The action depends on the underlying BIO. When using a
47ebfedea0SLionel Sambucnon-blocking socket, nothing is to be done, but select() can be used to check
48ebfedea0SLionel Sambucfor the required condition. When using a buffering BIO, like a BIO pair, data
49ebfedea0SLionel Sambucmust be written into or retrieved out of the BIO before being able to continue.
50ebfedea0SLionel Sambuc
51ebfedea0SLionel SambucSSL_write() will only return with success, when the complete contents
52ebfedea0SLionel Sambucof B<buf> of length B<num> has been written. This default behaviour
53ebfedea0SLionel Sambuccan be changed with the SSL_MODE_ENABLE_PARTIAL_WRITE option of
54ebfedea0SLionel SambucL<SSL_CTX_set_mode(3)|SSL_CTX_set_mode(3)>. When this flag is set,
55ebfedea0SLionel SambucSSL_write() will also return with success, when a partial write has been
56ebfedea0SLionel Sambucsuccessfully completed. In this case the SSL_write() operation is considered
57ebfedea0SLionel Sambuccompleted. The bytes are sent and a new SSL_write() operation with a new
58ebfedea0SLionel Sambucbuffer (with the already sent bytes removed) must be started.
59ebfedea0SLionel SambucA partial write is performed with the size of a message block, which is
60ebfedea0SLionel Sambuc16kB for SSLv3/TLSv1.
61ebfedea0SLionel Sambuc
62ebfedea0SLionel Sambuc=head1 WARNING
63ebfedea0SLionel Sambuc
64ebfedea0SLionel SambucWhen an SSL_write() operation has to be repeated because of
65ebfedea0SLionel SambucB<SSL_ERROR_WANT_READ> or B<SSL_ERROR_WANT_WRITE>, it must be repeated
66ebfedea0SLionel Sambucwith the same arguments.
67ebfedea0SLionel Sambuc
68ebfedea0SLionel SambucWhen calling SSL_write() with num=0 bytes to be sent the behaviour is
69ebfedea0SLionel Sambucundefined.
70ebfedea0SLionel Sambuc
71ebfedea0SLionel Sambuc=head1 RETURN VALUES
72ebfedea0SLionel Sambuc
73ebfedea0SLionel SambucThe following return values can occur:
74ebfedea0SLionel Sambuc
75ebfedea0SLionel Sambuc=over 4
76ebfedea0SLionel Sambuc
77ebfedea0SLionel Sambuc=item E<gt>0
78ebfedea0SLionel Sambuc
79ebfedea0SLionel SambucThe write operation was successful, the return value is the number of
80ebfedea0SLionel Sambucbytes actually written to the TLS/SSL connection.
81ebfedea0SLionel Sambuc
82*0a6a1f1dSLionel Sambuc=item Z<>0
83ebfedea0SLionel Sambuc
84ebfedea0SLionel SambucThe write operation was not successful. Probably the underlying connection
85ebfedea0SLionel Sambucwas closed. Call SSL_get_error() with the return value B<ret> to find out,
86ebfedea0SLionel Sambucwhether an error occurred or the connection was shut down cleanly
87ebfedea0SLionel Sambuc(SSL_ERROR_ZERO_RETURN).
88ebfedea0SLionel Sambuc
89ebfedea0SLionel SambucSSLv2 (deprecated) does not support a shutdown alert protocol, so it can
90ebfedea0SLionel Sambuconly be detected, whether the underlying connection was closed. It cannot
91ebfedea0SLionel Sambucbe checked, why the closure happened.
92ebfedea0SLionel Sambuc
93ebfedea0SLionel Sambuc=item E<lt>0
94ebfedea0SLionel Sambuc
95ebfedea0SLionel SambucThe write operation was not successful, because either an error occurred
96ebfedea0SLionel Sambucor action must be taken by the calling process. Call SSL_get_error() with the
97ebfedea0SLionel Sambucreturn value B<ret> to find out the reason.
98ebfedea0SLionel Sambuc
99ebfedea0SLionel Sambuc=back
100ebfedea0SLionel Sambuc
101ebfedea0SLionel Sambuc=head1 SEE ALSO
102ebfedea0SLionel Sambuc
103ebfedea0SLionel SambucL<SSL_get_error(3)|SSL_get_error(3)>, L<SSL_read(3)|SSL_read(3)>,
104ebfedea0SLionel SambucL<SSL_CTX_set_mode(3)|SSL_CTX_set_mode(3)>, L<SSL_CTX_new(3)|SSL_CTX_new(3)>,
105ebfedea0SLionel SambucL<SSL_connect(3)|SSL_connect(3)>, L<SSL_accept(3)|SSL_accept(3)>
106ebfedea0SLionel SambucL<SSL_set_connect_state(3)|SSL_set_connect_state(3)>,
107ebfedea0SLionel SambucL<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>
108ebfedea0SLionel Sambuc
109ebfedea0SLionel Sambuc=cut
110