diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-04-13 19:08:48 +0400 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-04-13 19:08:48 +0400 |
commit | 3d54061602b20fa5a6fdf55b11cb333285d61d03 (patch) | |
tree | dc7cb2320ba0f21cda2cd87096481c0731074296 /src/http/modules/proxy | |
parent | a21e30b91900dbbde5ea7fbc5ed4b2ec59969de7 (diff) |
nginx-0.0.3-2004-04-13-19:08:48 import
Diffstat (limited to 'src/http/modules/proxy')
-rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_handler.c | 9 | ||||
-rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_upstream.c | 43 |
2 files changed, 33 insertions, 19 deletions
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c index 017d7c8d0..0fd89c139 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.c +++ b/src/http/modules/proxy/ngx_http_proxy_handler.c @@ -425,7 +425,9 @@ void ngx_http_proxy_check_broken_connection(ngx_event_t *ev) n = recv(c->fd, buf, 1, MSG_PEEK); - if (ev->write && n >= 0) { + err = ngx_socket_errno; + + if (ev->write && (n >= 0 || err == NGX_EAGAIN)) { return; } @@ -443,7 +445,6 @@ void ngx_http_proxy_check_broken_connection(ngx_event_t *ev) ev->eof = 1; if (n == -1) { - err = ngx_socket_errno; if (err == NGX_EAGAIN) { return; } @@ -634,11 +635,11 @@ void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p) ngx_del_conn(c, NGX_CLOSE_EVENT); } else { - if (c->read->active) { + if (c->read->active || c->read->posted) { ngx_del_event(c->read, NGX_READ_EVENT, NGX_CLOSE_EVENT); } - if (c->write->active) { + if (c->write->active || c->read->posted) { ngx_del_event(c->write, NGX_WRITE_EVENT, NGX_CLOSE_EVENT); } } diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c index d27975919..760d8d629 100644 --- a/src/http/modules/proxy/ngx_http_proxy_upstream.c +++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c @@ -327,19 +327,20 @@ static void ngx_http_proxy_init_upstream(void *data) r->connection->read->event_handler = ngx_http_proxy_check_broken_connection; - if ((ngx_event_flags & (NGX_USE_CLEAR_EVENT|NGX_HAVE_KQUEUE_EVENT)) - && !r->connection->write->active) - { + if (ngx_event_flags & (NGX_USE_CLEAR_EVENT|NGX_HAVE_KQUEUE_EVENT)) { + /* kqueue allows to detect when client closes prematurely connection */ r->connection->write->event_handler = ngx_http_proxy_check_broken_connection; - if (ngx_add_event(r->connection->write, NGX_WRITE_EVENT, + if (!r->connection->write->active) { + if (ngx_add_event(r->connection->write, NGX_WRITE_EVENT, NGX_CLEAR_EVENT) == NGX_ERROR) - { - ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); - return; + { + ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); + return; + } } } @@ -560,6 +561,9 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p) rc = ngx_event_connect_peer(&p->upstream->peer); + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0, + "http proxy connect: %d", rc); + if (rc == NGX_ERROR) { ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); return; @@ -573,14 +577,13 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p) return; } - p->upstream->peer.connection->data = p; - p->upstream->peer.connection->write->event_handler = - ngx_http_proxy_send_request_handler; - p->upstream->peer.connection->read->event_handler = - ngx_http_proxy_process_upstream_status_line; - r = p->request; c = p->upstream->peer.connection; + + c->data = p; + c->write->event_handler = ngx_http_proxy_send_request_handler; + c->read->event_handler = ngx_http_proxy_process_upstream_status_line; + c->pool = r->pool; c->read->log = c->write->log = c->log = r->connection->log; @@ -613,6 +616,11 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p) if (rc == NGX_AGAIN) { ngx_add_timer(c->write, p->lcf->connect_timeout); + + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, + "http proxy connect handler: " PTR_FMT, + c->write->event_handler); + return; } @@ -638,6 +646,9 @@ static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p) c = p->upstream->peer.connection; + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, + "http proxy send request"); + #if (HAVE_KQUEUE) if ((ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) @@ -715,8 +726,7 @@ static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p) } #endif - p->upstream->peer.connection->write->event_handler = - ngx_http_proxy_dummy_handler; + c->write->event_handler = ngx_http_proxy_dummy_handler; if (ngx_handle_level_write_event(c->write) == NGX_ERROR) { ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); @@ -733,6 +743,9 @@ static void ngx_http_proxy_send_request_handler(ngx_event_t *wev) c = wev->data; p = c->data; + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0, + "http proxy send request handler"); + if (wev->timedout) { p->action = "sending request to upstream"; ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_TIMEOUT); |