2
votes

I haven't gotten a clear answer for this question yet.

If I use non-blocking sockets, can a call to SSL_read or write still block? If I call SSL_read when there is nothing to read, will it immediately return?

What kind of time does SSL_write(16kb) take? Can you rely on a worst case scenario or can this change a lot?

I have 4ms cycles where I have to do things so I cannot have a read or write that exceeds that, is that impossible to achieve reliably?

1

1 Answers

2
votes

SSL_read's documentation states:

The behaviour of SSL_read() depends on the underlying BIO.

and

If the underlying BIO is blocking, SSL_read() will only return, once the read operation has been finished or an error occurred, except when a renegotiation take place, in which case a SSL_ERROR_WANT_READ may occur. This behaviour can be controlled with the SSL_MODE_AUTO_RETRY flag of the SSL_CTX_set_mode call.

If the underlying BIO is non-blocking, SSL_read() will also return when the underlying BIO could not satisfy the needs of SSL_read() to continue the operation. In this case a call to SSL_get_error with the return value of SSL_read() will yield SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. As at any time a re-negotiation is possible, a call to SSL_read() can also cause write operations! The calling process then must repeat the call after taking appropriate action to satisfy the needs of SSL_read(). The action depends on the underlying BIO. When using a non-blocking socket, nothing is to be done, but select() can be used to check for the required condition. When using a buffering BIO, like a BIO pair, data must be written into or retrieved out of the BIO before being able to continue.

If you want to know how long SSL_write takes to do a certain amount of bytes then you must test it. ALso test it on different systems to get an idea of the general time it takes unless you will always have the same system running your code, which I doubt.

Have a look at this SO post. It was answered by Remy, a guy who knows how to implement SSL: How to handle OpenSSL SSL_ERROR_WANT_READ / WANT_WRITE on non-blocking sockets