> On Tue, Apr 13, 1999 at 12:00:00AM +0000, Andrew Cooke wrote:
> 
> > I am reading across the network, using SSLeay-0.9.0.b, and have an
> > intermittent problem - the sending socket is being closed, but this is
> > not always being detected by the receiving SSL.  In particular,
> > 
> > SSL_read(ssl, buffer, length)
> > 
> > is returning zero rather than -1.
> 
> The return value zero means that the connection has been closed (well,
> unless you called read() with length == 0, which does not make too
> much sense).  Look at s_client.c: First there's the call
> 
>      k = SSL_read(con, ...),
> 
> and then there's
> 
>      switch (SSL_get_error(con, k)).
> 

The notion is that we should be able to implement code that looks
like:

    if (ssl_active_flag || tls_active_flag) {
        int error;
        if ( ssl_active_flag )
            count = SSL_read(ssl_con, buf, sizeof(buf));
        else
            count = SSL_read(tls_con, buf, sizeof(buf));
        switch ( SSL_get_error(ssl_active_flag?ssl_con:tls_con,count)) {
        case SSL_ERROR_NONE:
            if (count > 0) {
                /* Reset buffer pointer. */
                return(count);  /* Return buffer count. */
            } else if (count < 0) {
                return(-1);     /* Non-fatal error */
            } else {
                /* count == 0 : close connection */
                netclos();
                return(-2);     /* Fatal Error */
            }
        case SSL_ERROR_WANT_WRITE:
        case SSL_ERROR_WANT_READ:
            return(-1);         /* Non-fatal error */
        case SSL_ERROR_SYSCALL:
             switch (WSAGetLastError()) {
             case WSAESHUTDOWN:
             case WSAECONNABORTED:
                 netclos();
                 return(-2);
             default: return(-1); /* Non-fatal error */
             }
        case SSL_ERROR_WANT_X509_LOOKUP:
        case SSL_ERROR_SSL:
        case SSL_ERROR_ZERO_RETURN:
        default:
            netclos();
            return(-2);
        }
    }


Now on Windows NT SP4 this code does not detect the closing of the
socket by the peer.  SSL_ERROR_ZERO_RETURN is never returned by
SSL_get_error().  When the peer closes the connection SSL_get_error() 
starts to return SSL_ERROR_SSYCALL.  But WSAGetLastError() returns 
NO_ERROR (0).  

If the application attempts to write using SSL_write() SSL_get_error()
returns SSL_ERROR_SYSCALL with WSAGetLastError() returning
WSAESHUTDOWN.   Subsequent SSL_read() calls will produce a
WSAGetLastError() of WSAECONNABORTED.

If I am doing something wrong, please advise.  Otherwise, I still
believe that there is something wrong in the code (at least on
Windows.) 



    Jeffrey Altman * Sr.Software Designer * Kermit-95 for Win32 and OS/2
                 The Kermit Project * Columbia University
              612 West 115th St #716 * New York, NY * 10025
  http://www.kermit-project.org/k95.html * [EMAIL PROTECTED]


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

Reply via email to