mirror of
https://github.com/nginx/nginx.git
synced 2025-06-07 17:52:38 +08:00
nginx-0.0.1-2003-07-11-19:17:50 import
This commit is contained in:
parent
a7f7fa878c
commit
7f125081f4
@ -9,10 +9,42 @@ static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log);
|
||||
static int ngx_open_listening_sockets(ngx_cycle_t *cycle, ngx_log_t *log);
|
||||
static void ngx_clean_old_cycles(ngx_event_t *ev);
|
||||
|
||||
|
||||
#if (NGX_DEBUG) && (__FreeBSD__)
|
||||
extern char *malloc_options;
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct {
|
||||
int daemon;
|
||||
} ngx_core_conf_t;
|
||||
|
||||
|
||||
static ngx_str_t core_name = ngx_string("core");
|
||||
|
||||
static ngx_command_t ngx_core_commands[] = {
|
||||
|
||||
{ngx_string("daemon"),
|
||||
NGX_MAIN_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_core_flag_slot,
|
||||
0,
|
||||
offsetof(ngx_core_conf_t, daemon),
|
||||
NULL},
|
||||
|
||||
ngx_null_command
|
||||
};
|
||||
|
||||
|
||||
ngx_module_t ngx_core_module = {
|
||||
NGX_MODULE,
|
||||
&core_name, /* module context */
|
||||
ngx_core_commands, /* module directives */
|
||||
NGX_CORE_MODULE, /* module type */
|
||||
NULL, /* init module */
|
||||
NULL /* init child */
|
||||
};
|
||||
|
||||
|
||||
int ngx_max_module;
|
||||
ngx_os_io_t ngx_io;
|
||||
|
||||
@ -36,6 +68,7 @@ int main(int argc, char *const *argv)
|
||||
int i;
|
||||
ngx_log_t *log;
|
||||
ngx_cycle_t *cycle;
|
||||
ngx_core_conf_t *ccf;
|
||||
|
||||
#if (NGX_DEBUG) && (__FreeBSD__)
|
||||
malloc_options = "J";
|
||||
@ -63,14 +96,18 @@ int main(int argc, char *const *argv)
|
||||
|
||||
#if !(WIN32)
|
||||
|
||||
if (0) {
|
||||
if (ngx_daemon(cycle->log) == NGX_ERROR) {
|
||||
ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx,
|
||||
ngx_core_module);
|
||||
|
||||
if (ccf->daemon != 0) {
|
||||
if (ngx_daemon(ngx_cycle->log) == NGX_ERROR) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDERR) failed");
|
||||
if (dup2(ngx_cycle->log->file->fd, STDERR_FILENO) == -1) {
|
||||
ngx_log_error(NGX_LOG_EMERG, ngx_cycle->log, ngx_errno,
|
||||
"dup2(STDERR) failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -138,6 +175,7 @@ static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log)
|
||||
ngx_conf_t conf;
|
||||
ngx_pool_t *pool;
|
||||
ngx_cycle_t *cycle, **old;
|
||||
ngx_core_conf_t *ccf;
|
||||
ngx_open_file_t *file;
|
||||
ngx_listening_t *ls, *nls;
|
||||
|
||||
@ -156,6 +194,7 @@ static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log)
|
||||
|
||||
cycle->old_cycle = old_cycle;
|
||||
|
||||
|
||||
n = old_cycle ? old_cycle->open_files.nelts : 20;
|
||||
cycle->open_files.elts = ngx_pcalloc(pool, n * sizeof(ngx_open_file_t));
|
||||
if (cycle->open_files.elts == NULL) {
|
||||
@ -167,12 +206,14 @@ static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log)
|
||||
cycle->open_files.nalloc = n;
|
||||
cycle->open_files.pool = pool;
|
||||
|
||||
|
||||
cycle->log = ngx_log_create_errlog(cycle, NULL);
|
||||
if (cycle->log == NULL) {
|
||||
ngx_destroy_pool(pool);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
n = old_cycle ? old_cycle->listening.nelts : 10;
|
||||
cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t));
|
||||
if (cycle->listening.elts == NULL) {
|
||||
@ -184,12 +225,23 @@ static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log)
|
||||
cycle->listening.nalloc = n;
|
||||
cycle->listening.pool = pool;
|
||||
|
||||
|
||||
cycle->conf_ctx = ngx_pcalloc(pool, ngx_max_module * sizeof(void *));
|
||||
if (cycle->conf_ctx == NULL) {
|
||||
ngx_destroy_pool(pool);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
ccf = ngx_pcalloc(pool, sizeof(ngx_core_conf_t));
|
||||
if (ccf == NULL) {
|
||||
ngx_destroy_pool(pool);
|
||||
return NULL;
|
||||
}
|
||||
ccf->daemon = -1;
|
||||
((void **)(cycle->conf_ctx))[ngx_core_module.index] = ccf;
|
||||
|
||||
|
||||
ngx_memzero(&conf, sizeof(ngx_conf_t));
|
||||
/* STUB: init array ? */
|
||||
conf.args = ngx_create_array(pool, 10, sizeof(ngx_str_t));
|
||||
@ -213,6 +265,7 @@ static ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle, ngx_log_t *log)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
failed = 0;
|
||||
|
||||
file = cycle->open_files.elts;
|
||||
|
@ -9,5 +9,8 @@
|
||||
extern int ngx_max_module;
|
||||
extern int ngx_connection_counter;
|
||||
|
||||
extern ngx_module_t ngx_core_module;
|
||||
|
||||
|
||||
|
||||
#endif /* _NGINX_H_INCLUDED_ */
|
||||
|
@ -471,6 +471,13 @@ ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data);
|
||||
}
|
||||
|
||||
|
||||
char *ngx_conf_set_core_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf)
|
||||
{
|
||||
return ngx_conf_set_flag_slot(cf, cmd, *(void **)conf);
|
||||
}
|
||||
|
||||
|
||||
char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
@ -184,6 +184,8 @@ char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
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;
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
extern ngx_module_t ngx_core_module;
|
||||
extern ngx_module_t ngx_errlog_module;
|
||||
|
||||
extern ngx_module_t ngx_events_module;
|
||||
@ -46,6 +47,7 @@ ngx_module_t *ngx_modules[] = {
|
||||
|
||||
/* core */
|
||||
|
||||
&ngx_core_module,
|
||||
&ngx_errlog_module,
|
||||
|
||||
/* events */
|
||||
|
@ -179,14 +179,12 @@ ngx_log_debug(ev->log, "ADDR %s" _ ls->listening->addr_text.data);
|
||||
c->ctx = ls->ctx;
|
||||
c->servers = ls->servers;
|
||||
|
||||
#if 0
|
||||
c->log = ngx_palloc(c->pool, sizeof(ngx_log_t));
|
||||
if (c->log == NULL) {
|
||||
return;
|
||||
}
|
||||
ngx_memcpy(c->log, ev->log, sizeof(ngx_log_t));
|
||||
#endif
|
||||
rev->log = wev->log = c->log = ev->log;
|
||||
rev->log = wev->log = c->log;
|
||||
|
||||
/* TODO: x86: MT: lock xadd, MP: lock xadd, shared */
|
||||
c->number = ngx_connection_counter++;
|
||||
|
@ -43,6 +43,7 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r)
|
||||
int rc, boundary, len, i;
|
||||
char *p;
|
||||
off_t start, end;
|
||||
ngx_table_elt_t *accept_ranges;
|
||||
ngx_http_range_t *range;
|
||||
ngx_http_range_filter_ctx_t *ctx;
|
||||
|
||||
@ -51,11 +52,24 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r)
|
||||
|| r->headers_out.status != NGX_HTTP_OK
|
||||
|| r->headers_out.content_length == -1
|
||||
/* STUB: we currently support ranges for file hunks only */
|
||||
|| r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY
|
||||
|| r->headers_in.range == NULL
|
||||
|| r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY)
|
||||
{
|
||||
return next_header_filter(r);
|
||||
}
|
||||
|
||||
if (r->headers_in.range == NULL
|
||||
|| r->headers_in.range->value.len < 7
|
||||
|| ngx_strncasecmp(r->headers_in.range->value.data, "bytes=", 6) != 0)
|
||||
{
|
||||
ngx_test_null(accept_ranges,
|
||||
ngx_push_table(r->headers_out.headers),
|
||||
NGX_ERROR);
|
||||
|
||||
accept_ranges->key.len = sizeof("Accept-Ranges") - 1;
|
||||
accept_ranges->key.data = "Accept-Ranges";
|
||||
accept_ranges->value.len = sizeof("bytes") - 1;
|
||||
accept_ranges->value.data = "bytes";
|
||||
|
||||
return next_header_filter(r);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user