On Wed, 14 Apr 1999, Andrew Cooke wrote:

> 
> Hi,
> 
> The problem I am seeing does not resolve itself on subsequent calls to SSL_read -
> if it fails to return -1 once, then repeated calls also return 0.  In other words,
> on most occassions when the socket closes it returns -1 immediately, but sometimes
> it repeatedly returns 0.

        Your presumtion (b) below is wrong. Unless you have requested
        otherwise SSL_read/SSL_write is blocking.
 
        And... After a normal socket close (no errors) from the other side
        SSL_read *should* continue to return 0 (unless YOU close the
        socket after the first 0 return). This is 100% analogues
        with UN*X read behaviour.

        And by the way it behaves the same way if you are using select and
        non-blocking sockets. select will mark the socket as readable and
        a read will return 0 if the other side has closed the socket.

        So the correct way to handle the returnvalue from SSL_read should
        be:

        retval = SSL_read();
        if(retval == 0)
                otherSideClosedConnection();
        else(if retval == -1)
                errorOccuredDuringRead();
        else
                processReadData();

> 
> If anyone could explain how to persuade SSL to do blocking reads that would give
> me a work-round.
> 
> You mention using select - I have *not* been calling select.  I presumed that:
> 
> (a) Because of blocks/internal buffering select would be unreliable (there may be
> no decrypted data even if some encrypted data are available - if less than a block
> is present, for example).
> 
> (b) SSL_read (and BIO in general) is non-blocking and self-contained.
> 
> Should I be using select anyway?
> 
> Cheers,
> Andrew
> 
> Bodo Moeller wrote:
> 
> > > What can be regarded as odd is that SSL_read() can return 0 even if it
> > > hasn't reached EOF.
> >
> > This can happen only under strange circumstances, I think.
> > Namely, ssl2_read will return 0 if it has read an empty data block.
> > Probably it should really return -1 and have things arranged so that
> > SSL_get_error tells the application to select() on readability;
> > or it should directly start the next read(), which will possibly
> > block.
> 
> 
> 
> 
> 
> ______________________________________________________________________
> OpenSSL Project                                 http://www.openssl.org
> User Support Mailing List                    [EMAIL PROTECTED]
> Automated List Manager                           [EMAIL PROTECTED]
> 

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

Reply via email to