Using TLS on non-blocking sockets
In order to learn how to use TLS on a non-blocking socket, we are going to write a small tls-client-non-blocking
program.
We are going to use some OpenSSL functions that we have not used before. Here are their man
pages:
$ man BIO_set_nbio $ man BIO_should_retry $ man BIO_wait
Our tls-client-non-blocking
program will be based on the tls-client
program from Chapter 9, Establishing TLS Connections and Sending Data over Them. We are going to take the tls-client
program source code and change it to use a non-blocking socket instead of a blocking socket. Or, rather, a non-blocking BIO instead of a blocking BIO.
We will only need to change the run_tls_client()
function to accomplish this.
Changing the run_tls_client() function
Here is what we are going to change:
- The first thing that we are going to do is to switch the BIO to the non-blocking mode. To accomplish this, we need to add the following lines:
BIO_set_nbio(ssl_bio, 1);...