Lines Matching +full:write +full:- +full:back
1 .\" -*- mode: troff; coding: utf-8 -*-
57 .IX Title "OSSL-GUIDE-TLS-CLIENT-NON-BLOCK 7ossl"
58 .TH OSSL-GUIDE-TLS-CLIENT-NON-BLOCK 7ossl 2025-09-30 3.5.4 OpenSSL
64 ossl\-guide\-tls\-client\-non\-block
65 \&\- OpenSSL Guide: Writing a simple nonblocking TLS client
69 \&\fBossl\-guide\-tls\-client\-block\fR\|(7) page which demonstrates how to write a simple
75 \&\fBtls\-client\-non\-block.c\fR. It is also available online at
76 <https://github.com/openssl/openssl/blob/master/demos/guide/tls\-client\-non\-block.c>.
81 write at the moment. This can simplify the development of code because you do
85 to go and do other tasks whilst the socket is unable to read/write, for example
88 With a nonblocking socket attempting to read or write to a socket that is
89 currently unable to read or write will return immediately with a non-fatal
95 \&\fBossl\-guide\-tls\-client\-block\fR\|(7) page we assume that you are familiar with it
107 \& sock = \-1;
118 we want to read or write to the socket, but we are currently unable to. In fact
121 application has to do, it must also be prepared to come back and retry the
129 attempting to write the text "Hello World" and the operation failed because the
130 socket is currently unable to write, then you cannot then attempt to write
141 \& static void wait_for_activity(SSL *ssl, int write)
170 \& if (write)
190 connection has failed), or non-fatal (for example because we are trying to read
198 out what type of error has occurred. If the error is non-fatal and can be
200 \&\fBSSL_ERROR_WANT_WRITE\fR depending on whether OpenSSL wanted to read to or write
203 may need to write protocol messages (such as to update cryptographic keys) even
207 Another type of non-fatal error that may occur is \fBSSL_ERROR_ZERO_RETURN\fR. This
208 indicates an EOF (End-Of-File) which can occur if you attempt to read data from
210 on it. In this case you may still want to write data to the connection but you
221 In our demo application we will write a function to handle these errors from
234 \& /* Temporary failure. Wait until we can write and try again */
243 \& return \-1;
253 \& return \-1;
256 \& return \-1;
263 the event of a non-fatal failure, it waits until a retry of the I/O operation
265 in the previous section). It returns 1 in the event of a non-fatal error
266 (except EOF), 0 in the event of EOF, or \-1 if a fatal error occurred.
271 on the \fBossl\-guide\-tls\-client\-block\fR\|(7) page. We won't repeat that information
277 socket it is very likely that calls to this function will fail with a non-fatal
300 a nonblocking socket, this call could fail with a non-fatal error. In that case
303 write with the same length. You must not attempt to send different data on a
307 same data \- even though the buffer that contains that data may change location.
309 blocking tutorial (\fBossl\-guide\-tls\-client\-block\fR\|(7)) we write the request
313 \& /* Write an HTTP GET request to the peer */
317 \& printf("Failed to write start of HTTP request\en");
323 \& printf("Failed to write hostname in HTTP request\en");
329 \& printf("Failed to write end of HTTP request\en");
334 On a write we do not expect to see an EOF response so we treat that case in the
337 Reading a response back from the server is similar:
352 \& case \-1:
360 \& * that it is NUL terminated so we use fwrite() to write the exact
361 \& * number of bytes that we read. The data could be non\-printable or
376 In this demo we just print out all the data we've received back in the response
398 \& * SSL_ERROR_ZERO_RETURN (i.e. EOF) above). We should do the same back.
405 \& * close_notify and we\*(Aqre waiting for one back". But we already know
420 See \fBossl\-guide\-tls\-client\-block\fR\|(7) to read a tutorial on how to write a
421 blocking TLS client. See \fBossl\-guide\-quic\-client\-block\fR\|(7) to see how to do the
425 \&\fBossl\-guide\-introduction\fR\|(7), \fBossl\-guide\-libraries\-introduction\fR\|(7),
426 \&\fBossl\-guide\-libssl\-introduction\fR\|(7), \fBossl\-guide\-tls\-introduction\fR\|(7),
427 \&\fBossl\-guide\-tls\-client\-block\fR\|(7), \fBossl\-guide\-quic\-client\-block\fR\|(7)