On Tue, Jul 24, 2001 at 09:11:32AM +0100, Michael Playle wrote:
> I've noticed that SSL_read() will either read from the socket, or
> return buffered data, but never both. That is, if there are (eg) 1000
> bytes of data waiting to be read, and I call SSL_read() asking for
> 1500 bytes, it will return only the 1000 buffered bytes, rather than
> reading from the socket to supply the other 500.
>
> This means that if I call SSL_read() in a loop like so:
>
> do {
> SSL_read(x, ...);
> } while(SSL_pending(x));
>
> it will read once from the socket, and then return all of the data
> which was fetched; it won't leave data in the buffer, and it won't sit
> in the loop for as long as data is arriving from the peer.
SSL_read() must work on the TLS-record layer, because otherwise applications
being ready to receive large amounts of data (by specifying a large buffer),
would always hang until the buffer is filled. Therefore SSL_read() will
return what is in the buffer or it will only return when the complete next
TLS record has arrived (as only then the MAC can be checked).
SSL_pending() returns the number of bytes still in the buffer. Your construct
will only loop, if SSL_read() reads data in chunks smaller then the records
coming in. In SSLv3/TLSv1 the maximum record size is 16kB, so records up to
this size can arrive.
> Can I rely on this behaviour to stay the same in future OpenSSL
> versions?
Yes, as there is no other way to realize it in a useful manner.
Best regards,
Lutz
--
Lutz Jaenicke [EMAIL PROTECTED]
BTU Cottbus http://www.aet.TU-Cottbus.DE/personen/jaenicke/
Lehrstuhl Allgemeine Elektrotechnik Tel. +49 355 69-4129
Universitaetsplatz 3-4, D-03044 Cottbus Fax. +49 355 69-4153
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]