> Hi, I have a question. I have multithread system, with non
> blocking I/O and perhaps 100 connections to servers. I have a
> special thread, that waits on select(). When it returns me, that
> I have some data for reading, I start the reading for every
> connection.

That's not particularly efficient. You could look at the 'select' set
returned and only read on the connections where data was received.

> When the select throws me timeout, I start the readig
> too, because it´s possible that some data came, while I was doing
> previous reading.

The 'select' function doesn't only return if the operation becomes possible
while you're blocked in 'select'. It's a status-reporting function. If you
get a timeout, it means that none of the operations you tested for could
complete.

However, this type of coding is very defensive and saves you from having to
correctly handle some complicated cases. So you may encounter problems if
you try to change it, and then incorrectly think it's because data arrived
during the read.

For example, suppose you call SSL_write, and during the write process, some
data is read from the socket. A call to 'select' won't indicate a read can
succeed on the socket because the data was already read, but an SSL_read
might have some data for you.

> I have two types of connection. One TCP, where I use for reading
> the BIO_read function and one TLS where I use the SSL_read
> function. Now I have this problem. When I try to read data from
> some connection, it is posible, that there is not any data. I
> have read, that when there is not any data, the BIO_read function
> throws me 0 or -1, but these return values can mean error too.

Zero means normal termination of the connection. Only negative return values
indicate an error.

> How can I recognize, that this means, that I read only 0b of data?

BIO_should_retry.

> And I have the similar problem with SSL_read. I use SSL_get_error
> function to determine, what hapen in reading, but I havent find
> what error code it returns me, when I read no data? Will it be
> SSL_ERROR_NONE or SSL_ERROR_ZERO_RETURN?

SSL_ERROR_NONE means the operation completed successfully.
SSL_ERROR_ZERO_RETURN means the connection closed normally. The cases that
mean you need to 'select' are SSL_WANT_READ or SSL_WANT_WRITE.

Getting an SSL_WANT_READ or SSL_WANT_WRITE are the *only* cases where you
should wait for a 'select' hit before calling SSL_read or SSL_write. And
after a 'select' hit in either direction, you should retry both a read or a
write operation that you deferred.

DS


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to