nginx-0.0.3-2004-03-16-16:35:20 import

This commit is contained in:
Igor Sysoev 2004-03-16 13:35:20 +00:00
parent 10a543a810
commit 9c61095a30
12 changed files with 184 additions and 48 deletions

View File

@ -53,7 +53,7 @@ fi
if [ \( $version -lt 500000 -a $version -ge 430000 \) \
-o $version -ge 500018 ]
then
echo " + using kqueue's NOTE_LAWAT"
echo " + using kqueue's NOTE_LOWAT"
have=HAVE_LOWAT_EVENT . auto/have
fi

View File

@ -2,7 +2,7 @@
#define _NGINX_H_INCLUDED_
#define NGINX_VER "nginx/0.0.2"
#define NGINX_VER "nginx/0.0.3"
#define NGINX_CONF (u_char *) "nginx.conf"
#define NGINX_PID "nginx.pid"
#define NGINX_NEW_PID_EXT ".newbin"

View File

@ -3,14 +3,62 @@
#include <ngx_core.h>
ngx_inline static size_t ngx_sprint_uchar(u_char *text, u_char c, size_t len)
{
size_t n;
ngx_uint_t c1, c2;
n = 0;
if (len == n) {
return n;
}
c1 = c / 100;
if (c1) {
*text++ = (u_char) (c1 + '0');
n++;
if (len == n) {
return n;
}
}
c2 = (c % 100) / 10;
if (c1 || c2) {
*text++ = (u_char) (c2 + '0');
n++;
if (len == n) {
return n;
}
}
c2 = c % 10;
*text++ = (u_char) (c2 + '0');
n++;
return n;
}
/* AF_INET only */
size_t ngx_sock_ntop(int family, struct sockaddr *addr, u_char *text,
size_t len)
{
u_char *p;
size_t n;
ngx_uint_t i;
struct sockaddr_in *addr_in;
if (len == 0) {
return 0;
}
if (family != AF_INET) {
return 0;
}
@ -18,19 +66,101 @@ size_t ngx_sock_ntop(int family, struct sockaddr *addr, u_char *text,
addr_in = (struct sockaddr_in *) addr;
p = (u_char *) &addr_in->sin_addr;
if (len > INET_ADDRSTRLEN) {
len = INET_ADDRSTRLEN;
}
n = ngx_sprint_uchar(text, p[0], len);
i = 1;
do {
if (len == n) {
text[n - 1] = '\0';
return n;
}
text[n++] = '.';
if (len == n) {
text[n - 1] = '\0';
return n;
}
n += ngx_sprint_uchar(&text[n], p[i++], len - n);
} while (i < 4);
if (len == n) {
text[n] = '\0';
return n;
}
text[n] = '\0';
return n;
#if 0
return ngx_snprintf((char *) text,
len > INET_ADDRSTRLEN ? INET_ADDRSTRLEN : len,
"%u.%u.%u.%u", p[0], p[1], p[2], p[3]);
#endif
}
size_t ngx_inet_ntop(int family, u_char *addr, u_char *text, size_t len)
size_t ngx_inet_ntop(int family, void *addr, u_char *text, size_t len)
{
u_char *p;
size_t n;
ngx_uint_t i;
if (len == 0) {
return 0;
}
if (family != AF_INET) {
return 0;
}
p = (u_char *) addr;
if (len > INET_ADDRSTRLEN) {
len = INET_ADDRSTRLEN;
}
n = ngx_sprint_uchar(text, p[0], len);
i = 1;
do {
if (len == n) {
text[n - 1] = '\0';
return n;
}
text[n++] = '.';
if (len == n) {
text[n - 1] = '\0';
return n;
}
n += ngx_sprint_uchar(&text[n], p[i++], len - n);
} while (i < 4);
if (len == n) {
text[n] = '\0';
return n;
}
text[n] = '\0';
return n;
#if 0
return ngx_snprintf((char *) text,
len > INET_ADDRSTRLEN ? INET_ADDRSTRLEN : len,
"%u.%u.%u.%u", addr[0], addr[1], addr[2], addr[3]);
"%u.%u.%u.%u", p[0], p[1], p[2], p[3]);
#endif
}

View File

@ -4,7 +4,7 @@
size_t ngx_sock_ntop(int family, struct sockaddr *addr, u_char *text,
size_t len);
size_t ngx_inet_ntop(int family, u_char *addr, u_char *text, size_t len);
size_t ngx_inet_ntop(int family, void *addr, u_char *text, size_t len);
#endif /* _NGX_INET_H_INCLUDED_ */

View File

@ -265,8 +265,14 @@ int ngx_chain_writer(void *data, ngx_chain_t *in)
ctx->last = &cl->next;
}
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0,
"WRITER0: %X", ctx->out);
ctx->out = ngx_write_chain(ctx->connection, ctx->out);
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0,
"WRITER1: %X", ctx->out);
if (ctx->out == NGX_CHAIN_ERROR) {
return NGX_ERROR;
}

View File

@ -207,8 +207,8 @@ int ngx_event_connect_peer(ngx_peer_connection_t *pc)
addr.sin_port = (u_short) peer->port;
addr.sin_addr.s_addr = peer->addr;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pc->log, 0,
"connect to %s", peer->addr_port_text.data);
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pc->log, 0,
"connect to %s, #%d", peer->addr_port_text.data, c->number);
rc = connect(s, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));

View File

@ -984,7 +984,7 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
NGX_CONF_ERROR);
len = ngx_inet_ntop(AF_INET,
(u_char *) &lcf->peers->peers[i].addr,
&lcf->peers->peers[i].addr,
lcf->peers->peers[i].addr_port_text.data,
len);

View File

@ -303,8 +303,8 @@ static void ngx_http_proxy_init_upstream(void *data)
ngx_chain_t *cl;
ngx_http_request_t *r;
ngx_output_chain_ctx_t *octx;
ngx_chain_writer_ctx_t *wctx;
ngx_output_chain_ctx_t *output;
ngx_chain_writer_ctx_t *writer;
ngx_http_proxy_log_ctx_t *lctx;
r = p->request;
@ -359,27 +359,27 @@ static void ngx_http_proxy_init_upstream(void *data)
r->connection->log->handler = ngx_http_proxy_log_error;
p->action = "connecting to upstream";
if (!(octx = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t)))) {
if (!(output = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t)))) {
ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
p->upstream->output_chain_ctx = octx;
p->upstream->output_chain_ctx = output;
octx->sendfile = r->sendfile;
octx->pool = r->pool;
octx->bufs.num = 1;
octx->tag = (ngx_hunk_tag_t) &ngx_http_proxy_module;
octx->output_filter = (ngx_output_chain_filter_pt) ngx_chain_writer;
output->sendfile = r->sendfile;
output->pool = r->pool;
output->bufs.num = 1;
output->tag = (ngx_hunk_tag_t) &ngx_http_proxy_module;
output->output_filter = (ngx_output_chain_filter_pt) ngx_chain_writer;
if (!(wctx = ngx_palloc(r->pool, sizeof(ngx_chain_writer_ctx_t)))) {
if (!(writer = ngx_palloc(r->pool, sizeof(ngx_chain_writer_ctx_t)))) {
ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
octx->output_ctx = wctx;
output->output_ctx = writer;
wctx->pool = r->pool;
writer->pool = r->pool;
if (p->lcf->busy_lock && !p->busy_locked) {
ngx_http_proxy_upstream_busy_lock(p);
@ -392,9 +392,9 @@ static void ngx_http_proxy_init_upstream(void *data)
static void ngx_http_proxy_reinit_upstream(ngx_http_proxy_ctx_t *p)
{
ngx_chain_t *cl;
ngx_output_chain_ctx_t *octx;
ngx_output_chain_ctx_t *output;
octx = p->upstream->output_chain_ctx;
output = p->upstream->output_chain_ctx;
/* reinit the request chain */
@ -404,10 +404,10 @@ static void ngx_http_proxy_reinit_upstream(ngx_http_proxy_ctx_t *p)
/* reinit ngx_output_chain() context */
octx->hunk = NULL;
octx->in = NULL;
octx->free = NULL;
octx->busy = NULL;
output->hunk = NULL;
output->in = NULL;
output->free = NULL;
output->busy = NULL;
/* reinit r->header_in buffer */
@ -487,7 +487,7 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
int rc;
ngx_connection_t *c;
ngx_http_request_t *r;
ngx_output_chain_ctx_t *octx;
ngx_output_chain_ctx_t *output;
p->action = "connecting to upstream";
@ -517,7 +517,7 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
c->pool = r->pool;
c->read->log = c->write->log = c->log = r->connection->log;
octx = p->upstream->output_chain_ctx;
output = p->upstream->output_chain_ctx;
if (p->upstream->peer.tries > 1 && p->request_sent) {
ngx_http_proxy_reinit_upstream(p);
@ -526,14 +526,14 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
/* init or reinit ngx_output_chain() context */
if (r->request_body_hunk) {
if (!(octx->free = ngx_alloc_chain_link(r->pool))) {
if (!(output->free = ngx_alloc_chain_link(r->pool))) {
ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
octx->free->hunk = r->request_body_hunk;
octx->free->next = NULL;
octx->hunks = 1;
output->free->hunk = r->request_body_hunk;
output->free->next = NULL;
output->hunks = 1;
r->request_body_hunk->pos = r->request_body_hunk->start;
r->request_body_hunk->last = r->request_body_hunk->start;
@ -565,7 +565,7 @@ static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p)
{
int rc;
ngx_connection_t *c;
ngx_chain_writer_ctx_t *wctx;
ngx_chain_writer_ctx_t *writer;
c = p->upstream->peer.connection;
@ -586,10 +586,10 @@ static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p)
p->action = "sending request to upstream";
wctx = p->upstream->output_chain_ctx->output_ctx;
wctx->out = NULL;
wctx->last = &wctx->out;
wctx->connection = c;
writer = p->upstream->output_chain_ctx->output_ctx;
writer->out = NULL;
writer->last = &writer->out;
writer->connection = c;
rc = ngx_output_chain(p->upstream->output_chain_ctx,
p->request_sent ? NULL : p->request->request_hunks);

View File

@ -496,8 +496,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ls->addr_text.len =
ngx_snprintf((char *) ls->addr_text.data
+ ngx_inet_ntop(AF_INET,
(u_char *)
&in_addr[a].addr,
&in_addr[a].addr,
ls->addr_text.data,
INET_ADDRSTRLEN),
6, ":%d", in_port[p].port);
@ -597,7 +596,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
in_addr = in_port[p].addrs.elts;
for (a = 0; a < in_port[p].addrs.nelts; a++) {
u_char ip[20];
ngx_inet_ntop(AF_INET, (u_char *) &in_addr[a].addr, ip, 20);
ngx_inet_ntop(AF_INET, &in_addr[a].addr, ip, 20);
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0,
"%s %08x", ip, in_addr[a].core_srv_conf);
s_name = in_addr[a].names.elts;

View File

@ -458,7 +458,7 @@ ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_hunk_t *h)
state = sw_name;
r->header_name_start = p - 1;
c = (char) (ch | 0x20);
c = (u_char) (ch | 0x20);
if (c >= 'a' && c <= 'z') {
break;
}
@ -778,15 +778,15 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
case sw_quoted:
if (ch >= '0' && ch <= '9') {
decoded = (char) (ch - '0');
decoded = (u_char) (ch - '0');
state = sw_quoted_second;
ch = *p++;
break;
}
c = (char) (ch | 0x20);
c = (u_char) (ch | 0x20);
if (c >= 'a' && c <= 'f') {
decoded = (char) (c - 'a' + 10);
decoded = (u_char) (c - 'a' + 10);
state = sw_quoted_second;
ch = *p++;
break;
@ -796,7 +796,7 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
case sw_quoted_second:
if (ch >= '0' && ch <= '9') {
ch = (char) ((decoded << 4) + ch - '0');
ch = (u_char) ((decoded << 4) + ch - '0');
if (ch == '%') {
state = sw_usual;
*u++ = ch;
@ -807,9 +807,9 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
break;
}
c = (char) (ch | 0x20);
c = (u_char) (ch | 0x20);
if (c >= 'a' && c <= 'f') {
ch = (char) ((decoded << 4) + c - 'a' + 10);
ch = (u_char) ((decoded << 4) + c - 'a' + 10);
if (ch == '%') {
state = sw_usual;
*u++ = ch;

View File

@ -64,6 +64,7 @@ void ngx_http_init_connection(ngx_connection_t *c)
c->addr_text.len = ngx_sock_ntop(c->listening->family, c->sockaddr,
c->addr_text.data,
c->listening->addr_text_max_len);
if (c->addr_text.len == 0) {
ngx_http_close_connection(c);
return;

View File

@ -43,7 +43,7 @@ ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size);
#else
#define ngx_strerror_r(err, errstr, size) \
ngx_cpystrn(errstr, strerror(err), size) - (errstr)
(char *) ngx_cpystrn(errstr, strerror(err), size) - (errstr)
#endif