mirror of
https://github.com/nginx/nginx.git
synced 2024-11-24 04:49:01 +08:00
nginx-0.0.1-2003-06-03-19:42:58 import
This commit is contained in:
parent
7578ec9df4
commit
1c10462e88
@ -31,21 +31,25 @@ ngx_array_t ngx_listening_sockets;
|
||||
int main(int argc, char *const *argv)
|
||||
{
|
||||
int i;
|
||||
ngx_str_t conf_file;
|
||||
ngx_conf_t conf;
|
||||
ngx_str_t conf_file;
|
||||
ngx_log_t *log;
|
||||
ngx_conf_t conf;
|
||||
|
||||
ngx_max_sockets = -1;
|
||||
|
||||
#if 0
|
||||
ngx_log.fd = STDERR_FILENO;
|
||||
ngx_log.log_level = NGX_LOG_INFO;
|
||||
|
||||
/* STUB */ ngx_log.log_level = NGX_LOG_DEBUG;
|
||||
#endif
|
||||
log = ngx_log_init_errlog();
|
||||
|
||||
if (ngx_os_init(&ngx_log) == NGX_ERROR) {
|
||||
if (ngx_os_init(log) == NGX_ERROR) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
ngx_pool = ngx_create_pool(16 * 1024, &ngx_log);
|
||||
ngx_pool = ngx_create_pool(16 * 1024, log);
|
||||
/* */
|
||||
|
||||
ngx_max_module = 0;
|
||||
@ -72,7 +76,7 @@ int main(int argc, char *const *argv)
|
||||
|
||||
conf.ctx = ngx_conf_ctx;
|
||||
conf.pool = ngx_pool;
|
||||
conf.log = &ngx_log;
|
||||
conf.log = log;
|
||||
conf.module_type = NGX_CORE_MODULE;
|
||||
conf.cmd_type = NGX_MAIN_CONF;
|
||||
|
||||
@ -83,6 +87,11 @@ int main(int argc, char *const *argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
log = (ngx_log_t *) ngx_get_conf(ngx_errlog_module);
|
||||
/* STUB */ log->log_level = NGX_LOG_DEBUG;
|
||||
#endif
|
||||
|
||||
ngx_init_temp_number();
|
||||
|
||||
ngx_io = ngx_os_io;
|
||||
@ -95,7 +104,7 @@ int main(int argc, char *const *argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (ngx_open_listening_sockets(&ngx_log) == NGX_ERROR) {
|
||||
if (ngx_open_listening_sockets(log) == NGX_ERROR) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -103,12 +112,12 @@ int main(int argc, char *const *argv)
|
||||
|
||||
/* TODO: fork */
|
||||
|
||||
ngx_pre_thread(&ngx_listening_sockets, ngx_pool, &ngx_log);
|
||||
ngx_pre_thread(&ngx_listening_sockets, ngx_pool, log);
|
||||
|
||||
/* TODO: threads */
|
||||
|
||||
/* STUB */
|
||||
ngx_worker(&ngx_log);
|
||||
ngx_worker(log);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1,10 +1,6 @@
|
||||
|
||||
#include <ngx_config.h>
|
||||
|
||||
#include <ngx_errno.h>
|
||||
#include <ngx_log.h>
|
||||
#include <ngx_string.h>
|
||||
#include <ngx_alloc.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
void *ngx_alloc(size_t size, ngx_log_t *log)
|
||||
|
@ -3,8 +3,8 @@
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
#include <ngx_log.h>
|
||||
|
||||
/* NGX_MAX_ALLOC_FROM_POOL should be (PAGE_SIZE - 1), i.e. 4095 on x86.
|
||||
On FreeBSD 5.x it allows to use zero copy send.
|
||||
@ -18,12 +18,15 @@
|
||||
|
||||
|
||||
typedef struct ngx_pool_large_s ngx_pool_large_t;
|
||||
|
||||
struct ngx_pool_large_s {
|
||||
ngx_pool_large_t *next;
|
||||
void *alloc;
|
||||
};
|
||||
|
||||
typedef struct ngx_pool_s ngx_pool_t;
|
||||
|
||||
typedef struct ngx_pool_s ngx_pool_t;
|
||||
|
||||
struct ngx_pool_s {
|
||||
char *last;
|
||||
char *end;
|
||||
|
@ -1,9 +1,6 @@
|
||||
|
||||
#include <ngx_config.h>
|
||||
|
||||
#include <ngx_alloc.h>
|
||||
#include <ngx_string.h>
|
||||
#include <ngx_array.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
ngx_array_t *ngx_create_array(ngx_pool_t *p, int n, size_t size)
|
||||
|
@ -3,8 +3,8 @@
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
#include <ngx_alloc.h>
|
||||
|
||||
typedef struct {
|
||||
void *elts;
|
||||
|
@ -1,9 +1,6 @@
|
||||
|
||||
#include <ngx_config.h>
|
||||
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_files.h>
|
||||
#include <ngx_conf_file.h>
|
||||
|
||||
|
||||
char ngx_conf_errstr[MAX_CONF_ERRSTR];
|
||||
|
@ -3,14 +3,7 @@
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_files.h>
|
||||
#include <ngx_log.h>
|
||||
#include <ngx_file.h>
|
||||
#include <ngx_time.h>
|
||||
#include <ngx_string.h>
|
||||
#include <ngx_alloc.h>
|
||||
#include <ngx_hunk.h>
|
||||
#include <ngx_array.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
/*
|
||||
@ -51,10 +44,6 @@
|
||||
extern char ngx_conf_errstr[MAX_CONF_ERRSTR];
|
||||
|
||||
|
||||
typedef struct ngx_conf_s ngx_conf_t;
|
||||
|
||||
|
||||
typedef struct ngx_command_s ngx_command_t;
|
||||
struct ngx_command_s {
|
||||
ngx_str_t name;
|
||||
int type;
|
||||
@ -66,14 +55,15 @@ struct ngx_command_s {
|
||||
|
||||
#define ngx_null_command {ngx_null_string, 0, NULL, 0, 0, NULL}
|
||||
|
||||
typedef struct {
|
||||
|
||||
struct ngx_module_s {
|
||||
int ctx_index;
|
||||
int index;
|
||||
void *ctx;
|
||||
ngx_command_t *commands;
|
||||
int type;
|
||||
int (*init_module)(ngx_pool_t *p);
|
||||
} ngx_module_t;
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
|
@ -1,26 +1,10 @@
|
||||
#ifndef _NGX_CONNECTION_H_INCLUDED_
|
||||
#define _NGX_CONNECTION_H_INCLUDED_
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
#if 0
|
||||
#include <ngx_socket.h>
|
||||
#include <ngx_log.h>
|
||||
#include <ngx_alloc.h>
|
||||
#include <ngx_hunk.h>
|
||||
#include <ngx_array.h>
|
||||
#include <ngx_string.h>
|
||||
|
||||
#include <ngx_server.h>
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
typedef struct ngx_connection_s ngx_connection_t;
|
||||
#endif
|
||||
|
||||
#ifdef NGX_EVENT
|
||||
#include <ngx_event.h>
|
||||
#endif
|
||||
|
||||
|
||||
struct ngx_connection_s {
|
||||
ngx_socket_t fd;
|
||||
|
@ -5,19 +5,25 @@
|
||||
#include <ngx_types.h>
|
||||
#include <ngx_time.h>
|
||||
#include <ngx_socket.h>
|
||||
#include <ngx_files.h>
|
||||
#include <ngx_errno.h>
|
||||
#include <ngx_process.h>
|
||||
|
||||
typedef struct ngx_connection_s ngx_connection_t;
|
||||
typedef struct ngx_module_s ngx_module_t;
|
||||
typedef struct ngx_conf_s ngx_conf_t;
|
||||
typedef struct ngx_command_s ngx_command_t;
|
||||
|
||||
typedef struct ngx_file_s ngx_file_t;
|
||||
typedef struct ngx_event_s ngx_event_t;
|
||||
typedef struct ngx_connection_s ngx_connection_t;
|
||||
|
||||
#include <ngx_log.h>
|
||||
#include <ngx_alloc.h>
|
||||
#include <ngx_string.h>
|
||||
#include <ngx_hunk.h>
|
||||
#include <ngx_array.h>
|
||||
#include <ngx_string.h>
|
||||
#include <ngx_table.h>
|
||||
#include <ngx_file.h>
|
||||
#include <ngx_files.h>
|
||||
#include <ngx_inet.h>
|
||||
#include <ngx_conf_file.h>
|
||||
#include <ngx_os_init.h>
|
||||
|
@ -1,10 +1,6 @@
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_hunk.h>
|
||||
#include <ngx_array.h>
|
||||
#include <ngx_file.h>
|
||||
#include <ngx_files.h>
|
||||
|
||||
|
||||
static int ngx_temp_number;
|
||||
|
@ -2,11 +2,9 @@
|
||||
#define _NGX_FILE_H_INCLUDED_
|
||||
|
||||
|
||||
#include <ngx_log.h>
|
||||
#include <ngx_alloc.h>
|
||||
#include <ngx_string.h>
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
typedef struct ngx_file_s ngx_file_t;
|
||||
|
||||
struct ngx_file_s {
|
||||
ngx_fd_t fd;
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_hunk.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
ngx_hunk_t *ngx_create_temp_hunk(ngx_pool_t *pool, int size,
|
||||
|
@ -1,11 +1,9 @@
|
||||
#ifndef _NGX_CHUNK_H_INCLUDED_
|
||||
#define _NGX_CHUNK_H_INCLUDED_
|
||||
#ifndef _NGX_HUNK_H_INCLUDED_
|
||||
#define _NGX_HUNK_H_INCLUDED_
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_types.h>
|
||||
#include <ngx_file.h>
|
||||
#include <ngx_alloc.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
/* hunk type */
|
||||
@ -35,7 +33,8 @@
|
||||
|
||||
|
||||
|
||||
typedef struct ngx_hunk_s ngx_hunk_t;
|
||||
typedef struct ngx_hunk_s ngx_hunk_t;
|
||||
|
||||
struct ngx_hunk_s {
|
||||
char *pos;
|
||||
char *last;
|
||||
@ -53,7 +52,8 @@ struct ngx_hunk_s {
|
||||
};
|
||||
|
||||
|
||||
typedef struct ngx_chain_s ngx_chain_t;
|
||||
typedef struct ngx_chain_s ngx_chain_t;
|
||||
|
||||
struct ngx_chain_s {
|
||||
ngx_hunk_t *hunk;
|
||||
ngx_chain_t *next;
|
||||
@ -83,4 +83,4 @@ ngx_hunk_t *ngx_create_temp_hunk(ngx_pool_t *pool, int size,
|
||||
} while (0);
|
||||
|
||||
|
||||
#endif /* _NGX_CHUNK_H_INCLUDED_ */
|
||||
#endif /* _NGX_HUNK_H_INCLUDED_ */
|
||||
|
@ -1,7 +1,6 @@
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_string.h>
|
||||
#include <ngx_inet.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
/* AF_INET only */
|
||||
|
@ -14,6 +14,36 @@
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
|
||||
|
||||
static ngx_str_t errlog_name = ngx_string("errlog");
|
||||
|
||||
static ngx_command_t ngx_errlog_commands[] = {
|
||||
|
||||
{ngx_string("error_log"),
|
||||
NGX_MAIN_CONF|NGX_CONF_TAKE1,
|
||||
ngx_set_error_log,
|
||||
0,
|
||||
0,
|
||||
NULL},
|
||||
|
||||
ngx_null_command
|
||||
};
|
||||
|
||||
|
||||
ngx_module_t ngx_errlog_module = {
|
||||
NGX_MODULE,
|
||||
&errlog_name, /* module context */
|
||||
ngx_errlog_commands, /* module directives */
|
||||
NGX_CORE_MODULE, /* module type */
|
||||
NULL /* init module */
|
||||
};
|
||||
|
||||
|
||||
static ngx_log_t ngx_log;
|
||||
|
||||
|
||||
static const char *err_levels[] = {
|
||||
"stderr", "emerg", "alert", "crit", "error",
|
||||
"warn", "notice", "info", "debug"
|
||||
@ -33,6 +63,9 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
|
||||
#if (HAVE_VARIADIC_MACROS)
|
||||
va_list args;
|
||||
#endif
|
||||
#if (WIN32)
|
||||
int written;
|
||||
#endif
|
||||
|
||||
ngx_localtime(&tm);
|
||||
len = ngx_snprintf(errstr, sizeof(errstr), "%4d/%02d/%02d %02d:%02d:%02d",
|
||||
@ -87,10 +120,15 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
|
||||
|
||||
#if (WIN32)
|
||||
errstr[len++] = '\r';
|
||||
#endif
|
||||
errstr[len++] = '\n';
|
||||
|
||||
if (log->fd) {
|
||||
WriteFile(log->fd, errstr, len, &written, NULL);
|
||||
}
|
||||
#else
|
||||
errstr[len++] = '\n';
|
||||
write(log->fd, errstr, len);
|
||||
#endif
|
||||
|
||||
|
||||
#if 0
|
||||
errstr[len] = '\0';
|
||||
@ -137,6 +175,8 @@ void ngx_assert_core(ngx_log_t *log, const char *fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
void ngx_log_stderr(ngx_event_t *ev)
|
||||
{
|
||||
char errstr[MAX_ERROR_STR];
|
||||
@ -165,3 +205,79 @@ void ngx_log_stderr(ngx_event_t *ev)
|
||||
ngx_log_error(NGX_LOG_STDERR, &ngx_log, 0, "%s", errstr);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
return ngx_log_set_errlog(cf, cmd, &ngx_log);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ngx_log_t *ngx_log_init_errlog()
|
||||
{
|
||||
#if (WIN32)
|
||||
ngx_log.fd = GetStdHandle(STD_ERROR_HANDLE);
|
||||
|
||||
if (ngx_log.fd == NGX_INVALID_FILE) {
|
||||
/* TODO: where we can log error ? */
|
||||
return NULL;
|
||||
|
||||
} else if (ngx_log.fd == NULL) {
|
||||
/* there are no associated standard handles */
|
||||
/* TODO: where we can log possible errors ? */
|
||||
}
|
||||
|
||||
#else
|
||||
ngx_log.fd = STDERR_FILENO;
|
||||
#endif
|
||||
|
||||
ngx_log.log_level = NGX_LOG_INFO;
|
||||
/* STUB */ ngx_log.log_level = NGX_LOG_DEBUG;
|
||||
|
||||
return &ngx_log;
|
||||
}
|
||||
|
||||
|
||||
char *ngx_log_set_errlog(ngx_conf_t *cf, ngx_command_t *cmd, ngx_log_t *log)
|
||||
{
|
||||
int len;
|
||||
ngx_err_t err;
|
||||
ngx_str_t *value;
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
log->fd = ngx_open_file(value[1].data,
|
||||
NGX_FILE_RDWR,
|
||||
NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
|
||||
|
||||
if (log->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: ",
|
||||
value[1].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(log->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: ",
|
||||
value[1].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
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
@ -2,8 +2,9 @@
|
||||
#define _NGX_LOG_H_INCLUDED_
|
||||
|
||||
|
||||
#include <ngx_types.h>
|
||||
#include <ngx_errno.h>
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
typedef enum {
|
||||
NGX_LOG_STDERR = 0,
|
||||
@ -160,4 +161,11 @@ void ngx_assert_core(ngx_log_t *log, const char *fmt, ...);
|
||||
#endif /* VARIADIC MACROS */
|
||||
|
||||
|
||||
ngx_log_t *ngx_log_init_errlog();
|
||||
char *ngx_log_set_errlog(ngx_conf_t *cf, ngx_command_t *cmd, ngx_log_t *log);
|
||||
|
||||
|
||||
extern ngx_module_t ngx_errlog_module;
|
||||
|
||||
|
||||
#endif /* _NGX_LOG_H_INCLUDED_ */
|
||||
|
@ -1,9 +1,9 @@
|
||||
|
||||
#include <ngx_config.h>
|
||||
|
||||
#include <ngx_conf_file.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
extern ngx_module_t ngx_errlog_module;
|
||||
extern ngx_module_t ngx_events_module;
|
||||
extern ngx_module_t ngx_event_module;
|
||||
|
||||
@ -42,6 +42,10 @@ extern ngx_module_t ngx_http_log_module;
|
||||
|
||||
ngx_module_t *ngx_modules[] = {
|
||||
|
||||
/* core */
|
||||
|
||||
&ngx_errlog_module,
|
||||
|
||||
/* events */
|
||||
|
||||
&ngx_events_module,
|
||||
|
@ -1,25 +0,0 @@
|
||||
|
||||
#include <ngx_config.h>
|
||||
|
||||
#if !(HAVE_SENDFILE)
|
||||
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_log.h>
|
||||
#include <ngx_socket.h>
|
||||
#include <ngx_sendv.h>
|
||||
|
||||
int ngx_sendfile(ngx_socket_t s,
|
||||
ngx_iovec_t *headers, int hdr_cnt,
|
||||
ngx_fd_t fd, off_t offset, size_t nbytes,
|
||||
ngx_iovec_t *trailers, int trl_cnt,
|
||||
off_t *sent,
|
||||
ngx_log_t *log)
|
||||
{
|
||||
ngx_log_error(NGX_LOG_INFO, log, 0,
|
||||
"ngx_sendfile: sendfile is not implemented");
|
||||
|
||||
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,23 +0,0 @@
|
||||
#ifndef _NGX_SENDFILE_H_INCLUDED_
|
||||
#define _NGX_SENDFILE_H_INCLUDED_
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_types.h>
|
||||
#include <ngx_files.h>
|
||||
#include <ngx_socket.h>
|
||||
#include <ngx_log.h>
|
||||
#include <ngx_connection.h>
|
||||
#include <ngx_sendv.h>
|
||||
|
||||
int ngx_sendfile(ngx_connection_t *c,
|
||||
ngx_iovec_t *headers, int hdr_cnt,
|
||||
ngx_fd_t fd, off_t offset, size_t nbytes,
|
||||
ngx_iovec_t *trailers, int trl_cnt,
|
||||
off_t *sent, u_int flags);
|
||||
|
||||
|
||||
extern u_int ngx_sendfile_flags;
|
||||
|
||||
|
||||
#endif /* _NGX_SENDFILE_H_INCLUDED_ */
|
@ -1,17 +0,0 @@
|
||||
#ifndef _NGX_SERVER_H_INCLUDED_
|
||||
#define _NGX_SERVER_H_INCLUDED_
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_types.h>
|
||||
#include <ngx_alloc.h>
|
||||
|
||||
typedef struct {
|
||||
int log_level;
|
||||
ngx_pool_t *pool;
|
||||
int (*handler)(void *data);
|
||||
int buff_size;
|
||||
} ngx_server_t;
|
||||
|
||||
|
||||
#endif /* _NGX_SERVER_H_INCLUDED_ */
|
@ -1,7 +1,6 @@
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_string.h>
|
||||
|
||||
|
||||
char *ngx_cpystrn(char *dst, char *src, size_t n)
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
typedef struct {
|
||||
|
@ -3,9 +3,8 @@
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_string.h>
|
||||
#include <ngx_alloc.h>
|
||||
#include <ngx_array.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
typedef ngx_array_t ngx_table_t;
|
||||
|
||||
@ -14,6 +13,7 @@ typedef struct {
|
||||
ngx_str_t value;
|
||||
} ngx_table_elt_t;
|
||||
|
||||
|
||||
#define ngx_create_table(p, n) ngx_create_array(p, n, 2 * sizeof(ngx_str_t))
|
||||
#define ngx_push_table(t) ngx_push_array(t)
|
||||
|
||||
|
@ -78,7 +78,7 @@ void ngx_event_accept(ngx_event_t *ev)
|
||||
ls->addr_text.data);
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
ngx_msleep(1000);
|
||||
|
||||
ngx_destroy_pool(pool);
|
||||
return;
|
||||
|
@ -1,11 +1,9 @@
|
||||
|
||||
#include <ngx_config.h>
|
||||
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_types.h>
|
||||
#include <ngx_log.h>
|
||||
|
||||
#include <ngx_listen.h>
|
||||
#include <ngx_connection.h>
|
||||
|
||||
#include <ngx_event.h>
|
||||
#include <ngx_event_close.h>
|
||||
#include <ngx_iocp_module.h>
|
||||
@ -14,10 +12,7 @@
|
||||
|
||||
|
||||
|
||||
/* This function should always return NGX_OK even there are some failures
|
||||
because if we return NGX_ERROR then listening socket would be closed */
|
||||
|
||||
int ngx_event_acceptex(ngx_event_t *ev)
|
||||
void ngx_event_acceptex(ngx_event_t *ev)
|
||||
{
|
||||
ngx_connection_t *c;
|
||||
|
||||
@ -25,25 +20,23 @@ int ngx_event_acceptex(ngx_event_t *ev)
|
||||
|
||||
if (ev->ovlp.error) {
|
||||
ngx_log_error(NGX_LOG_CRIT, ev->log, ev->ovlp.error,
|
||||
"AcceptEx(%s) falied", c->addr_text.data);
|
||||
return NGX_OK;
|
||||
"AcceptEx() falied for %s", c->addr_text.data);
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
/* can we do SO_UPDATE_ACCEPT_CONTEXT just before shutdown() ???
|
||||
/* TODO: can we do SO_UPDATE_ACCEPT_CONTEXT just before shutdown() ???
|
||||
or AcceptEx's context will be lost ??? */
|
||||
|
||||
/* SO_UPDATE_ACCEPT_CONTEXT is required for shutdown() to work */
|
||||
if (setsockopt(context->accept_socket, SOL_SOCKET,
|
||||
SO_UPDATE_ACCEPT_CONTEXT, (char *)&nsd,
|
||||
sizeof(nsd))) {
|
||||
ap_log_error(APLOG_MARK, APLOG_ERR, WSAGetLastError(), server_conf,
|
||||
"setsockopt(SO_UPDATE_ACCEPT_CONTEXT) failed.");
|
||||
if (setsockopt(c->fd, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT,
|
||||
(char *)&c->listening->fd, sizeof(ngx_socket_t)) == -1)
|
||||
{
|
||||
ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_socket_errno,
|
||||
"setsockopt(SO_UPDATE_ACCEPT_CONTEXT) failed for %s",
|
||||
c->addr_text.data);
|
||||
|
||||
/* non fatal - we can not only do lingering close */
|
||||
|
||||
#endif
|
||||
/* non fatal - we can not only do lingering close */
|
||||
}
|
||||
|
||||
getacceptexsockaddrs(c->data, 0,
|
||||
c->socklen + 16, c->socklen + 16,
|
||||
@ -57,7 +50,7 @@ int ngx_event_acceptex(ngx_event_t *ev)
|
||||
|
||||
c->handler(c);
|
||||
|
||||
return NGX_OK;
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
@ -198,5 +198,19 @@ static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
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_appned_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
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
@ -252,7 +252,7 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r)
|
||||
r->headers_out.content_length);
|
||||
|
||||
len += ctx->boundary_header.len + range[i].content_range.len
|
||||
+ range[i].end - range[i].start;
|
||||
+ (size_t) (range[i].end - range[i].start);
|
||||
}
|
||||
|
||||
r->headers_out.content_length = len;
|
||||
|
@ -1,13 +1,10 @@
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
#include <ngx_string.h>
|
||||
#include <ngx_socket.h>
|
||||
#include <ngx_listen.h>
|
||||
#include <ngx_inet.h>
|
||||
|
||||
#include <ngx_http.h>
|
||||
#include <ngx_http_config.h>
|
||||
#include <ngx_http_core_module.h>
|
||||
|
||||
|
||||
static void ngx_http_init_filters(ngx_pool_t *pool, ngx_module_t **modules);
|
||||
|
@ -3,15 +3,7 @@
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
|
||||
#include <ngx_types.h>
|
||||
#include <ngx_string.h>
|
||||
#include <ngx_table.h>
|
||||
#include <ngx_hunk.h>
|
||||
#include <ngx_files.h>
|
||||
#include <ngx_connection.h>
|
||||
#include <ngx_conf_file.h>
|
||||
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_http_request.h>
|
||||
#include <ngx_http_config.h>
|
||||
#include <ngx_http_filter.h>
|
||||
|
@ -798,8 +798,12 @@ static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool,
|
||||
if (conf->listen.nelts == 0) {
|
||||
ngx_test_null(l, ngx_push_array(&conf->listen), NGX_CONF_ERROR);
|
||||
l->addr = INADDR_ANY;
|
||||
#if (WIN32)
|
||||
l->port = 80;
|
||||
#else
|
||||
/* STUB: getuid() should be cached */
|
||||
l->port = (getuid() == 0) ? 80 : 8000;
|
||||
#endif
|
||||
l->family = AF_INET;
|
||||
}
|
||||
|
||||
|
@ -279,6 +279,10 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
|
||||
|
||||
/* STUB: we need to handle such URIs */
|
||||
if (r->complex_uri || r->unusual_uri) {
|
||||
r->request_line.len = r->request_end - r->request_start;
|
||||
r->request_line.data = r->request_start;
|
||||
r->request_line.data[r->request_line.len] = '\0';
|
||||
|
||||
ngx_http_header_parse_error(r, NGX_HTTP_PARSE_INVALID_REQUEST);
|
||||
ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
|
||||
return;
|
||||
|
@ -93,7 +93,6 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
|
||||
ngx_hunk_t *h;
|
||||
ngx_chain_t *ch;
|
||||
ngx_table_elt_t *header;
|
||||
ngx_http_range_t *range;
|
||||
|
||||
if (r->http_version < NGX_HTTP_VERSION_10) {
|
||||
return NGX_OK;
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
typedef int ngx_err_t;
|
||||
|
||||
#define NGX_ENOENT ENOENT
|
||||
|
@ -24,7 +24,7 @@ void ngx_localtime(ngx_tm_t *tm);
|
||||
ngx_msec_t ngx_msec(void);
|
||||
|
||||
/* STUB */
|
||||
#define ngx_time() time(NULL)
|
||||
#define ngx_time() time(NULL)
|
||||
|
||||
|
||||
#endif /* _NGX_TIME_H_INCLUDED_ */
|
||||
|
@ -3,22 +3,24 @@
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
typedef DWORD ngx_err_t;
|
||||
|
||||
typedef DWORD ngx_err_t;
|
||||
|
||||
#define ngx_errno GetLastError()
|
||||
#define ngx_socket_errno WSAGetLastError()
|
||||
#define ngx_set_socket_errno(err) WSASetLastError(err)
|
||||
|
||||
#define NGX_ENOENT ERROR_FILE_NOT_FOUND
|
||||
#define NGX_EACCES ERROR_ACCESS_DENIED
|
||||
#define NGX_EEXIST ERROR_FILE_EXISTS
|
||||
#define NGX_ENOTDIR ERROR_PATH_NOT_FOUND
|
||||
#define NGX_EAGAIN WSAEWOULDBLOCK
|
||||
#define NGX_EINPROGRESS WSAEINPROGRESS
|
||||
#define NGX_EADDRINUSE WSAEADDRINUSE
|
||||
#define NGX_ECONNRESET ECONNRESET
|
||||
#define NGX_ETIMEDOUT WSAETIMEDOUT
|
||||
#define NGX_ENOENT ERROR_FILE_NOT_FOUND
|
||||
#define NGX_EACCES ERROR_ACCESS_DENIED
|
||||
#define NGX_EEXIST ERROR_FILE_EXISTS
|
||||
#define NGX_ENOTDIR ERROR_PATH_NOT_FOUND
|
||||
#define NGX_EAGAIN WSAEWOULDBLOCK
|
||||
#define NGX_EINPROGRESS WSAEINPROGRESS
|
||||
#define NGX_EADDRINUSE WSAEADDRINUSE
|
||||
#define NGX_ECONNRESET ECONNRESET
|
||||
#define NGX_ETIMEDOUT WSAETIMEDOUT
|
||||
|
||||
int ngx_strerror_r(ngx_err_t err, char *errstr, size_t size);
|
||||
|
||||
|
@ -1,9 +1,7 @@
|
||||
|
||||
#include <ngx_config.h>
|
||||
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_types.h>
|
||||
#include <ngx_file.h>
|
||||
|
||||
|
||||
ssize_t ngx_read_file(ngx_file_t *file, char *buf, size_t size, off_t offset)
|
||||
{
|
||||
@ -18,3 +16,15 @@ ssize_t ngx_read_file(ngx_file_t *file, char *buf, size_t size, off_t offset)
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
int ngx_file_append_mode(ngx_fd_t *fd)
|
||||
{
|
||||
if (SetFilePointer(fd, 0, NULL, FILE_END) == 0xFFFFFFFF) {
|
||||
if (GetLastError() != NO_ERROR) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
@ -3,14 +3,12 @@
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
|
||||
#include <ngx_types.h>
|
||||
#include <ngx_file.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
/* INVALID_FILE_ATTRIBUTES specified but never defined at least in VC6SP2 */
|
||||
#ifndef INVALID_FILE_ATTRIBUTES
|
||||
#define INVALID_FILE_ATTRIBUTES 0xFFFFFFFF
|
||||
#define INVALID_FILE_ATTRIBUTES 0xFFFFFFFF
|
||||
#endif
|
||||
|
||||
#define NGX_INVALID_FILE INVALID_HANDLE_VALUE
|
||||
@ -19,7 +17,7 @@
|
||||
|
||||
|
||||
#define ngx_open_file(name, access, create) \
|
||||
CreateFile(name, flags, \
|
||||
CreateFile(name, access, \
|
||||
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, \
|
||||
NULL, create, FILE_FLAG_BACKUP_SEMANTICS, NULL)
|
||||
/*
|
||||
@ -31,6 +29,11 @@
|
||||
#define NGX_FILE_RDWR GENERIC_READ|GENERIC_WRITE
|
||||
#define NGX_FILE_CREATE_OR_OPEN OPEN_ALWAYS
|
||||
#define NGX_FILE_OPEN OPEN_EXISTING
|
||||
#define NGX_FILE_APPEND 0
|
||||
|
||||
|
||||
int ngx_file_append_mode(ngx_fd_t fd);
|
||||
#define ngx_file_append_mode_n "SetFilePointer()"
|
||||
|
||||
|
||||
#define ngx_open_tempfile(name, persistent) \
|
||||
@ -46,7 +49,6 @@
|
||||
#define ngx_open_tempfile_n "CreateFile()"
|
||||
|
||||
|
||||
|
||||
#define ngx_close_file CloseHandle
|
||||
#define ngx_close_file_n "CloseHandle()"
|
||||
|
||||
|
@ -14,11 +14,73 @@ ngx_os_io_t ngx_os_io = {
|
||||
};
|
||||
|
||||
|
||||
/* Should these pointers be per protocol ? */
|
||||
LPFN_ACCEPTEX acceptex;
|
||||
LPFN_GETACCEPTEXSOCKADDRS getacceptexsockaddrs;
|
||||
LPFN_TRANSMITFILE transmitfile;
|
||||
|
||||
static GUID ae_guid = WSAID_ACCEPTEX;
|
||||
static GUID as_guid = WSAID_GETACCEPTEXSOCKADDRS;
|
||||
static GUID tf_guid = WSAID_TRANSMITFILE;
|
||||
|
||||
|
||||
int ngx_os_init(ngx_log_t *log)
|
||||
{
|
||||
if (ngx_init_sockets(log) == NGX_ERROR) {
|
||||
DWORD bytes;
|
||||
SOCKET s;
|
||||
WSADATA wsd;
|
||||
|
||||
/* init Winsock */
|
||||
|
||||
if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) {
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
||||
"WSAStartup failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
ngx_log_error(NGX_LOG_INFO, log, 0, "max sockets: %d", wsd.iMaxSockets);
|
||||
|
||||
/* get AcceptEx(), GetAcceptExSockAddrs() and TransmitFile() addresses */
|
||||
|
||||
s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0);
|
||||
if (s == -1) {
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
||||
ngx_socket_n " %s falied");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &ae_guid, sizeof(GUID),
|
||||
&acceptex, sizeof(LPFN_ACCEPTEX), &bytes, NULL, NULL) == -1) {
|
||||
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
||||
"WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
|
||||
"WSAID_ACCEPTEX) failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &as_guid, sizeof(GUID),
|
||||
&getacceptexsockaddrs, sizeof(LPFN_GETACCEPTEXSOCKADDRS),
|
||||
&bytes, NULL, NULL) == -1) {
|
||||
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
||||
"WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
|
||||
"WSAID_ACCEPTEX) failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &tf_guid, sizeof(GUID),
|
||||
&transmitfile, sizeof(LPFN_TRANSMITFILE), &bytes,
|
||||
NULL, NULL) == -1) {
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
||||
"WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
|
||||
"WSAID_TRANSMITFILE) failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (ngx_close_socket(s) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno,
|
||||
ngx_close_socket_n " failed");
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_log.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
int ngx_os_init(ngx_log_t *log);
|
||||
|
@ -1,77 +1,8 @@
|
||||
|
||||
#include <ngx_config.h>
|
||||
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_log.h>
|
||||
#include <ngx_errno.h>
|
||||
#include <ngx_socket.h>
|
||||
|
||||
|
||||
/* These pointers should be per protocol ? */
|
||||
LPFN_ACCEPTEX acceptex;
|
||||
LPFN_GETACCEPTEXSOCKADDRS getacceptexsockaddrs;
|
||||
LPFN_TRANSMITFILE transmitfile;
|
||||
|
||||
static GUID ae_guid = WSAID_ACCEPTEX;
|
||||
static GUID as_guid = WSAID_GETACCEPTEXSOCKADDRS;
|
||||
static GUID tf_guid = WSAID_TRANSMITFILE;
|
||||
|
||||
|
||||
int ngx_init_sockets(ngx_log_t *log)
|
||||
{
|
||||
DWORD bytes;
|
||||
SOCKET s;
|
||||
WSADATA wsd;
|
||||
|
||||
if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) {
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
||||
"WSAStartup failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0);
|
||||
if (s == -1) {
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
||||
ngx_socket_n " %s falied");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &ae_guid, sizeof(GUID),
|
||||
&acceptex, sizeof(LPFN_ACCEPTEX), &bytes, NULL, NULL) == -1) {
|
||||
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
||||
"WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
|
||||
"WSAID_ACCEPTEX) failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &as_guid, sizeof(GUID),
|
||||
&getacceptexsockaddrs, sizeof(LPFN_GETACCEPTEXSOCKADDRS),
|
||||
&bytes, NULL, NULL) == -1) {
|
||||
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
||||
"WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
|
||||
"WSAID_ACCEPTEX) failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &tf_guid, sizeof(GUID),
|
||||
&transmitfile, sizeof(LPFN_TRANSMITFILE), &bytes,
|
||||
NULL, NULL) == -1) {
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
||||
"WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
|
||||
"WSAID_TRANSMITFILE) failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (ngx_close_socket(s) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno,
|
||||
ngx_close_socket_n " failed");
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
int ngx_nonblocking(ngx_socket_t s)
|
||||
{
|
||||
unsigned long nb = 1;
|
||||
@ -79,6 +10,7 @@ int ngx_nonblocking(ngx_socket_t s)
|
||||
return ioctlsocket(s, FIONBIO, &nb);
|
||||
}
|
||||
|
||||
|
||||
int ngx_blocking(ngx_socket_t s)
|
||||
{
|
||||
unsigned long nb = 0;
|
||||
|
@ -3,7 +3,8 @@
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_log.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
#define NGX_WRITE_SHUTDOWN SD_SEND
|
||||
|
||||
@ -12,7 +13,6 @@
|
||||
typedef SOCKET ngx_socket_t;
|
||||
typedef int socklen_t;
|
||||
|
||||
int ngx_init_sockets(ngx_log_t *log);
|
||||
|
||||
#define ngx_socket(af, type, proto, flags) \
|
||||
WSASocket(af, type, proto, NULL, 0, flags)
|
||||
|
@ -2,7 +2,9 @@
|
||||
#define _NGX_TIME_H_INCLUDED_
|
||||
|
||||
|
||||
#include <windows.h>
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
typedef unsigned int ngx_msec_t;
|
||||
#define NGX_MAX_MSEC ~0
|
||||
@ -24,7 +26,7 @@ typedef FILETIME ngx_mtime_t;
|
||||
#define ngx_msec GetTickCount
|
||||
|
||||
/* STUB */
|
||||
#define ngx_time() time(NULL)
|
||||
#define ngx_time() time(NULL)
|
||||
|
||||
|
||||
#endif /* _NGX_TIME_H_INCLUDED_ */
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
typedef unsigned __int32 u_int32_t;
|
||||
|
Loading…
Reference in New Issue
Block a user