1SSL_WRITE(3ossl)                    OpenSSL                   SSL_WRITE(3ossl)
2
3
4

NAME

6       SSL_write_ex, SSL_write, SSL_sendfile - write bytes to a TLS/SSL
7       connection
8

SYNOPSIS

10        #include <openssl/ssl.h>
11
12        ossl_ssize_t SSL_sendfile(SSL *s, int fd, off_t offset, size_t size, int flags);
13        int SSL_write_ex(SSL *s, const void *buf, size_t num, size_t *written);
14        int SSL_write(SSL *ssl, const void *buf, int num);
15

DESCRIPTION

17       SSL_write_ex() and SSL_write() write num bytes from the buffer buf into
18       the specified ssl connection. On success SSL_write_ex() will store the
19       number of bytes written in *written.
20
21       SSL_sendfile() writes size bytes from offset offset in the file
22       descriptor fd to the specified SSL connection s. This function provides
23       efficient zero-copy semantics. SSL_sendfile() is available only when
24       Kernel TLS is enabled, which can be checked by calling
25       BIO_get_ktls_send().  It is provided here to allow users to maintain
26       the same interface.  The meaning of flags is platform dependent.
27       Currently, under Linux it is ignored.
28

NOTES

30       In the paragraphs below a "write function" is defined as one of either
31       SSL_write_ex(), or SSL_write().
32
33       If necessary, a write function will negotiate a TLS/SSL session, if not
34       already explicitly performed by SSL_connect(3) or SSL_accept(3). If the
35       peer requests a re-negotiation, it will be performed transparently
36       during the write function operation. The behaviour of the write
37       functions depends on the underlying BIO.
38
39       For the transparent negotiation to succeed, the ssl must have been
40       initialized to client or server mode. This is being done by calling
41       SSL_set_connect_state(3) or SSL_set_accept_state() before the first
42       call to a write function.
43
44       If the underlying BIO is blocking, the write functions will only
45       return, once the write operation has been finished or an error
46       occurred.
47
48       If the underlying BIO is nonblocking the write functions will also
49       return when the underlying BIO could not satisfy the needs of the
50       function to continue the operation. In this case a call to
51       SSL_get_error(3) with the return value of the write function will yield
52       SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. As at any time a re-
53       negotiation is possible, a call to a write function can also cause read
54       operations! The calling process then must repeat the call after taking
55       appropriate action to satisfy the needs of the write function. The
56       action depends on the underlying BIO. When using a nonblocking socket,
57       nothing is to be done, but select() can be used to check for the
58       required condition. When using a buffering BIO, like a BIO pair, data
59       must be written into or retrieved out of the BIO before being able to
60       continue.
61
62       The write functions will only return with success when the complete
63       contents of buf of length num has been written. This default behaviour
64       can be changed with the SSL_MODE_ENABLE_PARTIAL_WRITE option of
65       SSL_CTX_set_mode(3). When this flag is set the write functions will
66       also return with success when a partial write has been successfully
67       completed. In this case the write function operation is considered
68       completed. The bytes are sent and a new write call with a new buffer
69       (with the already sent bytes removed) must be started. A partial write
70       is performed with the size of a message block, which is 16kB.
71

WARNINGS

73       When a write function call has to be repeated because SSL_get_error(3)
74       returned SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE, it must be
75       repeated with the same arguments.  The data that was passed might have
76       been partially processed.  When SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER was
77       set using SSL_CTX_set_mode(3) the pointer can be different, but the
78       data and length should still be the same.
79
80       You should not call SSL_write() with num=0, it will return an error.
81       SSL_write_ex() can be called with num=0, but will not send application
82       data to the peer.
83

RETURN VALUES

85       SSL_write_ex() will return 1 for success or 0 for failure. Success
86       means that all requested application data bytes have been written to
87       the SSL connection or, if SSL_MODE_ENABLE_PARTIAL_WRITE is in use, at
88       least 1 application data byte has been written to the SSL connection.
89       Failure means that not all the requested bytes have been written yet
90       (if SSL_MODE_ENABLE_PARTIAL_WRITE is not in use) or no bytes could be
91       written to the SSL connection (if SSL_MODE_ENABLE_PARTIAL_WRITE is in
92       use). Failures can be retryable (e.g. the network write buffer has
93       temporarily filled up) or non-retryable (e.g. a fatal network error).
94       In the event of a failure call SSL_get_error(3) to find out the reason
95       which indicates whether the call is retryable or not.
96
97       For SSL_write() the following return values can occur:
98
99       > 0 The write operation was successful, the return value is the number
100           of bytes actually written to the TLS/SSL connection.
101
102       <= 0
103           The write operation was not successful, because either the
104           connection was closed, an error occurred or action must be taken by
105           the calling process.  Call SSL_get_error() with the return value
106           ret to find out the reason.
107
108           Old documentation indicated a difference between 0 and -1, and that
109           -1 was retryable.  You should instead call SSL_get_error() to find
110           out if it's retryable.
111
112       For SSL_sendfile(), the following return values can occur:
113
114       >= 0
115           The write operation was successful, the return value is the number
116           of bytes of the file written to the TLS/SSL connection. The return
117           value can be less than size for a partial write.
118
119       < 0 The write operation was not successful, because either the
120           connection was closed, an error occurred or action must be taken by
121           the calling process.  Call SSL_get_error() with the return value to
122           find out the reason.
123

SEE ALSO

125       SSL_get_error(3), SSL_read_ex(3), SSL_read(3) SSL_CTX_set_mode(3),
126       SSL_CTX_new(3), SSL_connect(3), SSL_accept(3) SSL_set_connect_state(3),
127       BIO_ctrl(3), ssl(7), bio(7)
128

HISTORY

130       The SSL_write_ex() function was added in OpenSSL 1.1.1.  The
131       SSL_sendfile() function was added in OpenSSL 3.0.
132
134       Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
135
136       Licensed under the Apache License 2.0 (the "License").  You may not use
137       this file except in compliance with the License.  You can obtain a copy
138       in the file LICENSE in the source distribution or at
139       <https://www.openssl.org/source/license.html>.
140
141
142
1433.0.9                             2023-07-27                  SSL_WRITE(3ossl)
Impressum