I have a multithreaded application that makes heavy use of OpenSSL in C. It is designed with the idea that all of its SSL connections are expected to block. Specifically, blocking BIOs. They are all allocated off a single incoming port like this:
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 turns out though, there are a few small parts of the codebase where using non-blocking BIOs would be the best choice. The small parts that would benefit from the non-blocking BIOs have no way of knowing which SSL connections will belong to them. Thus, they always receive blocking BIOs.
The question is, can the blocking BIOs be changed to be non-blocking?
I know that BIO_set_nbio can be used to make a BIO non-blocking but the documentation says:
The call to BIO_set_nbio() should be made before the connection is established because non blocking I/O is set during the connect process.
Another possible option I have thought about would be to copy the BIO and recreate it, while somehow maintaining all of the state.