diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-07-18 23:11:20 +0400 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-07-18 23:11:20 +0400 |
commit | 74a5ddb47aef86bb07336713bb1ace0007c2d452 (patch) | |
tree | 449c6ceb229b7646ef40417135c66843a677746b /src/event | |
parent | f38e046a0a2e7437f8232ef2a99cead69c4b9ebb (diff) |
nginx-0.0.7-2004-07-18-23:11:20 import
Diffstat (limited to 'src/event')
-rw-r--r-- | src/event/ngx_event_accept.c | 3 | ||||
-rw-r--r-- | src/event/ngx_event_openssl.c | 59 | ||||
-rw-r--r-- | src/event/ngx_event_openssl.h | 11 |
3 files changed, 48 insertions, 25 deletions
diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c index da15a292d..d84d8c542 100644 --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -258,6 +258,9 @@ void ngx_event_accept(ngx_event_t *ev) c->ctx = ls->ctx; c->servers = ls->servers; + c->recv = ngx_recv; + c->send_chain = ngx_send_chain; + c->log = log; rev->log = log; wev->log = log; diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c index 89ef7031c..27d33b0e7 100644 --- a/src/event/ngx_event_openssl.c +++ b/src/event/ngx_event_openssl.c @@ -64,10 +64,10 @@ ngx_int_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size) sslerr = SSL_get_error(c->ssl->ssl, n); - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d", sslerr); - err = (sslerr == SSL_ERROR_SYSCALL) ? ngx_errno : 0; + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d", sslerr); + if (sslerr == SSL_ERROR_WANT_READ) { return NGX_AGAIN; } @@ -85,20 +85,18 @@ ngx_int_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size) handshake = ""; } + c->ssl->no_rcv_shut = 1; + if (sslerr == SSL_ERROR_ZERO_RETURN || ERR_peek_error() == 0) { ngx_log_error(NGX_LOG_INFO, c->log, err, "client closed connection%s", handshake); - SSL_set_shutdown(c->ssl->ssl, SSL_RECEIVED_SHUTDOWN); - return NGX_ERROR; } ngx_ssl_error(NGX_LOG_ALERT, c->log, err, "SSL_read() failed%s", handshake); - SSL_set_shutdown(c->ssl->ssl, SSL_RECEIVED_SHUTDOWN); - return NGX_ERROR; } @@ -106,7 +104,8 @@ ngx_int_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size) ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) { - int n; + int n, sslerr; + ngx_err_t err; ssize_t send, size; ngx_buf_t *buf; @@ -157,6 +156,7 @@ ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in, if (n > 0) { buf->pos += n; send += n; + c->sent += n; if (n < size) { break; @@ -233,6 +233,7 @@ ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in, if (n > 0) { in->buf->pos += n; send += n; + c->sent += n; if (n == size) { if (send < limit) { @@ -246,21 +247,26 @@ ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in, return in; } - n = SSL_get_error(c->ssl->ssl, n); + sslerr = SSL_get_error(c->ssl->ssl, n); + + err = (sslerr == SSL_ERROR_SYSCALL) ? ngx_errno : 0; - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d", n); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, + "SSL_get_error: %d", sslerr); - if (n == SSL_ERROR_WANT_WRITE) { + if (sslerr == SSL_ERROR_WANT_WRITE) { c->write->ready = 0; return in; } #if 0 - if (n == SSL_ERROR_WANT_READ) { + if (sslerr == SSL_ERROR_WANT_READ) { return NGX_AGAIN; } #endif + c->ssl->no_rcv_shut = 1; + ngx_ssl_error(NGX_LOG_ALERT, c->log, 0, "SSL_write() failed"); return NGX_CHAIN_ERROR; @@ -272,19 +278,21 @@ ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in, ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c) { - int n; + int n, sslerr; ngx_uint_t again; -#if 0 - if (c->read->timedout || c->write->timedout) { - SSL_set_shutdown(c->ssl, SSL_RECEIVED_SHUTDOWN); - SSL_set_shutdown(c->ssl, SSL_RECEIVED_SHUTDOWN|SSL_SENT_SHUTDOWN); - } -#endif + if (c->timedout) { + SSL_set_shutdown(c->ssl->ssl, SSL_RECEIVED_SHUTDOWN|SSL_SENT_SHUTDOWN); -#if 0 - SSL_set_shutdown(c->ssl->ssl, SSL_RECEIVED_SHUTDOWN); -#endif + } else { + if (c->ssl->no_rcv_shut) { + SSL_set_shutdown(c->ssl->ssl, SSL_RECEIVED_SHUTDOWN); + } + + if (c->ssl->no_send_shut) { + SSL_set_shutdown(c->ssl->ssl, SSL_SENT_SHUTDOWN); + } + } again = 0; @@ -308,12 +316,13 @@ ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c) } if (!again) { - n = SSL_get_error(c->ssl->ssl, n); + sslerr = SSL_get_error(c->ssl->ssl, n); - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d", n); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, + "SSL_get_error: %d", sslerr); } - if (again || n == SSL_ERROR_WANT_READ) { + if (again || sslerr == SSL_ERROR_WANT_READ) { ngx_add_timer(c->read, 10000); @@ -324,7 +333,7 @@ ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c) return NGX_AGAIN; } - if (n == SSL_ERROR_WANT_WRITE) { + if (sslerr == SSL_ERROR_WANT_WRITE) { if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) { return NGX_ERROR; diff --git a/src/event/ngx_event_openssl.h b/src/event/ngx_event_openssl.h index 7d098f6d6..c1b36feb7 100644 --- a/src/event/ngx_event_openssl.h +++ b/src/event/ngx_event_openssl.h @@ -13,6 +13,9 @@ typedef struct { SSL *ssl; ngx_buf_t *buf; ngx_event_handler_pt saved_handler; + + unsigned no_rcv_shut:1; + unsigned no_send_shut:1; } ngx_ssl_t; @@ -28,6 +31,9 @@ typedef SSL_CTX ngx_ssl_ctx_t; ngx_int_t ngx_ssl_init(ngx_log_t *log); ngx_int_t ngx_ssl_create_session(ngx_ssl_ctx_t *ctx, ngx_connection_t *c, ngx_uint_t flags); + +#define ngx_ssl_handshake(c) NGX_OK + ngx_int_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size); ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit); @@ -35,5 +41,10 @@ ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c); void ngx_ssl_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, char *fmt, ...); +#define ngx_ssl_set_nosendshut(ssl) \ + if (ssl) { \ + ssl->no_send_shut = 1; \ + } + #endif /* _NGX_EVENT_OPENSSL_H_INCLUDED_ */ |