mirror of
https://github.com/nginx/nginx.git
synced 2025-01-04 13:17:15 -06:00
nginx-0.0.1-2003-07-21-01:15:59 import
This commit is contained in:
parent
8e1fbe61b6
commit
890fc96596
@ -66,8 +66,10 @@ int rotate;
|
||||
int main(int argc, char *const *argv)
|
||||
{
|
||||
int i;
|
||||
ngx_fd_t fd;
|
||||
ngx_log_t *log;
|
||||
ngx_cycle_t *cycle;
|
||||
ngx_open_file_t *file;
|
||||
ngx_core_conf_t *ccf;
|
||||
|
||||
#if (NGX_DEBUG) && (__FreeBSD__)
|
||||
@ -150,6 +152,55 @@ int main(int argc, char *const *argv)
|
||||
|
||||
if (rotate) {
|
||||
ngx_log_debug(ngx_cycle->log, "rotate");
|
||||
|
||||
file = cycle->open_files.elts;
|
||||
for (i = 0; i < cycle->open_files.nelts; i++) {
|
||||
if (file[i].name.data == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fd = ngx_open_file(file[i].name.data,
|
||||
NGX_FILE_RDWR,
|
||||
NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
|
||||
|
||||
ngx_log_debug(log, "REOPEN: %d:%d:%s" _ fd _ file[i].fd _ file[i].name.data);
|
||||
|
||||
if (fd == NGX_INVALID_FILE) {
|
||||
ngx_log_error(NGX_LOG_EMERG,
|
||||
ngx_cycle->log, ngx_errno,
|
||||
ngx_open_file_n " \"%s\" failed",
|
||||
file[i].name.data);
|
||||
continue;
|
||||
}
|
||||
|
||||
#if (WIN32)
|
||||
if (ngx_file_append_mode(fd) == NGX_ERROR) {
|
||||
ngx_log_error(NGX_LOG_EMERG,
|
||||
ngx_cycle->log, ngx_errno,
|
||||
ngx_file_append_mode_n
|
||||
" \"%s\" failed",
|
||||
file[i].name.data);
|
||||
|
||||
if (ngx_close_file(fd) == NGX_FILE_ERROR) {
|
||||
ngx_log_error(NGX_LOG_EMERG,
|
||||
ngx_cycle->log, ngx_errno,
|
||||
ngx_close_file_n " \"%s\" failed",
|
||||
file[i].name.data);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) {
|
||||
ngx_log_error(NGX_LOG_EMERG,
|
||||
ngx_cycle->log, ngx_errno,
|
||||
ngx_close_file_n " \"%s\" failed",
|
||||
file[i].name.data);
|
||||
}
|
||||
|
||||
file[i].fd = fd;
|
||||
}
|
||||
}
|
||||
|
||||
if (restart) {
|
||||
@ -275,25 +326,33 @@ static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log)
|
||||
|
||||
file = cycle->open_files.elts;
|
||||
for (i = 0; i < cycle->open_files.nelts; i++) {
|
||||
if (file->name.data == NULL) {
|
||||
if (file[i].name.data == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
file->fd = ngx_open_file(file->name.data,
|
||||
NGX_FILE_RDWR,
|
||||
NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
|
||||
file[i].fd = ngx_open_file(file[i].name.data,
|
||||
NGX_FILE_RDWR,
|
||||
NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
|
||||
|
||||
ngx_log_debug(log, "OPEN: %d:%s" _ file->fd _ file->name.data);
|
||||
ngx_log_debug(log, "OPEN: %d:%s" _ file[i].fd _ file[i].name.data);
|
||||
|
||||
if (file->fd == NGX_INVALID_FILE) {
|
||||
if (file[i].fd == NGX_INVALID_FILE) {
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
|
||||
ngx_open_file_n " \"%s\" failed",
|
||||
file->name.data);
|
||||
file[i].name.data);
|
||||
failed = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* TODO: Win32 append */
|
||||
#if (WIN32)
|
||||
if (ngx_file_append_mode(file[i].fd) == NGX_ERROR) {
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
|
||||
ngx_file_append_mode_n " \"%s\" failed",
|
||||
file[i].name.data);
|
||||
failed = 1;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* STUB */ cycle->log->log_level = NGX_LOG_DEBUG;
|
||||
@ -341,14 +400,14 @@ ngx_log_debug(log, "OPEN: %d:%s" _ file->fd _ file->name.data);
|
||||
|
||||
file = cycle->open_files.elts;
|
||||
for (i = 0; i < cycle->open_files.nelts; i++) {
|
||||
if (file->fd == NGX_INVALID_FILE) {
|
||||
if (file[i].fd == NGX_INVALID_FILE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_close_file(file->fd) == NGX_FILE_ERROR) {
|
||||
if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) {
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
|
||||
ngx_close_file_n " \"%s\" failed",
|
||||
file->name.data);
|
||||
file[i].name.data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -405,14 +464,14 @@ ngx_log_debug(log, "OPEN: %d:%s" _ file->fd _ file->name.data);
|
||||
|
||||
file = old_cycle->open_files.elts;
|
||||
for (i = 0; i < old_cycle->open_files.nelts; i++) {
|
||||
if (file->fd == NGX_INVALID_FILE) {
|
||||
if (file[i].fd == NGX_INVALID_FILE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_close_file(file->fd) == NGX_FILE_ERROR) {
|
||||
if (ngx_close_file(file[i].fd) == NGX_FILE_ERROR) {
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
|
||||
ngx_close_file_n " \"%s\" failed",
|
||||
file->name.data);
|
||||
file[i].name.data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,8 @@
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
char ngx_conf_errstr[MAX_CONF_ERRSTR];
|
||||
|
||||
#define MAX_CONF_ERRSTR 256
|
||||
|
||||
static int argument_number[] = {
|
||||
NGX_CONF_NOARGS,
|
||||
@ -212,19 +212,11 @@ ngx_log_debug(cf->log, "rv: %d" _ rv);
|
||||
break;
|
||||
|
||||
} else {
|
||||
if (rv == ngx_conf_errstr) {
|
||||
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
||||
"%s in %s:%d",
|
||||
rv,
|
||||
cf->conf_file->file.name.data,
|
||||
cf->conf_file->line);
|
||||
} else {
|
||||
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
||||
"\"%s\" directive %s in %s:%d",
|
||||
name->data, rv,
|
||||
cf->conf_file->file.name.data,
|
||||
cf->conf_file->line);
|
||||
}
|
||||
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
||||
"\"%s\" directive %s in %s:%d",
|
||||
name->data, rv,
|
||||
cf->conf_file->file.name.data,
|
||||
cf->conf_file->line);
|
||||
|
||||
rc = NGX_ERROR;
|
||||
break;
|
||||
@ -475,6 +467,34 @@ ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data);
|
||||
}
|
||||
|
||||
|
||||
ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
|
||||
{
|
||||
int i;
|
||||
ngx_open_file_t *file;
|
||||
|
||||
if (name) {
|
||||
file = cycle->open_files.elts;
|
||||
for (i = 0; i < cycle->open_files.nelts; i++) {
|
||||
if (name->len != file[i].name.len) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_strcmp(name->data, file[i].name.data) == 0) {
|
||||
return &file[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ngx_test_null(file, ngx_push_array(&cycle->open_files), NULL);
|
||||
file->fd = NGX_INVALID_FILE;
|
||||
if (name) {
|
||||
file->name = *name;
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
void ngx_conf_log_error(int level, ngx_conf_t *cf, ngx_err_t err,
|
||||
char *fmt, ...)
|
||||
{
|
||||
@ -526,10 +546,11 @@ char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
flag = 0;
|
||||
|
||||
} else {
|
||||
ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
|
||||
"invalid value \"%s\", it must be \"on\" or \"off\"",
|
||||
value[1].data);
|
||||
return ngx_conf_errstr;
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||
"invalid value \"%s\" in \"%s\" directive, "
|
||||
"it must be \"on\" or \"off\"",
|
||||
value[1].data, cmd->name.data);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
*(int *) (p + cmd->offset) = flag;
|
||||
|
@ -40,9 +40,6 @@
|
||||
#define NGX_CONF_MODULE 0x464E4F43 /* "CONF" */
|
||||
|
||||
|
||||
#define MAX_CONF_ERRSTR 256
|
||||
extern char ngx_conf_errstr[MAX_CONF_ERRSTR];
|
||||
|
||||
|
||||
struct ngx_command_s {
|
||||
ngx_str_t name;
|
||||
@ -59,6 +56,13 @@ struct ngx_command_s {
|
||||
struct ngx_open_file_s {
|
||||
ngx_fd_t fd;
|
||||
ngx_str_t name;
|
||||
#if 0
|
||||
/* e.g. append mode, error_log */
|
||||
int flags;
|
||||
/* e.g. reopen db file */
|
||||
int (*handler)(void *data, ngx_open_file_t *file);
|
||||
void *data;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@ -178,6 +182,7 @@ struct ngx_conf_s {
|
||||
char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename);
|
||||
|
||||
|
||||
ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name);
|
||||
void ngx_conf_log_error(int level, ngx_conf_t *cf, ngx_err_t err,
|
||||
char *fmt, ...);
|
||||
|
||||
@ -192,8 +197,10 @@ char *ngx_conf_set_time_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
char *ngx_conf_set_core_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
|
||||
|
||||
extern ngx_module_t *ngx_modules[];
|
||||
extern ngx_cycle_t *ngx_cycle;
|
||||
extern ngx_array_t ngx_old_cycles;
|
||||
|
||||
|
||||
#endif /* _NGX_HTTP_CONF_FILE_H_INCLUDED_ */
|
||||
|
@ -32,6 +32,13 @@
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef NGX_SERVER_ROOT
|
||||
#define NGX_SERVER_ROOT "./"
|
||||
#if 0
|
||||
#define NGX_SERVER_ROOT "/usr/local/nginx/"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if !(WIN32)
|
||||
|
||||
|
@ -69,6 +69,10 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
|
||||
int written;
|
||||
#endif
|
||||
|
||||
if (log->file->fd == NGX_INVALID_FILE) {
|
||||
return;
|
||||
}
|
||||
|
||||
ngx_localtime(&tm);
|
||||
len = ngx_snprintf(errstr, sizeof(errstr), "%4d/%02d/%02d %02d:%02d:%02d",
|
||||
tm.ngx_tm_year, tm.ngx_tm_mon, tm.ngx_tm_mday,
|
||||
@ -121,21 +125,16 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
|
||||
}
|
||||
|
||||
#if (WIN32)
|
||||
errstr[len++] = '\r';
|
||||
errstr[len++] = '\n';
|
||||
if (log->file->fd) {
|
||||
WriteFile(log->file->fd, errstr, len, &written, NULL);
|
||||
}
|
||||
|
||||
errstr[len++] = CR;
|
||||
errstr[len++] = LF;
|
||||
WriteFile(log->file->fd, errstr, len, &written, NULL);
|
||||
|
||||
#else
|
||||
errstr[len++] = '\n';
|
||||
|
||||
errstr[len++] = LF;
|
||||
write(log->file->fd, errstr, len);
|
||||
#endif
|
||||
|
||||
|
||||
#if 0
|
||||
errstr[len] = '\0';
|
||||
fputs(errstr, stderr);
|
||||
fflush(stderr);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -225,6 +224,8 @@ ngx_log_t *ngx_log_init_errlog()
|
||||
} else if (ngx_stderr.fd == NULL) {
|
||||
/* there are no associated standard handles */
|
||||
/* TODO: where we can log possible errors ? */
|
||||
|
||||
ngx_stderr.fd = NGX_INVALID_FILE;
|
||||
}
|
||||
|
||||
#else
|
||||
@ -246,11 +247,9 @@ ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_str_t *name)
|
||||
ngx_log_t *log;
|
||||
|
||||
ngx_test_null(log, ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)), NULL);
|
||||
ngx_test_null(log->file, ngx_push_array(&cycle->open_files), NULL);
|
||||
log->file->fd = NGX_INVALID_FILE;
|
||||
if (name) {
|
||||
log->file->name = *name;
|
||||
}
|
||||
ngx_test_null(log->file, ngx_conf_open_file(cycle, name), NULL);
|
||||
|
||||
/* STUB */ log->log_level = NGX_LOG_DEBUG;
|
||||
|
||||
return log;
|
||||
}
|
||||
|
@ -378,7 +378,7 @@ int ngx_devpoll_process_events(ngx_log_t *log)
|
||||
} else {
|
||||
if (events == 0) {
|
||||
ngx_log_error(NGX_LOG_ALERT, log, 0,
|
||||
"ioctl(DP_POLL) returns no events without timeout");
|
||||
"ioctl(DP_POLL) returned no events without timeout");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ static int ngx_poll_init(ngx_cycle_t *cycle)
|
||||
nevents = 0;
|
||||
}
|
||||
|
||||
if (cycle->old_cycle == NULL
|
||||
if (cycle->old_cycle == NULL
|
||||
|| cycle->old_cycle->connection_n < cycle->connection_n)
|
||||
{
|
||||
ngx_test_null(list,
|
||||
@ -272,7 +272,7 @@ static int ngx_poll_process_events(ngx_log_t *log)
|
||||
} else {
|
||||
if (ready == 0) {
|
||||
ngx_log_error(NGX_LOG_ALERT, log, 0,
|
||||
"poll() returns no events without timeout");
|
||||
"poll() returned no events without timeout");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
|
@ -263,7 +263,11 @@ static int ngx_select_process_events(ngx_log_t *log)
|
||||
tv.tv_sec = timer / 1000;
|
||||
tv.tv_usec = (timer % 1000) * 1000;
|
||||
tp = &tv;
|
||||
#if (HAVE_SELECT_CHANGE_TIMEOUT)
|
||||
delta = 0;
|
||||
#else
|
||||
delta = ngx_msec();
|
||||
#endif
|
||||
|
||||
} else {
|
||||
timer = 0;
|
||||
@ -313,8 +317,11 @@ static int ngx_select_process_events(ngx_log_t *log)
|
||||
#endif
|
||||
|
||||
if (timer) {
|
||||
/* TODO: Linux returns time in tv */
|
||||
#if (HAVE_SELECT_CHANGE_TIMEOUT)
|
||||
delta = timer - (tv.tv_sec * 1000 + tv.tv_usec / 1000);
|
||||
#else
|
||||
delta = ngx_msec() - delta;
|
||||
#endif
|
||||
|
||||
#if (NGX_DEBUG_EVENT)
|
||||
ngx_log_debug(log, "select timer: %d, delta: %d" _ timer _ delta);
|
||||
@ -324,7 +331,7 @@ static int ngx_select_process_events(ngx_log_t *log)
|
||||
} else {
|
||||
if (ready == 0) {
|
||||
ngx_log_error(NGX_LOG_ALERT, log, 0,
|
||||
"select() returns no events without timeout");
|
||||
"select() returned no events without timeout");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
@ -408,7 +415,7 @@ static char *ngx_select_init_conf(ngx_cycle_t *cycle, void *conf)
|
||||
|
||||
ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module);
|
||||
|
||||
/* the default FD_SETSIZE is 1024U in FreeBSD 5.x */
|
||||
/* disable warnings: the default FD_SETSIZE is 1024U in FreeBSD 5.x */
|
||||
|
||||
if ((unsigned) ecf->connections > FD_SETSIZE) {
|
||||
return "maximum number of connections "
|
||||
|
@ -67,6 +67,7 @@ ngx_log_debug(ev->log, "ADDR %s" _ ls->listening->addr_text.data);
|
||||
}
|
||||
|
||||
/* disable warnings: Win32 SOCKET is u_int while UNIX socket is int */
|
||||
|
||||
if ((unsigned) s >= (unsigned) ecf->connections) {
|
||||
|
||||
ngx_log_error(NGX_LOG_ALERT, ev->log, 0,
|
||||
@ -183,7 +184,7 @@ ngx_log_debug(ev->log, "ADDR %s" _ ls->listening->addr_text.data);
|
||||
if (c->log == NULL) {
|
||||
return;
|
||||
}
|
||||
ngx_memcpy(c->log, ev->log, sizeof(ngx_log_t));
|
||||
ngx_memcpy(c->log, ls->log, sizeof(ngx_log_t));
|
||||
rev->log = wev->log = c->log;
|
||||
|
||||
/* TODO: x86: MT: lock xadd, MP: lock xadd, shared */
|
||||
|
@ -4,16 +4,21 @@
|
||||
|
||||
int ngx_event_connect_peer(ngx_connect_peer_t *cp)
|
||||
{
|
||||
time_t now;
|
||||
|
||||
/* TODO: cached connection */
|
||||
|
||||
now = ngx_time();
|
||||
|
||||
if (cp->peers->number > 1) {
|
||||
|
||||
/* it's a first try - get current peer */
|
||||
/* there are several peers */
|
||||
|
||||
if (cp->tries == cp->peers->number) {
|
||||
|
||||
/* Here is the race condition
|
||||
when the peers are shared between
|
||||
/* it's a first try - get a current peer */
|
||||
|
||||
/* Here is the race condition when the peers are shared between
|
||||
the threads or the processes but it should not be serious */
|
||||
|
||||
cp->cur_peer = cp->peers->current++;
|
||||
@ -22,10 +27,11 @@ int ngx_event_connect_peer(ngx_connect_peer_t *cp)
|
||||
cp->peers->current = 0;
|
||||
}
|
||||
|
||||
/* */
|
||||
/* the end of the race condition */
|
||||
|
||||
#if (NGX_MULTITHREADED || NGX_MULTIPROCESSED)
|
||||
/* eliminate the sequences of the race condition */
|
||||
|
||||
if (cp->cur_peer >= cp->peers->number) {
|
||||
cp->cur_peer = 0;
|
||||
}
|
||||
@ -34,11 +40,12 @@ int ngx_event_connect_peer(ngx_connect_peer_t *cp)
|
||||
|
||||
if (cp->peers->max_fails > 0) {
|
||||
|
||||
/* the peers support a fault tolerance */
|
||||
|
||||
for ( ;; ) {
|
||||
peer = &cp->peers->peers[cp->cur_peer];
|
||||
|
||||
/* Here is the race condition
|
||||
when the peers are shared between
|
||||
/* Here is the race condition when the peers are shared between
|
||||
the threads or the processes but it should not be serious */
|
||||
|
||||
if (peer->fails <= cp->peers->max_fails
|
||||
@ -47,7 +54,7 @@ int ngx_event_connect_peer(ngx_connect_peer_t *cp)
|
||||
break;
|
||||
}
|
||||
|
||||
/* */
|
||||
/* the end of the race condition */
|
||||
|
||||
cp->cur_peer++;
|
||||
|
||||
@ -71,23 +78,23 @@ int ngx_event_connect_peer(ngx_connect_peer_t *cp)
|
||||
s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0);
|
||||
|
||||
if (s == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, cn->log, ngx_socket_errno,
|
||||
ngx_log_error(NGX_LOG_ALERT, cp->log, ngx_socket_errno,
|
||||
ngx_socket_n " failed");
|
||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (cn->rcvbuf) {
|
||||
if (cp->rcvbuf) {
|
||||
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,
|
||||
(const void *) &cn->rcvbuf, sizeof(int)) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, cn->log, ngx_socket_errno,
|
||||
(const void *) &cp->rcvbuf, sizeof(int)) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, cp->log, ngx_socket_errno,
|
||||
"setsockopt(SO_RCVBUF) failed");
|
||||
|
||||
if (ngx_close_socket(s) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, cn->log, ngx_socket_errno,
|
||||
ngx_log_error(NGX_LOG_ALERT, cp->log, ngx_socket_errno,
|
||||
ngx_close_socket_n " failed");
|
||||
}
|
||||
|
||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||
return NGX_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,12 +107,33 @@ int ngx_event_connect_peer(ngx_connect_peer_t *cp)
|
||||
ngx_close_socket_n " failed");
|
||||
}
|
||||
|
||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
c = &ngx_connections[s];
|
||||
rev = &ngx_read_events[s];
|
||||
wev = &ngx_write_events[s];
|
||||
#if (WIN32)
|
||||
/*
|
||||
* Winsock assignes a socket number divisible by 4
|
||||
* so to find a connection we divide a socket number by 4.
|
||||
*/
|
||||
|
||||
if (s % 4) {
|
||||
ngx_log_error(NGX_LOG_EMERG, cp->log, 0,
|
||||
ngx_socket_n
|
||||
" created socket %d, not divisible by 4", s);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
c = &ngx_cycle->connections[s / 4];
|
||||
rev = &ngx_cycle->read_events[s / 4];
|
||||
wev = &ngx_cycle->write_events[s / 4];
|
||||
|
||||
#else
|
||||
|
||||
c = &ngx_cycle->connections[s];
|
||||
rev = &ngx_cycle->read_events[s];
|
||||
wev = &ngx_cycle->write_events[s];
|
||||
|
||||
#endif
|
||||
|
||||
instance = rev->instance;
|
||||
|
||||
@ -120,7 +148,9 @@ int ngx_event_connect_peer(ngx_connect_peer_t *cp)
|
||||
|
||||
rev->instance = wev->instance = !instance;
|
||||
|
||||
!!!!!!!!!!!!!!!
|
||||
|
||||
rev->log = wev->log = c->log = cn->log;
|
||||
c->fd = s;
|
||||
wev->close_handler = rev->close_handler = ngx_event_close_connection;
|
||||
|
||||
}
|
||||
|
@ -3,10 +3,8 @@
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_string.h>
|
||||
#include <ngx_log.h>
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_event.h>
|
||||
#include <ngx_connection.h>
|
||||
|
||||
|
||||
typedef struct {
|
||||
@ -37,6 +35,8 @@ typedef struct {
|
||||
ngx_peers_t *peers;
|
||||
int cur_peer;
|
||||
int tries;
|
||||
|
||||
unsigned cached:1;
|
||||
} ngx_connect_peer_t;
|
||||
|
||||
|
||||
|
@ -4,6 +4,10 @@
|
||||
#include <ngx_event.h>
|
||||
|
||||
|
||||
/* in multithreaded enviroment all timer operations must be
|
||||
protected by the single mutex */
|
||||
|
||||
|
||||
static ngx_event_t *ngx_timer_queue, ngx_temp_timer_queue;
|
||||
static int ngx_timer_cur_queue;
|
||||
static int ngx_timer_queue_num;
|
||||
|
@ -10,8 +10,8 @@ typedef struct {
|
||||
|
||||
|
||||
static int ngx_http_charset_filter_init(ngx_cycle_t *cycle);
|
||||
static void *ngx_http_charset_create_loc_conf(ngx_pool_t *pool);
|
||||
static char *ngx_http_charset_merge_loc_conf(ngx_pool_t *pool,
|
||||
static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf);
|
||||
static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf,
|
||||
void *parent, void *child);
|
||||
|
||||
|
||||
@ -100,19 +100,19 @@ static int ngx_http_charset_filter_init(ngx_cycle_t *cycle)
|
||||
}
|
||||
|
||||
|
||||
static void *ngx_http_charset_create_loc_conf(ngx_pool_t *pool)
|
||||
static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf)
|
||||
{
|
||||
ngx_http_charset_loc_conf_t *lcf;
|
||||
|
||||
ngx_test_null(lcf,
|
||||
ngx_pcalloc(pool, sizeof(ngx_http_charset_loc_conf_t)),
|
||||
ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_loc_conf_t)),
|
||||
NGX_CONF_ERROR);
|
||||
|
||||
return lcf;
|
||||
}
|
||||
|
||||
|
||||
static char *ngx_http_charset_merge_loc_conf(ngx_pool_t *pool,
|
||||
static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf,
|
||||
void *parent, void *child)
|
||||
{
|
||||
ngx_http_charset_loc_conf_t *prev = parent;
|
||||
|
@ -15,11 +15,11 @@ typedef struct {
|
||||
|
||||
static int ngx_http_index_test_dir(ngx_http_request_t *r);
|
||||
static int ngx_http_index_init(ngx_cycle_t *cycle);
|
||||
static void *ngx_http_index_create_conf(ngx_pool_t *pool);
|
||||
static char *ngx_http_index_merge_conf(ngx_pool_t *p, void *parent,
|
||||
void *child);
|
||||
static void *ngx_http_index_create_conf(ngx_conf_t *cf);
|
||||
static char *ngx_http_index_merge_conf(ngx_conf_t *cf,
|
||||
void *parent, void *child);
|
||||
static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
void *conf);
|
||||
|
||||
|
||||
static ngx_command_t ngx_http_index_commands[] = {
|
||||
@ -220,14 +220,15 @@ static int ngx_http_index_init(ngx_cycle_t *cycle)
|
||||
}
|
||||
|
||||
|
||||
static void *ngx_http_index_create_conf(ngx_pool_t *pool)
|
||||
static void *ngx_http_index_create_conf(ngx_conf_t *cf)
|
||||
{
|
||||
ngx_http_index_conf_t *conf;
|
||||
|
||||
ngx_test_null(conf, ngx_palloc(pool, sizeof(ngx_http_index_conf_t)),
|
||||
ngx_test_null(conf, ngx_palloc(cf->pool, sizeof(ngx_http_index_conf_t)),
|
||||
NGX_CONF_ERROR);
|
||||
|
||||
ngx_init_array(conf->indices, pool, 3, sizeof(ngx_str_t), NGX_CONF_ERROR);
|
||||
ngx_init_array(conf->indices, cf->pool, 3, sizeof(ngx_str_t),
|
||||
NGX_CONF_ERROR);
|
||||
conf->max_index_len = 0;
|
||||
|
||||
return conf;
|
||||
@ -236,7 +237,8 @@ static void *ngx_http_index_create_conf(ngx_pool_t *pool)
|
||||
|
||||
/* TODO: remove duplicate indices */
|
||||
|
||||
static char *ngx_http_index_merge_conf(ngx_pool_t *p, void *parent, void *child)
|
||||
static char *ngx_http_index_merge_conf(ngx_conf_t *cf,
|
||||
void *parent, void *child)
|
||||
{
|
||||
ngx_http_index_conf_t *prev = parent;
|
||||
ngx_http_index_conf_t *conf = child;
|
||||
|
@ -5,14 +5,14 @@
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_file_t file;
|
||||
ngx_open_file_t *file;
|
||||
} ngx_http_log_conf_t;
|
||||
|
||||
|
||||
static void *ngx_http_log_create_conf(ngx_pool_t *pool);
|
||||
static char *ngx_http_log_merge_conf(ngx_pool_t *p, void *parent, void *child);
|
||||
static void *ngx_http_log_create_conf(ngx_conf_t *cf);
|
||||
static char *ngx_http_log_merge_conf(ngx_conf_t *cf, void *parent, void *child);
|
||||
static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
void *conf);
|
||||
|
||||
static ngx_command_t ngx_http_log_commands[] = {
|
||||
|
||||
@ -49,6 +49,8 @@ ngx_module_t ngx_http_log_module = {
|
||||
};
|
||||
|
||||
|
||||
static ngx_str_t http_access_log = ngx_string("access.log");
|
||||
|
||||
|
||||
static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
|
||||
@ -60,6 +62,9 @@ int ngx_http_log_handler(ngx_http_request_t *r)
|
||||
size_t len;
|
||||
ngx_tm_t tm;
|
||||
ngx_http_log_conf_t *lcf;
|
||||
#if (WIN32)
|
||||
int written;
|
||||
#endif
|
||||
|
||||
ngx_log_debug(r->connection->log, "log handler");
|
||||
|
||||
@ -135,35 +140,47 @@ int ngx_http_log_handler(ngx_http_request_t *r)
|
||||
*p++ = '"';
|
||||
|
||||
#if (WIN32)
|
||||
|
||||
*p++ = CR; *p++ = LF;
|
||||
WriteFile(lcf->file->fd, line, p - line, &written, NULL);
|
||||
|
||||
#else
|
||||
|
||||
*p++ = LF;
|
||||
write(lcf->file->fd, line, p - line);
|
||||
|
||||
#endif
|
||||
|
||||
write(lcf->file.fd, line, p - line);
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
static void *ngx_http_log_create_conf(ngx_pool_t *pool)
|
||||
static void *ngx_http_log_create_conf(ngx_conf_t *cf)
|
||||
{
|
||||
ngx_http_log_conf_t *conf;
|
||||
|
||||
ngx_test_null(conf, ngx_pcalloc(pool, sizeof(ngx_http_log_conf_t)),
|
||||
ngx_test_null(conf, ngx_pcalloc(cf->pool, sizeof(ngx_http_log_conf_t)),
|
||||
NGX_CONF_ERROR);
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
|
||||
static char *ngx_http_log_merge_conf(ngx_pool_t *p, void *parent, void *child)
|
||||
static char *ngx_http_log_merge_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
{
|
||||
ngx_http_log_conf_t *prev = parent;
|
||||
ngx_http_log_conf_t *conf = child;
|
||||
|
||||
/* STUB */
|
||||
*conf = *prev;
|
||||
if (conf->file == NULL) {
|
||||
if (prev->file) {
|
||||
conf->file = prev->file;
|
||||
} else {
|
||||
ngx_test_null(conf->file,
|
||||
ngx_conf_open_file(cf->cycle, &http_access_log),
|
||||
NGX_CONF_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
@ -174,44 +191,12 @@ static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
{
|
||||
ngx_http_log_conf_t *lcf = conf;
|
||||
|
||||
int len;
|
||||
ngx_err_t err;
|
||||
ngx_str_t *value;
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
lcf->file.name.len = value[1].len;
|
||||
lcf->file.name.data = value[1].data;
|
||||
|
||||
lcf->file.fd = ngx_open_file(lcf->file.name.data,
|
||||
NGX_FILE_RDWR,
|
||||
NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
|
||||
|
||||
if (lcf->file.fd == NGX_INVALID_FILE) {
|
||||
err = ngx_errno;
|
||||
len = ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
|
||||
ngx_open_file_n " \"%s\" failed (%d: ",
|
||||
lcf->file.name.data, err);
|
||||
len += ngx_strerror_r(err, ngx_conf_errstr + len,
|
||||
sizeof(ngx_conf_errstr) - len - 1);
|
||||
ngx_conf_errstr[len++] = ')';
|
||||
ngx_conf_errstr[len++] = '\0';
|
||||
return ngx_conf_errstr;
|
||||
}
|
||||
|
||||
#if (WIN32)
|
||||
if (ngx_file_append_mode(lcf->file.fd) == NGX_ERROR) {
|
||||
err = ngx_errno;
|
||||
len = ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
|
||||
ngx_file_append_mode_n " \"%s\" failed (%d: ",
|
||||
lcf->file.name.data, err);
|
||||
len += ngx_strerror_r(err, ngx_conf_errstr + len,
|
||||
sizeof(ngx_conf_errstr) - len - 1);
|
||||
ngx_conf_errstr[len++] = ')';
|
||||
ngx_conf_errstr[len++] = '\0';
|
||||
return ngx_conf_errstr;
|
||||
}
|
||||
#endif
|
||||
ngx_test_null(lcf->file, ngx_conf_open_file(cf->cycle, &value[1]),
|
||||
NGX_CONF_ERROR);
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
ngx_http_in_addr_t *in_addr, *inaddr;
|
||||
ngx_http_core_main_conf_t *cmcf;
|
||||
ngx_http_core_srv_conf_t **cscfp, *cscf;
|
||||
ngx_http_core_loc_conf_t **clcfp;
|
||||
ngx_http_core_loc_conf_t **clcfp, *clcf;
|
||||
ngx_http_listen_t *lscf;
|
||||
ngx_http_server_name_t *s_name, *name;
|
||||
#if (WIN32)
|
||||
@ -108,20 +108,17 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
mi = ngx_modules[m]->ctx_index;
|
||||
|
||||
if (module->create_main_conf) {
|
||||
ngx_test_null(ctx->main_conf[mi],
|
||||
module->create_main_conf(cf->pool),
|
||||
ngx_test_null(ctx->main_conf[mi], module->create_main_conf(cf),
|
||||
NGX_CONF_ERROR);
|
||||
}
|
||||
|
||||
if (module->create_srv_conf) {
|
||||
ngx_test_null(ctx->srv_conf[mi],
|
||||
module->create_srv_conf(cf->pool),
|
||||
ngx_test_null(ctx->srv_conf[mi], module->create_srv_conf(cf),
|
||||
NGX_CONF_ERROR);
|
||||
}
|
||||
|
||||
if (module->create_loc_conf) {
|
||||
ngx_test_null(ctx->loc_conf[mi],
|
||||
module->create_loc_conf(cf->pool),
|
||||
ngx_test_null(ctx->loc_conf[mi], module->create_loc_conf(cf),
|
||||
NGX_CONF_ERROR);
|
||||
}
|
||||
}
|
||||
@ -157,7 +154,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
/* init http{} main_conf's */
|
||||
|
||||
if (module->init_main_conf) {
|
||||
rv = module->init_main_conf(cf->pool, ctx->main_conf[mi]);
|
||||
rv = module->init_main_conf(cf, ctx->main_conf[mi]);
|
||||
if (rv != NGX_CONF_OK) {
|
||||
return rv;
|
||||
}
|
||||
@ -168,7 +165,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
/* merge the server{}s' srv_conf's */
|
||||
|
||||
if (module->merge_srv_conf) {
|
||||
rv = module->merge_srv_conf(cf->pool,
|
||||
rv = module->merge_srv_conf(cf,
|
||||
ctx->srv_conf[mi],
|
||||
cscfp[s]->ctx->srv_conf[mi]);
|
||||
if (rv != NGX_CONF_OK) {
|
||||
@ -180,7 +177,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
|
||||
/* merge the server{}'s loc_conf */
|
||||
|
||||
rv = module->merge_loc_conf(cf->pool,
|
||||
rv = module->merge_loc_conf(cf,
|
||||
ctx->loc_conf[mi],
|
||||
cscfp[s]->ctx->loc_conf[mi]);
|
||||
if (rv != NGX_CONF_OK) {
|
||||
@ -192,7 +189,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
clcfp = (ngx_http_core_loc_conf_t **)cscfp[s]->locations.elts;
|
||||
|
||||
for (l = 0; l < cscfp[s]->locations.nelts; l++) {
|
||||
rv = module->merge_loc_conf(cf->pool,
|
||||
rv = module->merge_loc_conf(cf,
|
||||
cscfp[s]->ctx->loc_conf[mi],
|
||||
clcfp[l]->loc_conf[mi]);
|
||||
if (rv != NGX_CONF_OK) {
|
||||
@ -464,12 +461,18 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
ls->nonblocking = 1;
|
||||
|
||||
ls->handler = ngx_http_init_connection;
|
||||
|
||||
#if 0
|
||||
ls->log = cf->cycle->log;
|
||||
#endif
|
||||
|
||||
cscf = in_addr[a].core_srv_conf;
|
||||
ls->pool_size = cscf->connection_pool_size;
|
||||
ls->post_accept_timeout = cscf->post_accept_timeout;
|
||||
|
||||
clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index];
|
||||
ls->log = clcf->err_log;
|
||||
|
||||
#if (WIN32)
|
||||
iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module);
|
||||
if (iocpcf->acceptex_read) {
|
||||
|
@ -20,14 +20,14 @@ typedef struct {
|
||||
|
||||
|
||||
typedef struct {
|
||||
void *(*create_main_conf)(ngx_pool_t *p);
|
||||
char *(*init_main_conf)(ngx_pool_t *p, void *conf);
|
||||
void *(*create_main_conf)(ngx_conf_t *cf);
|
||||
char *(*init_main_conf)(ngx_conf_t *cf, void *conf);
|
||||
|
||||
void *(*create_srv_conf)(ngx_pool_t *p);
|
||||
char *(*merge_srv_conf)(ngx_pool_t *p, void *prev, void *conf);
|
||||
void *(*create_srv_conf)(ngx_conf_t *cf);
|
||||
char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, void *conf);
|
||||
|
||||
void *(*create_loc_conf)(ngx_pool_t *p);
|
||||
char *(*merge_loc_conf)(ngx_pool_t *p, void *prev, void *conf);
|
||||
void *(*create_loc_conf)(ngx_conf_t *cf);
|
||||
char *(*merge_loc_conf)(ngx_conf_t *cf, void *prev, void *conf);
|
||||
} ngx_http_module_t;
|
||||
|
||||
|
||||
|
@ -11,25 +11,26 @@ int ngx_http_static_handler(ngx_http_request_t *r);
|
||||
|
||||
static int ngx_http_core_index_handler(ngx_http_request_t *r);
|
||||
|
||||
static void *ngx_http_core_create_main_conf(ngx_pool_t *pool);
|
||||
static char *ngx_http_core_init_main_conf(ngx_pool_t *pool, void *conf);
|
||||
static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool);
|
||||
static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool,
|
||||
static void *ngx_http_core_create_main_conf(ngx_conf_t *cf);
|
||||
static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf);
|
||||
static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf);
|
||||
static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
|
||||
void *parent, void *child);
|
||||
static void *ngx_http_core_create_loc_conf(ngx_pool_t *pool);
|
||||
static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool,
|
||||
static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf);
|
||||
static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
|
||||
void *parent, void *child);
|
||||
|
||||
static int ngx_http_core_init(ngx_cycle_t *cycle);
|
||||
static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy);
|
||||
static int ngx_cmp_locations(const void *first, const void *second);
|
||||
static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *dummy);
|
||||
void *dummy);
|
||||
static char *ngx_types_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf);
|
||||
static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
void *conf);
|
||||
static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
|
||||
|
||||
static ngx_command_t ngx_http_core_commands[] = {
|
||||
@ -165,6 +166,13 @@ static ngx_command_t ngx_http_core_commands[] = {
|
||||
offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
|
||||
NULL},
|
||||
|
||||
{ngx_string("error_log"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
||||
ngx_set_error_log,
|
||||
NGX_HTTP_LOC_CONF_OFFSET,
|
||||
0,
|
||||
NULL},
|
||||
|
||||
ngx_null_command
|
||||
};
|
||||
|
||||
@ -226,22 +234,25 @@ void ngx_http_handler(ngx_http_request_t *r)
|
||||
#if 0
|
||||
ngx_log_debug(r->connection->log, "trans: %s" _ clcfp[i]->name.data);
|
||||
#endif
|
||||
if (r->uri.len < clcfp[i]->name.len) {
|
||||
continue;
|
||||
}
|
||||
if (r->uri.len < clcfp[i]->name.len) {
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = ngx_strncmp(r->uri.data, clcfp[i]->name.data,
|
||||
clcfp[i]->name.len);
|
||||
rc = ngx_strncmp(r->uri.data, clcfp[i]->name.data,
|
||||
clcfp[i]->name.len);
|
||||
|
||||
ngx_log_debug(r->connection->log, "rc: %d" _ rc);
|
||||
|
||||
if (rc < 0) {
|
||||
break;
|
||||
}
|
||||
if (rc < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (rc == 0) {
|
||||
r->loc_conf = clcfp[i]->loc_conf;
|
||||
}
|
||||
if (rc == 0) {
|
||||
r->loc_conf = clcfp[i]->loc_conf;
|
||||
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
||||
r->connection->log->file = clcf->err_log->file;
|
||||
r->connection->log->log_level = clcf->err_log->log_level;
|
||||
}
|
||||
}
|
||||
|
||||
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
||||
@ -583,13 +594,13 @@ static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
||||
|
||||
if (module->create_srv_conf) {
|
||||
ngx_test_null(ctx->srv_conf[ngx_modules[m]->ctx_index],
|
||||
module->create_srv_conf(cf->pool),
|
||||
module->create_srv_conf(cf),
|
||||
NGX_CONF_ERROR);
|
||||
}
|
||||
|
||||
if (module->create_loc_conf) {
|
||||
ngx_test_null(ctx->loc_conf[ngx_modules[m]->ctx_index],
|
||||
module->create_loc_conf(cf->pool),
|
||||
module->create_loc_conf(cf),
|
||||
NGX_CONF_ERROR);
|
||||
}
|
||||
}
|
||||
@ -664,7 +675,7 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
||||
|
||||
if (module->create_loc_conf) {
|
||||
ngx_test_null(ctx->loc_conf[ngx_modules[m]->ctx_index],
|
||||
module->create_loc_conf(cf->pool),
|
||||
module->create_loc_conf(cf),
|
||||
NGX_CONF_ERROR);
|
||||
}
|
||||
}
|
||||
@ -740,22 +751,23 @@ static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
||||
}
|
||||
|
||||
|
||||
static void *ngx_http_core_create_main_conf(ngx_pool_t *pool)
|
||||
static void *ngx_http_core_create_main_conf(ngx_conf_t *cf)
|
||||
{
|
||||
ngx_http_core_main_conf_t *cmcf;
|
||||
|
||||
ngx_test_null(cmcf,
|
||||
ngx_palloc(pool, sizeof(ngx_http_core_main_conf_t)),
|
||||
ngx_palloc(cf->pool, sizeof(ngx_http_core_main_conf_t)),
|
||||
NGX_CONF_ERROR);
|
||||
|
||||
ngx_init_array(cmcf->servers, pool, 5, sizeof(ngx_http_core_srv_conf_t *),
|
||||
ngx_init_array(cmcf->servers, cf->pool,
|
||||
5, sizeof(ngx_http_core_srv_conf_t *),
|
||||
NGX_CONF_ERROR);
|
||||
|
||||
return cmcf;
|
||||
}
|
||||
|
||||
|
||||
static char *ngx_http_core_init_main_conf(ngx_pool_t *pool, void *conf)
|
||||
static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
|
||||
{
|
||||
ngx_http_core_main_conf_t *cmcf = conf;
|
||||
|
||||
@ -765,19 +777,20 @@ static char *ngx_http_core_init_main_conf(ngx_pool_t *pool, void *conf)
|
||||
}
|
||||
|
||||
|
||||
static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool)
|
||||
static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf)
|
||||
{
|
||||
ngx_http_core_srv_conf_t *cscf;
|
||||
|
||||
ngx_test_null(cscf,
|
||||
ngx_pcalloc(pool, sizeof(ngx_http_core_srv_conf_t)),
|
||||
ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t)),
|
||||
NGX_CONF_ERROR);
|
||||
|
||||
ngx_init_array(cscf->locations, pool, 5, sizeof(void *), NGX_CONF_ERROR);
|
||||
ngx_init_array(cscf->listen, pool, 5, sizeof(ngx_http_listen_t),
|
||||
NGX_CONF_ERROR);
|
||||
ngx_init_array(cscf->server_names, pool, 5, sizeof(ngx_http_server_name_t),
|
||||
ngx_init_array(cscf->locations, cf->pool,
|
||||
5, sizeof(void *), NGX_CONF_ERROR);
|
||||
ngx_init_array(cscf->listen, cf->pool, 5, sizeof(ngx_http_listen_t),
|
||||
NGX_CONF_ERROR);
|
||||
ngx_init_array(cscf->server_names, cf->pool,
|
||||
5, sizeof(ngx_http_server_name_t), NGX_CONF_ERROR);
|
||||
|
||||
cscf->connection_pool_size = NGX_CONF_UNSET;
|
||||
cscf->post_accept_timeout = NGX_CONF_UNSET;
|
||||
@ -790,14 +803,12 @@ static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool)
|
||||
}
|
||||
|
||||
|
||||
static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool,
|
||||
static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
|
||||
void *parent, void *child)
|
||||
{
|
||||
ngx_http_core_srv_conf_t *prev = parent;
|
||||
ngx_http_core_srv_conf_t *conf = child;
|
||||
|
||||
int len;
|
||||
ngx_err_t err;
|
||||
ngx_http_listen_t *l;
|
||||
ngx_http_server_name_t *n;
|
||||
|
||||
@ -817,24 +828,13 @@ static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool,
|
||||
|
||||
if (conf->server_names.nelts == 0) {
|
||||
ngx_test_null(n, ngx_push_array(&conf->server_names), NGX_CONF_ERROR);
|
||||
ngx_test_null(n->name.data, ngx_palloc(pool, NGX_MAXHOSTNAMELEN),
|
||||
ngx_test_null(n->name.data, ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN),
|
||||
NGX_CONF_ERROR);
|
||||
|
||||
if (gethostname(n->name.data, NGX_MAXHOSTNAMELEN) == -1) {
|
||||
#if 0
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
|
||||
"gethostname() failed");
|
||||
return NGX_CONF_ERROR;
|
||||
#endif
|
||||
|
||||
err = ngx_errno;
|
||||
len = ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
|
||||
"gethostname() failed (%d: ", err);
|
||||
len += ngx_strerror_r(err, ngx_conf_errstr + len,
|
||||
sizeof(ngx_conf_errstr) - len - 1);
|
||||
ngx_conf_errstr[len++] = ')';
|
||||
ngx_conf_errstr[len++] = '\0';
|
||||
return ngx_conf_errstr;
|
||||
}
|
||||
|
||||
n->name.len = ngx_strlen(n->name.data);
|
||||
@ -858,12 +858,12 @@ static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool,
|
||||
}
|
||||
|
||||
|
||||
static void *ngx_http_core_create_loc_conf(ngx_pool_t *pool)
|
||||
static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf)
|
||||
{
|
||||
ngx_http_core_loc_conf_t *lcf;
|
||||
|
||||
ngx_test_null(lcf,
|
||||
ngx_pcalloc(pool, sizeof(ngx_http_core_loc_conf_t)),
|
||||
ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)),
|
||||
NGX_CONF_ERROR);
|
||||
|
||||
/* set by ngx_pcalloc():
|
||||
@ -897,7 +897,7 @@ static ngx_http_type_t default_types[] = {
|
||||
};
|
||||
|
||||
|
||||
static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool,
|
||||
static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
|
||||
void *parent, void *child)
|
||||
{
|
||||
ngx_http_core_loc_conf_t *prev = parent;
|
||||
@ -914,13 +914,13 @@ static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool,
|
||||
|
||||
} else {
|
||||
ngx_test_null(conf->types,
|
||||
ngx_palloc(pool, NGX_HTTP_TYPES_HASH_PRIME
|
||||
ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME
|
||||
* sizeof(ngx_array_t)),
|
||||
NGX_CONF_ERROR);
|
||||
|
||||
for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) {
|
||||
ngx_init_array(conf->types[i], pool, 5, sizeof(ngx_http_type_t),
|
||||
NGX_CONF_ERROR);
|
||||
ngx_init_array(conf->types[i], cf->pool,
|
||||
5, sizeof(ngx_http_type_t), NGX_CONF_ERROR);
|
||||
}
|
||||
|
||||
for (i = 0; default_types[i].exten.len; i++) {
|
||||
@ -936,6 +936,14 @@ static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool,
|
||||
}
|
||||
}
|
||||
|
||||
if (conf->err_log == NULL) {
|
||||
if (prev->err_log) {
|
||||
conf->err_log = prev->err_log;
|
||||
} else {
|
||||
conf->err_log = cf->cycle->log;
|
||||
}
|
||||
}
|
||||
|
||||
ngx_conf_merge_str_value(conf->default_type,
|
||||
prev->default_type, "text/plain");
|
||||
|
||||
|
@ -65,7 +65,7 @@ void ngx_http_init_connection(ngx_connection_t *c)
|
||||
{
|
||||
int event;
|
||||
ngx_event_t *rev;
|
||||
ngx_http_log_ctx_t *lcx;
|
||||
ngx_http_log_ctx_t *lctx;
|
||||
|
||||
c->addr_text.data = ngx_palloc(c->pool, c->listening->addr_text_max_len);
|
||||
if (c->addr_text.data == NULL) {
|
||||
@ -81,15 +81,15 @@ void ngx_http_init_connection(ngx_connection_t *c)
|
||||
return;
|
||||
}
|
||||
|
||||
lcx = ngx_pcalloc(c->pool, sizeof(ngx_http_log_ctx_t));
|
||||
if (lcx == NULL) {
|
||||
lctx = ngx_pcalloc(c->pool, sizeof(ngx_http_log_ctx_t));
|
||||
if (lctx == NULL) {
|
||||
ngx_http_close_connection(c);
|
||||
return;
|
||||
}
|
||||
|
||||
lcx->client = c->addr_text.data;
|
||||
lcx->action = "reading client request line";
|
||||
c->log->data = lcx;
|
||||
lctx->client = c->addr_text.data;
|
||||
lctx->action = "reading client request line";
|
||||
c->log->data = lctx;
|
||||
c->log->handler = ngx_http_log_error;
|
||||
|
||||
rev = c->read;
|
||||
@ -136,6 +136,7 @@ static void ngx_http_init_request(ngx_event_t *rev)
|
||||
ngx_http_in_addr_t *in_addr;
|
||||
ngx_http_server_name_t *server_name;
|
||||
ngx_http_core_srv_conf_t *cscf;
|
||||
ngx_http_core_loc_conf_t *clcf;
|
||||
|
||||
c = rev->data;
|
||||
|
||||
@ -212,6 +213,10 @@ ngx_log_debug(rev->log, "IN: %08x" _ in_port);
|
||||
server_name = cscf->server_names.elts;
|
||||
r->server_name = &server_name->name;
|
||||
|
||||
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
||||
c->log->file = clcf->err_log->file;
|
||||
c->log->log_level = clcf->err_log->log_level;
|
||||
|
||||
if (c->buffer == NULL) {
|
||||
c->buffer = ngx_create_temp_hunk(c->pool,
|
||||
cscf->client_header_buffer_size,
|
||||
@ -265,7 +270,7 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
|
||||
ssize_t n;
|
||||
ngx_connection_t *c;
|
||||
ngx_http_request_t *r;
|
||||
ngx_http_log_ctx_t *lcx;
|
||||
ngx_http_log_ctx_t *lctx;
|
||||
ngx_http_core_srv_conf_t *cscf;
|
||||
|
||||
c = rev->data;
|
||||
@ -421,9 +426,9 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
|
||||
return;
|
||||
}
|
||||
|
||||
lcx = c->log->data;
|
||||
lcx->action = "reading client request headers";
|
||||
lcx->url = r->unparsed_uri.data;
|
||||
lctx = c->log->data;
|
||||
lctx->action = "reading client request headers";
|
||||
lctx->url = r->unparsed_uri.data;
|
||||
r->headers_in.headers = ngx_create_table(r->pool, 10);
|
||||
|
||||
if (cscf->large_client_header
|
||||
@ -505,6 +510,7 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
|
||||
ngx_http_request_t *r;
|
||||
ngx_http_server_name_t *name;
|
||||
ngx_http_core_srv_conf_t *cscf;
|
||||
ngx_http_core_loc_conf_t *clcf;
|
||||
|
||||
c = rev->data;
|
||||
r = c->data;
|
||||
@ -619,6 +625,12 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
|
||||
{
|
||||
r->srv_conf = name[i].core_srv_conf->ctx->srv_conf;
|
||||
r->loc_conf = name[i].core_srv_conf->ctx->loc_conf;
|
||||
|
||||
clcf = ngx_http_get_module_loc_conf(r,
|
||||
ngx_http_core_module);
|
||||
c->log->file = clcf->err_log->file;
|
||||
c->log->log_level = clcf->err_log->log_level;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
size_t ngx_http_get_time(char *buf, time_t t)
|
||||
{
|
||||
struct tm *tp;
|
||||
struct tm *tp;
|
||||
|
||||
tp = gmtime(&t);
|
||||
return strftime(buf, 30, "%a, %d %b %Y %H:%M:%S GMT", tp);
|
||||
|
@ -18,8 +18,8 @@ typedef struct {
|
||||
|
||||
|
||||
static int ngx_http_output_filter_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src);
|
||||
static void *ngx_http_output_filter_create_conf(ngx_pool_t *pool);
|
||||
static char *ngx_http_output_filter_merge_conf(ngx_pool_t *pool,
|
||||
static void *ngx_http_output_filter_create_conf(ngx_conf_t *cf);
|
||||
static char *ngx_http_output_filter_merge_conf(ngx_conf_t *cf,
|
||||
void *parent, void *child);
|
||||
|
||||
|
||||
@ -307,12 +307,12 @@ ngx_log_debug(src->file->log, "READ: %qd:%qd %X:%X %X:%X" _
|
||||
}
|
||||
|
||||
|
||||
static void *ngx_http_output_filter_create_conf(ngx_pool_t *pool)
|
||||
static void *ngx_http_output_filter_create_conf(ngx_conf_t *cf)
|
||||
{
|
||||
ngx_http_output_filter_conf_t *conf;
|
||||
|
||||
ngx_test_null(conf,
|
||||
ngx_palloc(pool, sizeof(ngx_http_output_filter_conf_t)),
|
||||
ngx_palloc(cf->pool, sizeof(ngx_http_output_filter_conf_t)),
|
||||
NULL);
|
||||
|
||||
conf->hunk_size = NGX_CONF_UNSET;
|
||||
@ -321,7 +321,7 @@ static void *ngx_http_output_filter_create_conf(ngx_pool_t *pool)
|
||||
}
|
||||
|
||||
|
||||
static char *ngx_http_output_filter_merge_conf(ngx_pool_t *pool,
|
||||
static char *ngx_http_output_filter_merge_conf(ngx_conf_t *cf,
|
||||
void *parent, void *child)
|
||||
{
|
||||
ngx_http_output_filter_conf_t *prev = parent;
|
||||
|
@ -15,8 +15,8 @@ typedef struct {
|
||||
} ngx_http_write_filter_ctx_t;
|
||||
|
||||
|
||||
static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool);
|
||||
static char *ngx_http_write_filter_merge_conf(ngx_pool_t *pool,
|
||||
static void *ngx_http_write_filter_create_conf(ngx_conf_t *cf);
|
||||
static char *ngx_http_write_filter_merge_conf(ngx_conf_t *cf,
|
||||
void *parent, void *child);
|
||||
static int ngx_http_write_filter_init(ngx_cycle_t *cycle);
|
||||
|
||||
@ -162,12 +162,12 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
}
|
||||
|
||||
|
||||
static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool)
|
||||
static void *ngx_http_write_filter_create_conf(ngx_conf_t *cf)
|
||||
{
|
||||
ngx_http_write_filter_conf_t *conf;
|
||||
|
||||
ngx_test_null(conf,
|
||||
ngx_palloc(pool, sizeof(ngx_http_write_filter_conf_t)),
|
||||
ngx_palloc(cf->pool, sizeof(ngx_http_write_filter_conf_t)),
|
||||
NULL);
|
||||
|
||||
conf->buffer_output = NGX_CONF_UNSET;
|
||||
@ -176,7 +176,7 @@ static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool)
|
||||
}
|
||||
|
||||
|
||||
static char *ngx_http_write_filter_merge_conf(ngx_pool_t *pool,
|
||||
static char *ngx_http_write_filter_merge_conf(ngx_conf_t *cf,
|
||||
void *parent, void *child)
|
||||
{
|
||||
ngx_http_write_filter_conf_t *prev = parent;
|
||||
|
@ -66,4 +66,9 @@
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef HAVE_SELECT_CHANGE_TIMEOUT
|
||||
#define HAVE_SELECT_CHANGE_TIMEOUT 1
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _NGX_LINUX_CONFIG_H_INCLUDED_ */
|
||||
|
@ -4,12 +4,15 @@
|
||||
|
||||
#define WIN32 1
|
||||
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <mswsock.h>
|
||||
#include <stddef.h> /* offsetof */
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <time.h> /* gmtime, strftime */
|
||||
|
||||
|
||||
#define ngx_inline __inline
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user