The OpenSSL library allows you to read from the base socket with SSL_read and write to it using SSL_write. These functions can be returned using SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE depending on the requirements of the ssl protocol (for example, when rebuilding a connection).
I really don't understand what the API wants me to do with these results.
Mapping a server application that accepts client connections, establishes a new ssl session, blocks the underlying socket, and then adds a filedescriptor to the select / poll / epoll loop.
If the client sends data, the main loop sends it to ssl_read. What needs to be done here if SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE is returned? WANT_READ can be easy, because the next main loop iteration can only lead to another ssl_read. But if ssl_read returns WANT_WRITE, with what parameters should it be called? And why does the library not issue the call itself?
If the server wants to send some data to the client, it will use ssl_write. Again, what if WANT_READ or WANT_WRITE returns? Can I answer WANT_WRITE by repeating the same call that was called? And if WANT_READ is returned, do I need to go back to the main loop and let this select / poll / epoll take care of this? But what about the message that should be written first?
Or do I need to read a read immediately after a failed write? Then, what protects against reading bytes from the application protocol and then deals with it somewhere on the edge of the application when the real parser is sitting in mainloop?
linux openssl sockets
dantje
source share