Lines Matching +full:wait +full:- +full:on +full:- +full:write

1 .\" -*- mode: troff; coding: utf-8 -*-
33 .\" If the F register is >0, we'll generate index entries on stderr for
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
68 This page will build on the example developed on the
69 \&\fBossl\-guide\-tls\-client\-block\fR\|(7) page which demonstrates how to write a simple
70 blocking TLS client. On this page we will amend that demo code so that it
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
86 updating a GUI or performing operations on some other socket.
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
94 Since this page is building on the example developed on the
95 \&\fBossl\-guide\-tls\-client\-block\fR\|(7) page we assume that you are familiar with it
101 exact details on how to do this can differ from one platform to another.
107 \& sock = \-1;
113 call whatever functions that your Operating System provides for this purpose on
118 we want to read or write to the socket, but we are currently unable to. In fact
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
134 other work. In fact, for the sake of simplicity, it will do nothing except wait
137 We call our function \f(CWwait_for_activity()\fR because all it does is wait until
141 \& static void wait_for_activity(SSL *ssl, int write)
154 \& * Wait until the socket is writeable or readable. We use select here
163 \& * Let\*(Aqs say for example that you want to update the progress counter on
166 \& * you check if it did so because of activity on the file descriptors or
170 \& if (write)
178 to use and is available on most Operating Systems. However you could use any
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
229 \& /* Temporary failure. Wait until we can read and try again */
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
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
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)