test reading fail when use https

wandenberg nginx-forum at nginx.us
Mon Jul 4 20:04:36 MSD 2011


Hi Maxim,

now I think the code is ok.
Could you check, please?

Maxim Dounin Wrote:
-------------------------------------------------------
> Hello!
> 
> On Sun, Jun 26, 2011 at 09:28:29AM -0400,
> wandenberg wrote:
> 
> [...]
> 
> > To solve the problem of detect when users close
> connection on https I
> > did this implementation
> > 
> > #if (NGX_HTTP_SSL)
> >     if (c->ssl == NULL) {
> > 	    n = recv(c->fd, buf, 1, MSG_PEEK);
> >     } else {
> > 	    n = SSL_peek(c->ssl->connection, buf, 1);
> >     }
> > #else
> >     n = recv(c->fd, buf, 1, MSG_PEEK);
> > #endif
> > 
> > I would like to know if you see any other
> problem on that and if is
> > possible to this code be applied on nginx
> source?
> 
> SSL_peek may (and likely will in many cases) leave
> an error in 
> OpenSSL error queue, so I suspect this actually
> requires a bit 
> more code.  
> 
> Maxim Dounin
> 
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://nginx.org/mailman/listinfo/nginx


#if (NGX_HTTP_SSL)
    if (c->ssl != NULL) {
        n = SSL_peek(c->ssl->connection, buf, 1);
    } else {
        n = recv(c->fd, buf, 1, MSG_PEEK);
    }
#else
    n = recv(c->fd, buf, 1, MSG_PEEK);
#endif

    if (n == 0) {
        rev->eof = 1;
        c->error = 1;
        err = 0;

        goto closed;

    } else if (n == -1) {

#if (NGX_HTTP_SSL)
		if (c->ssl != NULL) {
			err = SSL_get_error(c->ssl->connection, n);
		} else {
			err = ngx_socket_errno;
		}

		if ((err != NGX_EAGAIN) && (err != SSL_ERROR_WANT_READ) && (err !=
SSL_ERROR_WANT_WRITE)) {
#else
		err = ngx_socket_errno;
		if (err != NGX_EAGAIN) {
#endif
            rev->eof = 1;
            c->error = 1;

            goto closed;
        }
    }

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,209967,211939#msg-211939




More information about the nginx mailing list