mirror of
https://github.com/nginx/nginx.git
synced 2025-01-22 14:23:18 -06:00
nginx-0.0.1-2003-06-15-22:32:13 import
This commit is contained in:
parent
0915977df5
commit
be2cfc3d28
@ -41,6 +41,7 @@ int main(int argc, char *const *argv)
|
||||
|
||||
/* STUB */ ngx_log.log_level = NGX_LOG_DEBUG;
|
||||
#endif
|
||||
|
||||
log = ngx_log_init_errlog();
|
||||
|
||||
if (ngx_os_init(log) == NGX_ERROR) {
|
||||
@ -230,6 +231,9 @@ static int ngx_open_listening_sockets(ngx_log_t *log)
|
||||
}
|
||||
|
||||
if (failed) {
|
||||
|
||||
/* TODO: configurable */
|
||||
|
||||
ngx_log_error(NGX_LOG_EMERG, log, 0, "can not bind(), exiting");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
@ -102,6 +102,11 @@ struct ngx_conf_s {
|
||||
conf = default; \
|
||||
}
|
||||
|
||||
#define ngx_conf_init_unsigned_value(conf, default) \
|
||||
if (conf == (unsigned) NGX_CONF_UNSET) { \
|
||||
conf = default; \
|
||||
}
|
||||
|
||||
#define ngx_conf_init_size_value(conf, default) \
|
||||
if (conf == NGX_CONF_UNSET) { \
|
||||
conf = default; \
|
||||
|
@ -219,6 +219,7 @@ static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
ngx_log_t *ngx_log_init_errlog()
|
||||
{
|
||||
#if (WIN32)
|
||||
|
||||
ngx_log.fd = GetStdHandle(STD_ERROR_HANDLE);
|
||||
|
||||
if (ngx_log.fd == NGX_INVALID_FILE) {
|
||||
@ -231,7 +232,9 @@ ngx_log_t *ngx_log_init_errlog()
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
ngx_log.fd = STDERR_FILENO;
|
||||
|
||||
#endif
|
||||
|
||||
ngx_log.log_level = NGX_LOG_INFO;
|
||||
|
@ -68,10 +68,12 @@ typedef struct {
|
||||
ngx_fd_t fd;
|
||||
void *data;
|
||||
size_t (*handler)(void *ctx, char *buf, size_t len);
|
||||
#if 0
|
||||
/* STUB */
|
||||
char *action;
|
||||
char *context;
|
||||
/* */
|
||||
#endif
|
||||
} ngx_log_t;
|
||||
|
||||
#define MAX_ERROR_STR 2048
|
||||
@ -161,6 +163,9 @@ void ngx_assert_core(ngx_log_t *log, const char *fmt, ...);
|
||||
#endif /* VARIADIC MACROS */
|
||||
|
||||
|
||||
#define ngx_log_alloc_log(pool, log) ngx_palloc(pool, log, sizeof(ngx_log_t))
|
||||
#define ngx_log_copy_log(new, old) ngx_memcpy(new, old, sizeof(ngx_log_t))
|
||||
|
||||
ngx_log_t *ngx_log_init_errlog();
|
||||
char *ngx_log_set_errlog(ngx_conf_t *cf, ngx_command_t *cmd, ngx_log_t *log);
|
||||
|
||||
|
@ -11,8 +11,8 @@
|
||||
|
||||
|
||||
typedef struct {
|
||||
int changes;
|
||||
int events;
|
||||
u_int changes;
|
||||
u_int events;
|
||||
} ngx_kqueue_conf_t;
|
||||
|
||||
|
||||
@ -27,11 +27,10 @@ static void *ngx_kqueue_create_conf(ngx_pool_t *pool);
|
||||
static char *ngx_kqueue_init_conf(ngx_pool_t *pool, void *conf);
|
||||
|
||||
|
||||
int ngx_kqueue;
|
||||
int ngx_kqueue = -1;
|
||||
|
||||
static struct kevent *change_list, *event_list;
|
||||
static u_int max_changes, nchanges;
|
||||
static int nevents;
|
||||
static u_int max_changes, nchanges, nevents;
|
||||
|
||||
|
||||
static ngx_str_t kqueue_name = ngx_string("kqueue");
|
||||
@ -86,6 +85,7 @@ ngx_module_t ngx_kqueue_module = {
|
||||
|
||||
static int ngx_kqueue_init(ngx_log_t *log)
|
||||
{
|
||||
struct timespec ts;
|
||||
ngx_kqueue_conf_t *kcf;
|
||||
|
||||
kcf = ngx_event_get_conf(ngx_kqueue_module);
|
||||
@ -93,28 +93,57 @@ static int ngx_kqueue_init(ngx_log_t *log)
|
||||
ngx_log_debug(log, "CH: %d" _ kcf->changes);
|
||||
ngx_log_debug(log, "EV: %d" _ kcf->events);
|
||||
|
||||
max_changes = kcf->changes;
|
||||
nevents = kcf->events;
|
||||
nchanges = 0;
|
||||
|
||||
ngx_kqueue = kqueue();
|
||||
|
||||
if (ngx_kqueue == -1) {
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "kqueue() failed");
|
||||
return NGX_ERROR;
|
||||
ngx_kqueue = kqueue();
|
||||
|
||||
if (ngx_kqueue == -1) {
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "kqueue() failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
ngx_test_null(change_list,
|
||||
ngx_alloc(kcf->changes * sizeof(struct kevent), log),
|
||||
NGX_ERROR);
|
||||
ngx_test_null(event_list,
|
||||
ngx_alloc(kcf->events * sizeof(struct kevent), log),
|
||||
NGX_ERROR);
|
||||
if (max_changes < kcf->changes) {
|
||||
if (nchanges) {
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 0;
|
||||
|
||||
if (kevent(ngx_kqueue, change_list, nchanges, NULL, 0, &ts) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "kevent() failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (change_list) {
|
||||
ngx_free(change_list);
|
||||
}
|
||||
|
||||
ngx_test_null(change_list,
|
||||
ngx_alloc(kcf->changes * sizeof(struct kevent), log),
|
||||
NGX_ERROR);
|
||||
}
|
||||
|
||||
max_changes = kcf->changes;
|
||||
nchanges = 0;
|
||||
|
||||
if (nevents < kcf->events) {
|
||||
if (event_list) {
|
||||
ngx_free(event_list);
|
||||
}
|
||||
|
||||
ngx_test_null(event_list,
|
||||
ngx_alloc(kcf->events * sizeof(struct kevent), log),
|
||||
NGX_ERROR);
|
||||
}
|
||||
|
||||
nevents = kcf->events;
|
||||
|
||||
if (ngx_event_timer_init(log) == NGX_ERROR) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
/* TODO: re-add active events with new udata
|
||||
if ecf->connections was increased */
|
||||
|
||||
ngx_event_actions = ngx_kqueue_module_ctx.actions;
|
||||
|
||||
ngx_event_flags = NGX_HAVE_LEVEL_EVENT
|
||||
@ -139,10 +168,18 @@ static void ngx_kqueue_done(ngx_log_t *log)
|
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "kqueue close() failed");
|
||||
}
|
||||
|
||||
ngx_kqueue = -1;
|
||||
|
||||
ngx_event_timer_done(log);
|
||||
|
||||
ngx_free(change_list);
|
||||
ngx_free(event_list);
|
||||
|
||||
change_list = NULL;
|
||||
event_list = NULL;
|
||||
max_changes = 0;
|
||||
nchanges = 0;
|
||||
nevents = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -209,8 +246,8 @@ static int ngx_kqueue_del_event(ngx_event_t *ev, int event, u_int flags)
|
||||
|
||||
static int ngx_kqueue_set_event(ngx_event_t *ev, int filter, u_int flags)
|
||||
{
|
||||
struct timespec ts;
|
||||
ngx_connection_t *c;
|
||||
struct timespec ts;
|
||||
ngx_connection_t *c;
|
||||
|
||||
c = ev->data;
|
||||
|
||||
@ -227,7 +264,7 @@ static int ngx_kqueue_set_event(ngx_event_t *ev, int filter, u_int flags)
|
||||
ts.tv_nsec = 0;
|
||||
|
||||
if (kevent(ngx_kqueue, change_list, nchanges, NULL, 0, &ts) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, "kevent failed");
|
||||
ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, "kevent() failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
@ -295,7 +332,7 @@ static int ngx_kqueue_process_events(ngx_log_t *log)
|
||||
events = kevent(ngx_kqueue, change_list, nchanges, event_list, nevents, tp);
|
||||
|
||||
if (events == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "kevent failed");
|
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "kevent() failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
@ -313,7 +350,7 @@ static int ngx_kqueue_process_events(ngx_log_t *log)
|
||||
} else {
|
||||
if (events == 0) {
|
||||
ngx_log_error(NGX_LOG_ALERT, log, 0,
|
||||
"kevent returns no events without timeout");
|
||||
"kevent() returned no events without timeout");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
}
|
||||
@ -342,7 +379,7 @@ static int ngx_kqueue_process_events(ngx_log_t *log)
|
||||
|
||||
if (event_list[i].flags & EV_ERROR) {
|
||||
ngx_log_error(NGX_LOG_ALERT, log, event_list[i].data,
|
||||
"kevent error on %d", event_list[i].ident);
|
||||
"kevent() error on %d", event_list[i].ident);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -414,8 +451,8 @@ static char *ngx_kqueue_init_conf(ngx_pool_t *pool, void *conf)
|
||||
{
|
||||
ngx_kqueue_conf_t *kcf = conf;
|
||||
|
||||
ngx_conf_init_value(kcf->changes, 512);
|
||||
ngx_conf_init_value(kcf->events, 512);
|
||||
ngx_conf_init_unsigned_value(kcf->changes, 512);
|
||||
ngx_conf_init_unsigned_value(kcf->events, 512);
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
@ -42,7 +42,6 @@ static int ngx_event_connections;
|
||||
|
||||
|
||||
static ngx_str_t events_name = ngx_string("events");
|
||||
static ngx_str_t event_name = ngx_string("event");
|
||||
|
||||
static ngx_command_t ngx_events_commands[] = {
|
||||
|
||||
@ -66,6 +65,7 @@ ngx_module_t ngx_events_module = {
|
||||
};
|
||||
|
||||
|
||||
static ngx_str_t event_name = ngx_string("event");
|
||||
|
||||
static ngx_command_t ngx_event_commands[] = {
|
||||
|
||||
|
@ -12,20 +12,33 @@ static int ngx_timer_queue_num;
|
||||
int ngx_event_timer_init(ngx_log_t *log)
|
||||
{
|
||||
int i;
|
||||
ngx_event_t *new_queue;
|
||||
ngx_event_conf_t *ecf;
|
||||
|
||||
ecf = ngx_event_get_conf(ngx_event_module);
|
||||
|
||||
ngx_timer_queue_num = ecf->timer_queues;
|
||||
ngx_timer_cur_queue = 0;
|
||||
if (ngx_timer_queue_num < ecf->timer_queues) {
|
||||
ngx_test_null(new_queue,
|
||||
ngx_alloc(ecf->timer_queues * sizeof(ngx_event_t), log),
|
||||
NGX_ERROR);
|
||||
|
||||
ngx_test_null(ngx_timer_queue,
|
||||
ngx_alloc(ngx_timer_queue_num * sizeof(ngx_event_t), log),
|
||||
NGX_ERROR);
|
||||
for (i = 0; i < ngx_timer_queue_num; i++) {
|
||||
new_queue[i] = ngx_timer_queue[i];
|
||||
}
|
||||
|
||||
for (i = 0; i < ngx_timer_queue_num; i++) {
|
||||
ngx_timer_queue[i].timer_prev = &ngx_timer_queue[i];
|
||||
ngx_timer_queue[i].timer_next = &ngx_timer_queue[i];
|
||||
if (ngx_timer_queue) {
|
||||
ngx_free(ngx_timer_queue);
|
||||
}
|
||||
|
||||
ngx_timer_queue = new_queue;
|
||||
|
||||
ngx_timer_queue_num = ecf->timer_queues;
|
||||
ngx_timer_cur_queue = 0;
|
||||
|
||||
for (/* void */; i < ngx_timer_queue_num; i++) {
|
||||
ngx_timer_queue[i].timer_prev = &ngx_timer_queue[i];
|
||||
ngx_timer_queue[i].timer_next = &ngx_timer_queue[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NGX_OK;;
|
||||
@ -35,6 +48,7 @@ int ngx_event_timer_init(ngx_log_t *log)
|
||||
void ngx_event_timer_done(ngx_log_t *log)
|
||||
{
|
||||
ngx_free(ngx_timer_queue);
|
||||
ngx_timer_queue = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
* small file in malloc()ed memory, mmap()ed file, file descriptor only,
|
||||
* file access time only (to estimate can pages pages still be in memory),
|
||||
* file access time only (to estimate could pages still be in memory),
|
||||
* translated URI (ngx_http_index_hanlder),
|
||||
* compiled script (ngx_http_ssi_filter).
|
||||
*/
|
||||
@ -14,7 +14,9 @@
|
||||
/* "/" -> "/index.html" in ngx_http_index_handler */
|
||||
#define NGX_HTTP_CACHE_ENTRY_URI 0x00000004
|
||||
|
||||
/* complied script */
|
||||
/* 301 location "/dir" -> "dir/" in ngx_http_core_handler */
|
||||
|
||||
/* compiled script in ngx_http_ssi_filter */
|
||||
#define NGX_HTTP_CACHE_ENTRY_SCRIPT 0x00000008
|
||||
|
||||
#define NGX_HTTP_CACHE_FILTER_FLAGS 0xFFFF0000
|
||||
|
@ -359,6 +359,8 @@ ngx_log_debug(r->connection->log, "HTTP filename: '%s'" _ r->file.name.data);
|
||||
}
|
||||
}
|
||||
|
||||
ngx_log_debug(r->connection->log, "FILE: %d" _ r->file.fd);
|
||||
|
||||
if (!r->file.info_valid) {
|
||||
if (ngx_stat_fd(r->file.fd, &r->file.info) == NGX_FILE_ERROR) {
|
||||
ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
|
||||
|
@ -1,9 +1,7 @@
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_log.h>
|
||||
|
||||
/* daemon in Linux */
|
||||
|
||||
int ngx_daemon(ngx_log_t *log)
|
||||
{
|
||||
@ -26,27 +24,8 @@ int ngx_daemon(ngx_log_t *log)
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
#if (__SVR4 || linux)
|
||||
|
||||
/* need HUP IGN ? check in Solaris and Linux */
|
||||
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
ngx_log_error(NGX_LOG_EMERG, log, errno, "fork() failed");
|
||||
return NGX_ERROR;
|
||||
|
||||
case 0:
|
||||
break;
|
||||
|
||||
default:
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
umask(0);
|
||||
|
||||
#if 0
|
||||
fd = open("/dev/null", O_RDWR);
|
||||
if (fd == -1) {
|
||||
ngx_log_error(NGX_LOG_EMERG, log, errno, "open(\"/dev/null\") failed");
|
||||
@ -63,10 +42,12 @@ int ngx_daemon(ngx_log_t *log)
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (dup2(fd, STDERR_FILENO) == -1) {
|
||||
ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDERR) failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (fd > STDERR_FILENO) {
|
||||
if (close(fd) == -1) {
|
||||
@ -74,7 +55,6 @@ int ngx_daemon(ngx_log_t *log)
|
||||
return NGX_ERROR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h> /* TCP_NOPUSH */
|
||||
|
Loading…
Reference in New Issue
Block a user