Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

can non-blocking SSL_read() and SSL_write() be interleaved?

486 views
Skip to first unread message

Dave Mitchell

unread,
Oct 14, 2013, 7:54:34 AM10/14/13
to
Can calls to non-blocking SSL_read() and SSL_write() be interleaved?

I'm doing select() / event driven IO, and using a BIO pair to handle the
underlying socket IO myself.

A typical sequence might be:

SSL_read(ssl, read_buf, read_size); /* returns e.g. SSL_ERROR_WANT_READ */

select();

/* woken up by an unrelated event which triggers: */
SSL_write(ssl, write_buf, write_size);
/* which causes data to be appended to the BIO slave,
then returns SSL_ERROR_NONE. We read the data from BIO master
and schedule it to be writtenl then: */

select();

/* data available; read() and append to BIO master, then: */
SSL_read(ssl, read_buf, read_size); /* returns SSL_ERROR_NONE */
select();

Is that call to SSL_write() legitimate while the SSL_read() isn't finished?


--
Any [programming] language that doesn't occasionally surprise the
novice will pay for it by continually surprising the expert.
-- Larry Wall
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openss...@openssl.org
Automated List Manager majo...@openssl.org

Darryl Miles

unread,
Oct 14, 2013, 12:58:16 PM10/14/13
to

Dave Mitchell wrote:
> Can calls to non-blocking SSL_read() and SSL_write() be interleaved?
>
> I'm doing select() / event driven IO, and using a BIO pair to handle the
> underlying socket IO myself.


Yes, but not from 2 threads working on the same "SSL *" at the same time.

So your single threaded example is fine.

2 threads can work on 2 different "SSL *" instances at the same time,
providing you have setup and configured the necessary OpenSSL threading
primitives.



There is no such thing as an unfinished SSL_read() call. Either it
returns data or it doesn't.

Each time you call the method OpenSSL will attempt to make further
progress on returning more data.



Some people might say that when you call SSL_write() to push more data
that you can not change some elements of arguments to the call, when you
got a partial write occur (100% of the data you offered was not written).

I have never found this to be the case. Search for Internet concerning:

/usr/include/openssl/ssl.h:#define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER
0x00000002L

Even the description does not make much sense, the address of the bytes
isn't important.


No one on this list has explained why this exists and a look over the
source for the macro label shows it to make no difference.


Darryl
0 new messages