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

6 demos/guide/tls-client-non-block.c
12 ossl-guide-tls-client-non-block
13 - OpenSSL Guide: Writing a simple nonblocking TLS client
17 This page will build on the example developed on the
18 L<ossl-guide-tls-client-block(7)> page which demonstrates how to write a simple
19 blocking TLS client. On this page we will amend that demo code so that it
24 B<tls-client-non-block.c>. It is also available online at
25 L<https://github.com/openssl/openssl/blob/master/demos/guide/tls-client-non-block.c>.
30 write at the moment. This can simplify the development of code because you do
34 to go and do other tasks whilst the socket is unable to read/write, for example
35 updating a GUI or performing operations on some other socket.
37 With a nonblocking socket attempting to read or write to a socket that is
38 currently unable to read or write will return immediately with a non-fatal
43 Since this page is building on the example developed on the
44 L<ossl-guide-tls-client-block(7)> page we assume that you are familiar with it
51 exact details on how to do this can differ from one platform to another.
56 sock = -1;
61 call whatever functions that your Operating System provides for this purpose on
67 we want to read or write to the socket, but we are currently unable to. In fact
78 attempting to write the text "Hello World" and the operation failed because the
79 socket is currently unable to write, then you cannot then attempt to write
83 other work. In fact, for the sake of simplicity, it will do nothing except wait
86 We call our function C<wait_for_activity()> because all it does is wait until
89 static void wait_for_activity(SSL *ssl, int write)
102 * Wait until the socket is writeable or readable. We use select here
111 * Let's say for example that you want to update the progress counter on
114 * you check if it did so because of activity on the file descriptors or
118 if (write)
125 to use and is available on most Operating Systems. However you could use any
138 connection has failed), or non-fatal (for example because we are trying to read
146 out what type of error has occurred. If the error is non-fatal and can be
148 B<SSL_ERROR_WANT_WRITE> depending on whether OpenSSL wanted to read to or write
151 may need to write protocol messages (such as to update cryptographic keys) even
155 Another type of non-fatal error that may occur is B<SSL_ERROR_ZERO_RETURN>. This
156 indicates an EOF (End-Of-File) which can occur if you attempt to read data from
158 on it. In this case you may still want to write data to the connection but you
169 In our demo application we will write a function to handle these errors from
176 /* Temporary failure. Wait until we can read and try again */
181 /* Temporary failure. Wait until we can write and try again */
190 return -1;
200 return -1;
203 return -1;
209 the event of a non-fatal failure, it waits until a retry of the I/O operation
211 in the previous section). It returns 1 in the event of a non-fatal error
212 (except EOF), 0 in the event of EOF, or -1 if a fatal error occurred.
218 on the L<ossl-guide-tls-client-block(7)> page. We won't repeat that information
225 socket it is very likely that calls to this function will fail with a non-fatal
247 a nonblocking socket, this call could fail with a non-fatal error. In that case
250 write with the same length. You must not attempt to send different data on a
254 same data - even though the buffer that contains that data may change location.
256 blocking tutorial (L<ossl-guide-tls-client-block(7)>) we write the request
259 /* Write an HTTP GET request to the peer */
263 printf("Failed to write start of HTTP request\n");
269 printf("Failed to write hostname in HTTP request\n");
275 printf("Failed to write end of HTTP request\n");
279 On a write we do not expect to see an EOF response so we treat that case in the
296 case -1:
304 * that it is NUL terminated so we use fwrite() to write the exact
305 * number of bytes that we read. The data could be non-printable or
364 See L<ossl-guide-tls-client-block(7)> to read a tutorial on how to write a
365 blocking TLS client. See L<ossl-guide-quic-client-block(7)> to see how to do the
370 L<ossl-guide-introduction(7)>, L<ossl-guide-libraries-introduction(7)>,
371 L<ossl-guide-libssl-introduction(7)>, L<ossl-guide-tls-introduction(7)>,
372 L<ossl-guide-tls-client-block(7)>, L<ossl-guide-quic-client-block(7)>