1SSL_WRITE(3) OpenSSL SSL_WRITE(3)
2
3
4
6 SSL_write_ex, SSL_write - write bytes to a TLS/SSL connection
7
9 #include <openssl/ssl.h>
10
11 int SSL_write_ex(SSL *s, const void *buf, size_t num, size_t *written);
12 int SSL_write(SSL *ssl, const void *buf, int num);
13
15 SSL_write_ex() and SSL_write() write num bytes from the buffer buf into
16 the specified ssl connection. On success SSL_write_ex() will store the
17 number of bytes written in *written.
18
20 In the paragraphs below a "write function" is defined as one of either
21 SSL_write_ex(), or SSL_write().
22
23 If necessary, a write function will negotiate a TLS/SSL session, if not
24 already explicitly performed by SSL_connect(3) or SSL_accept(3). If the
25 peer requests a re-negotiation, it will be performed transparently
26 during the write function operation. The behaviour of the write
27 functions depends on the underlying BIO.
28
29 For the transparent negotiation to succeed, the ssl must have been
30 initialized to client or server mode. This is being done by calling
31 SSL_set_connect_state(3) or SSL_set_accept_state() before the first
32 call to a write function.
33
34 If the underlying BIO is blocking, the write functions will only
35 return, once the write operation has been finished or an error
36 occurred.
37
38 If the underlying BIO is nonblocking the write functions will also
39 return when the underlying BIO could not satisfy the needs of the
40 function to continue the operation. In this case a call to
41 SSL_get_error(3) with the return value of the write function will yield
42 SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. As at any time a re-
43 negotiation is possible, a call to a write function can also cause read
44 operations! The calling process then must repeat the call after taking
45 appropriate action to satisfy the needs of the write function. The
46 action depends on the underlying BIO. When using a nonblocking socket,
47 nothing is to be done, but select() can be used to check for the
48 required condition. When using a buffering BIO, like a BIO pair, data
49 must be written into or retrieved out of the BIO before being able to
50 continue.
51
52 The write functions will only return with success when the complete
53 contents of buf of length num has been written. This default behaviour
54 can be changed with the SSL_MODE_ENABLE_PARTIAL_WRITE option of
55 SSL_CTX_set_mode(3). When this flag is set the write functions will
56 also return with success when a partial write has been successfully
57 completed. In this case the write function operation is considered
58 completed. The bytes are sent and a new write call with a new buffer
59 (with the already sent bytes removed) must be started. A partial write
60 is performed with the size of a message block, which is 16kB.
61
63 When a write function call has to be repeated because SSL_get_error(3)
64 returned SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE, it must be
65 repeated with the same arguments. The data that was passed might have
66 been partially processed. When SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER was
67 set using SSL_CTX_set_mode(3) the pointer can be different, but the
68 data and length should still be the same.
69
70 You should not call SSL_write() with num=0, it will return an error.
71 SSL_write_ex() can be called with num=0, but will not send application
72 data to the peer.
73
75 SSL_write_ex() will return 1 for success or 0 for failure. Success
76 means that all requested application data bytes have been written to
77 the SSL connection or, if SSL_MODE_ENABLE_PARTIAL_WRITE is in use, at
78 least 1 application data byte has been written to the SSL connection.
79 Failure means that not all the requested bytes have been written yet
80 (if SSL_MODE_ENABLE_PARTIAL_WRITE is not in use) or no bytes could be
81 written to the SSL connection (if SSL_MODE_ENABLE_PARTIAL_WRITE is in
82 use). Failures can be retryable (e.g. the network write buffer has
83 temporarily filled up) or non-retryable (e.g. a fatal network error).
84 In the event of a failure call SSL_get_error(3) to find out the reason
85 which indicates whether the call is retryable or not.
86
87 For SSL_write() the following return values can occur:
88
89 > 0 The write operation was successful, the return value is the number
90 of bytes actually written to the TLS/SSL connection.
91
92 <= 0
93 The write operation was not successful, because either the
94 connection was closed, an error occurred or action must be taken by
95 the calling process. Call SSL_get_error() with the return value
96 ret to find out the reason.
97
98 Old documentation indicated a difference between 0 and -1, and that
99 -1 was retryable. You should instead call SSL_get_error() to find
100 out if it's retryable.
101
103 SSL_get_error(3), SSL_read_ex(3), SSL_read(3) SSL_CTX_set_mode(3),
104 SSL_CTX_new(3), SSL_connect(3), SSL_accept(3) SSL_set_connect_state(3),
105 ssl(7), bio(7)
106
108 The SSL_write_ex() function was added in OpenSSL 1.1.1.
109
111 Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
112
113 Licensed under the OpenSSL license (the "License"). You may not use
114 this file except in compliance with the License. You can obtain a copy
115 in the file LICENSE in the source distribution or at
116 <https://www.openssl.org/source/license.html>.
117
118
119
1201.1.1q 2023-02-06 SSL_WRITE(3)