2
votes

I have a client program which talks to a server using a message-based protocol. Every request is matched by 1 or more responses.

It's possible for multiple requests to be queued on a socket at once, and the I/O is done on a separate thread using non-blocking I/O. The algorithm is basically to wait for the socket to become readable and/or writable using select() (based on whether there's requests to send and/or responses to read), then to do the read and/or write. This works fine.

Now, if I enable SSL on the socket, we have to use SSL_Read()/SSL_Write() instead of send()/recv(). Now, my question is, can I call SSL_Write() after SSL_Read() fails with WANT_READ/WANT_WRITE (or vice versa), or do I have to keep calling SSL_Write() until it succeeds/fails? The documentation doesn't seem to explicitly rule this out, but it's kind of vague here.

1
After some more googling, it seems like it's allowed to mix SSL_read() & SSL_write(): marc.info/?l=openssl-dev&m=124312461512355&w=2Bwmat

1 Answers

-2
votes

can I call SSL_Write() after SSL_Read() fails with WANT_READ/WANT_WRITE (or vice versa)

If it fails with WANT_WRITE you must call SSL_write(). No 'can I' about it. A read shouldn't fail with WANT_READ, because you were reading, except I guess in non-blocking mode.

or do I have to keep calling SSL_Write() until it succeeds/fails

Yes, when it wants a write you have to write, and you have to repeat until success. No 'or' about it.

I don't really understand why you're even asking. Are there typos in the question?