diff options
author | Igor Sysoev <igor@sysoev.ru> | 2005-01-18 16:03:58 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2005-01-18 16:03:58 +0300 |
commit | 02025fd6bdfa997f521c3b26a08aeba366308e84 (patch) | |
tree | 44db6ebb4e310f97f4550b7d7d69932636764304 /src/event | |
parent | 543d02a4427e1833f8f9bdb60e3ff5e9fe2eb21b (diff) |
nginx-0.1.14-RELEASE importrelease-0.1.14
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
Diffstat (limited to 'src/event')
-rw-r--r-- | src/event/ngx_event_accept.c | 6 | ||||
-rw-r--r-- | src/event/ngx_event_acceptex.c | 2 | ||||
-rw-r--r-- | src/event/ngx_event_connect.c | 73 | ||||
-rw-r--r-- | src/event/ngx_event_connect.h | 38 | ||||
-rw-r--r-- | src/event/ngx_event_openssl.c | 47 | ||||
-rw-r--r-- | src/event/ngx_event_openssl.h | 4 | ||||
-rw-r--r-- | src/event/ngx_event_pipe.c | 40 |
7 files changed, 138 insertions, 72 deletions
diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c index f12c00373..70a7c89a4 100644 --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -313,12 +313,12 @@ void ngx_event_accept(ngx_event_t *ev) uint32_t *addr; in_addr_t i; - struct sockaddr_in *addr_in; + struct sockaddr_in *sin; - addr_in = (struct sockaddr_in *) sa; + sin = (struct sockaddr_in *) sa; addr = ecf->debug_connection.elts; for (i = 0; i < ecf->debug_connection.nelts; i++) { - if (addr[i] == addr_in->sin_addr.s_addr) { + if (addr[i] == sin->sin_addr.s_addr) { log->log_level = NGX_LOG_DEBUG_CONNECTION|NGX_LOG_DEBUG_ALL; break; } diff --git a/src/event/ngx_event_acceptex.c b/src/event/ngx_event_acceptex.c index 486636b44..3cfba6830 100644 --- a/src/event/ngx_event_acceptex.c +++ b/src/event/ngx_event_acceptex.c @@ -92,7 +92,7 @@ int ngx_event_post_acceptex(ngx_listening_t *ls, int n) /* TODO: look up reused sockets */ - s = ngx_socket(ls->family, ls->type, ls->protocol); + s = ngx_socket(ls->family, ls->type, 0); ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ls->log, 0, ngx_socket_n " s:%d", s); diff --git a/src/event/ngx_event_connect.c b/src/event/ngx_event_connect.c index 6f0d94f86..75277a7bd 100644 --- a/src/event/ngx_event_connect.c +++ b/src/event/ngx_event_connect.c @@ -25,7 +25,6 @@ ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc) ngx_event_t *rev, *wev; ngx_connection_t *c; ngx_event_conf_t *ecf; - struct sockaddr_in addr; now = ngx_time(); @@ -54,7 +53,7 @@ ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc) pc->connection = NULL; if (pc->peers->number == 1) { - peer = &pc->peers->peers[0]; + peer = &pc->peers->peer[0]; } else { @@ -64,45 +63,47 @@ ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc) /* it's a first try - get a current peer */ - pc->cur_peer = pc->peers->current++; + pc->cur_peer = pc->peers->current; + + pc->peers->weight--; + + if (pc->peers->weight == 0) { + pc->peers->current++; + } if (pc->peers->current >= pc->peers->number) { pc->peers->current = 0; } - } - if (pc->peers->max_fails == 0) { - peer = &pc->peers->peers[pc->cur_peer]; - - } else { - - /* the peers support a fault tolerance */ + if (pc->peers->weight == 0) { + pc->peers->weight = pc->peers->peer[pc->peers->current].weight; + } + } - for ( ;; ) { - peer = &pc->peers->peers[pc->cur_peer]; + for ( ;; ) { + peer = &pc->peers->peer[pc->cur_peer]; - if (peer->fails <= pc->peers->max_fails) { - break; - } + if (peer->fails <= peer->max_fails) { + break; + } - if (now - peer->accessed > pc->peers->fail_timeout) { - peer->fails = 0; - break; - } + if (now - peer->accessed > peer->fail_timeout) { + peer->fails = 0; + break; + } - pc->cur_peer++; + pc->cur_peer++; - if (pc->cur_peer >= pc->peers->number) { - pc->cur_peer = 0; - } + if (pc->cur_peer >= pc->peers->number) { + pc->cur_peer = 0; + } - pc->tries--; + pc->tries--; - if (pc->tries == 0) { - /* ngx_unlock_mutex(pc->peers->mutex); */ + if (pc->tries == 0) { + /* ngx_unlock_mutex(pc->peers->mutex); */ - return NGX_ERROR; - } + return NGX_ERROR; } } } @@ -110,7 +111,7 @@ ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc) /* ngx_unlock_mutex(pc->peers->mutex); */ - s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP); + s = ngx_socket(peer->sockaddr->sa_family, SOCK_STREAM, 0); if (s == -1) { ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, @@ -257,16 +258,10 @@ ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc) } } - ngx_memzero(&addr, sizeof(struct sockaddr_in)); - - addr.sin_family = AF_INET; - addr.sin_port = peer->port; - addr.sin_addr.s_addr = peer->addr; - ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pc->log, 0, - "connect to %V, #%d", &peer->addr_port_text, c->number); + "connect to %V, #%d", &peer->name, c->number); - rc = connect(s, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)); + rc = connect(s, peer->sockaddr, peer->socklen); if (rc == -1) { err = ngx_socket_errno; @@ -367,8 +362,8 @@ void ngx_event_connect_peer_failed(ngx_peer_connection_t *pc) /* ngx_lock_mutex(pc->peers->mutex); */ - pc->peers->peers[pc->cur_peer].fails++; - pc->peers->peers[pc->cur_peer].accessed = now; + pc->peers->peer[pc->cur_peer].fails++; + pc->peers->peer[pc->cur_peer].accessed = now; /* ngx_unlock_mutex(pc->peers->mutex); */ diff --git a/src/event/ngx_event_connect.h b/src/event/ngx_event_connect.h index 04086941b..4f3ee2e27 100644 --- a/src/event/ngx_event_connect.h +++ b/src/event/ngx_event_connect.h @@ -17,34 +17,40 @@ typedef struct { - in_addr_t addr; - ngx_str_t host; - in_port_t port; - ngx_str_t addr_port_text; + struct sockaddr *sockaddr; + socklen_t socklen; - ngx_int_t fails; - time_t accessed; -} ngx_peer_t; + ngx_str_t name; + char *uri_separator; + ngx_uint_t weight; -typedef struct { - ngx_int_t current; - ngx_int_t number; - ngx_int_t max_fails; + ngx_uint_t fails; + time_t accessed; + + ngx_uint_t max_fails; time_t fail_timeout; - ngx_int_t last_cached; +} ngx_peer_t; + + +struct ngx_peers_s { + ngx_uint_t current; + ngx_uint_t weight; + + ngx_uint_t number; + ngx_uint_t last_cached; /* ngx_mutex_t *mutex; */ ngx_connection_t **cached; - ngx_peer_t peers[1]; -} ngx_peers_t; + ngx_peer_t peer[1]; +}; typedef struct { ngx_peers_t *peers; - ngx_int_t cur_peer; - ngx_int_t tries; + ngx_uint_t cur_peer; + ngx_uint_t tries; ngx_connection_t *connection; #if (NGX_THREADS) diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c index c0ec6adfe..15a25d111 100644 --- a/src/event/ngx_event_openssl.c +++ b/src/event/ngx_event_openssl.c @@ -8,6 +8,8 @@ #include <ngx_core.h> #include <ngx_event.h> +#include <openssl/engine.h> + static void ngx_ssl_write_handler(ngx_event_t *wev); static ssize_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size); @@ -16,8 +18,11 @@ static void ngx_ssl_read_handler(ngx_event_t *rev); ngx_int_t ngx_ssl_init(ngx_log_t *log) { + ENGINE *engine; + SSL_library_init(); SSL_load_error_strings(); + ENGINE_load_builtin_engines(); return NGX_OK; } @@ -71,6 +76,48 @@ ssize_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size) ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_read: %d", n); if (n > 0) { + +#if (NGX_DEBUG) + + if (!c->ssl->handshaked && SSL_is_init_finished(c->ssl->ssl)) { + char buf[129], *s, *d; + SSL_CIPHER *cipher; + + c->ssl->handshaked = 1; + + cipher = SSL_get_current_cipher(c->ssl->ssl); + + if (cipher) { + SSL_CIPHER_description(cipher, &buf[1], 128); + + for (s = &buf[1], d = buf; *s; s++) { + if (*s == ' ' && *d == ' ') { + continue; + } + + if (*s == '\n' || *s == '\r') { + continue; + } + + *++d = *s; + } + + if (*d != ' ') { + d++; + } + + *d = '\0'; + + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, + "SSL cipher: \"%s\"", &buf[1]); + } else { + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, + "SSL no shared ciphers"); + } + } + +#endif + if (c->ssl->saved_write_handler) { c->write->event_handler = c->ssl->saved_write_handler; diff --git a/src/event/ngx_event_openssl.h b/src/event/ngx_event_openssl.h index 6e7b705b1..224cc84b3 100644 --- a/src/event/ngx_event_openssl.h +++ b/src/event/ngx_event_openssl.h @@ -25,6 +25,10 @@ typedef struct { unsigned no_rcv_shut:1; unsigned no_send_shut:1; unsigned shutdown_set:1; + +#if (NGX_DEBUG) + unsigned handshaked:1; +#endif } ngx_ssl_t; diff --git a/src/event/ngx_event_pipe.c b/src/event/ngx_event_pipe.c index 310f0ce43..ad67931c1 100644 --- a/src/event/ngx_event_pipe.c +++ b/src/event/ngx_event_pipe.c @@ -379,7 +379,7 @@ ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p) ngx_int_t ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p) { - off_t bsize; + size_t bsize; ngx_uint_t flush; ngx_buf_t *b; ngx_chain_t *out, **ll, *cl, *tl; @@ -433,16 +433,18 @@ ngx_int_t ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p) break; } - /* bsize is the size of the busy bufs */ + /* bsize is the size of the busy recycled bufs */ bsize = 0; for (cl = p->busy; cl; cl = cl->next) { - bsize += cl->buf->end - cl->buf->start; + if (cl->buf->recycled) { + bsize += cl->buf->end - cl->buf->start; + } } ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, - "pipe write busy: %O", bsize); + "pipe write busy: %uz", bsize); out = NULL; ll = NULL; @@ -452,19 +454,23 @@ ngx_int_t ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p) if (p->out) { cl = p->out; - if (bsize + ngx_buf_size(cl->buf) > p->busy_size) { + if (cl->buf->recycled + && bsize + cl->buf->last - cl->buf->pos > p->busy_size) + { flush = 1; break; } p->out = p->out->next; - ngx_event_pipe_free_shadow_raw_buf(&p->free_raw_bufs, - cl->buf); + + ngx_event_pipe_free_shadow_raw_buf(&p->free_raw_bufs, cl->buf); } else if (!p->cachable && p->in) { cl = p->in; - if (bsize + ngx_buf_size(cl->buf) > p->busy_size) { + if (cl->buf->recycled + && bsize + cl->buf->last - cl->buf->pos > p->busy_size) + { flush = 1; break; } @@ -475,7 +481,10 @@ ngx_int_t ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p) break; } - bsize += ngx_buf_size(cl->buf); + if (cl->buf->recycled) { + bsize += cl->buf->last - cl->buf->pos; + } + cl->next = NULL; ngx_chain_add_link(out, ll, cl); } @@ -618,8 +627,6 @@ static ngx_int_t ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p) b->in_file = 1; b->temp_file = 1; - b->temporary = 0; - b->recycled = 0; ngx_chain_add_link(p->out, p->last_out, cl); @@ -668,7 +675,7 @@ ngx_int_t ngx_event_pipe_copy_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf) ngx_alloc_link_and_set_buf(cl, b, p->pool, NGX_ERROR); - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "buf #%d", b->num); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "input buf #%d", b->num); ngx_chain_add_link(p->in, p->last_in, cl); @@ -781,7 +788,14 @@ static ngx_int_t ngx_event_pipe_drain_chains(ngx_event_pipe_t *p) b = cl->buf->shadow; b->pos = b->last = b->start; b->shadow = NULL; - ngx_alloc_link_and_set_buf(tl, b, p->pool, NGX_ABORT); + + if (!(tl = ngx_alloc_chain_link(p->pool))) { + return NGX_ABORT; + } + + tl->buf = b; + tl->next = NULL; + ngx_event_pipe_add_free_buf(&p->free_raw_bufs, tl); cl->buf->last_shadow = 0; |