I have a multi-threaded application that heavily uses OpenSSL in C. It is designed with the idea that all of its SSL connections are expected to be blocked. In particular, blocking the BIO. All of them are allocated from one inbound port as follows:
ssl = SSL_new(ctx); SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY); sock = BIO_new_socket(socket, BIO_CLOSE); SSL_set_bio(ssl, sock, sock);
As it turned out, there are several small parts of the code base where the best option would be to use non-blocking BIOs. Small parts that benefit from non-blocking BIOs will not be able to know which SSL connections will belong to them. Thus, they always get blocking BIOs.
The question is, can blocking BIOs be non-blocking?
I know that BIO_set_nbio can be used to lock BIO, but the documentation says:
A call to BIO_set_nbio () must be completed before the connection is established, since non-blocking I / O is established during the connection process.
Another possible option that I was thinking about is to copy the BIO and recreate it while maintaining all the state.
source share