nginx-0.0.7-2004-06-17-21:18:53 import

This commit is contained in:
Igor Sysoev 2004-06-17 17:18:53 +00:00
parent f924e6b694
commit 415b1ce1b9
15 changed files with 291 additions and 58 deletions

53
auto/feature Normal file
View File

@ -0,0 +1,53 @@
echo $ngx_n "checking for $ngx_feature ..." $ngx_c
echo >> $NGX_ERR
echo "checking for $ngx_feature" >> $NGX_ERR
ngx_found=no
feature=`echo $ngx_feature_name | tr '[a-z]' '[A-Z]'`
cat << END > $NGX_AUTOTEST.c
#include <sys/types.h>
$NGX_UNISTD_H
$ngx_feature_inc
int main() {
$ngx_feature_test;
return 0;
}
END
test="$CC_WARN $CC_TEST_FLAGS -o $NGX_AUTOTEST $NGX_AUTOTEST.c \
$ngx_feature_libs"
eval "$test >> $NGX_ERR 2>&1"
if [ -x $NGX_AUTOTEST ]; then
if [ $ngx_feature_run = yes ]; then
if $NGX_AUTOTEST 2>&1 > /dev/null; then
echo " found"
have=HAVE_$feature . auto/have
ngx_found=yes
else
echo " found but is not working"
fi
else
echo " found"
have=HAVE_$feature . auto/have
ngx_found=yes
fi
else
echo " not found"
echo "---------" >> $NGX_ERR
cat $NGX_AUTOTEST.c >> $NGX_ERR
echo "---------" >> $NGX_ERR
echo $test >> $NGX_ERR
echo "---------" >> $NGX_ERR
fi
rm $NGX_AUTOTEST*

View File

@ -5,7 +5,7 @@ echo "checking for $ngx_func" >> $NGX_ERR
ngx_found=no
func=`echo $ngx_func | sed -e 's/()$//' | tr '[a-z.]' '[A-Z_]'`
func=`echo $ngx_func | sed -e 's/()$//' | tr '[a-z]' '[A-Z]'`
cat << END > $NGX_AUTOTEST.c
@ -20,8 +20,8 @@ int main() {
END
eval "$CC_WARN $CC_TEST_FLAGS -o $NGX_AUTOTEST $NGX_AUTOTEST.c $ngx_func_libs \
>> $NGX_ERR 2>&1"
test="$CC_WARN $CC_TEST_FLAGS -o $NGX_AUTOTEST $NGX_AUTOTEST.c $ngx_func_libs"
eval "$test >> $NGX_ERR 2>&1"
if [ -x $NGX_AUTOTEST ]; then
echo " found"
@ -30,6 +30,11 @@ if [ -x $NGX_AUTOTEST ]; then
else
echo " not found"
echo "---------" >> $NGX_ERR
cat $NGX_AUTOTEST.c >> $NGX_ERR
echo "---------" >> $NGX_ERR
echo $test >> $NGX_ERR
echo "---------" >> $NGX_ERR
fi
rm $NGX_AUTOTEST*

View File

@ -105,6 +105,7 @@ UNIX_DEPS="$CORE_DEPS $EVENT_DEPS \
src/os/unix/ngx_errno.h \
src/os/unix/ngx_alloc.h \
src/os/unix/ngx_files.h \
src/os/unix/ngx_shared.h \
src/os/unix/ngx_process.h \
src/os/unix/ngx_thread.h \
src/os/unix/ngx_socket.h \
@ -120,8 +121,9 @@ UNIX_SRCS="$CORE_SRCS $EVENT_SRCS \
src/os/unix/ngx_recv.c \
src/os/unix/ngx_readv_chain.c \
src/os/unix/ngx_writev_chain.c \
src/os/unix/ngx_daemon.c \
src/os/unix/ngx_shared.c \
src/os/unix/ngx_process.c \
src/os/unix/ngx_daemon.c \
src/os/unix/ngx_posix_init.c \
src/os/unix/ngx_process_cycle.c"
@ -152,6 +154,7 @@ WIN32_DEPS="$CORE_DEPS $EVENT_DEPS \
src/os/win32/ngx_errno.h \
src/os/win32/ngx_alloc.h \
src/os/win32/ngx_files.h \
src/os/win32/ngx_shared.h \
src/os/win32/ngx_process.h \
src/os/win32/ngx_socket.h \
src/os/win32/ngx_os.h \

101
auto/unix
View File

@ -40,14 +40,6 @@ ngx_types="int"; . auto/types/typedef
. auto/types/uintptr_t
ngx_func="sin_len"
ngx_func_inc="#include <sys/socket.h>
#include <netinet/in.h>"
ngx_func_test="struct sockaddr_in sa; sa.sin_len = 5"
. auto/func
# printf() formats
CC_WARN=$CC_STRONG
@ -71,19 +63,21 @@ ngx_fmt_name=RLIM_T_FMT; ngx_type="rlim_t"; . auto/types/sizeof
eval ngx_formats=\${ngx_${ngx_bytes}_fmt}; . auto/fmt/fmt
# syscalls and libc calls
# syscalls, libc calls and some features
ngx_feature_libs=
ngx_func_libs=
ngx_func="pread()"
ngx_func_inc=
ngx_func_test="char buf[1]; ssize_t n;
n = pread(0, buf, 1, 0)"
ngx_func_test="char buf[1]; ssize_t n; n = pread(0, buf, 1, 0)"
. auto/func
ngx_func="pwrite()"
ngx_func_inc=
ngx_func_test="char buf[1]; ssize_t n;
n = pwrite(1, buf, 1, 0)"
ngx_func_test="char buf[1]; ssize_t n; n = pwrite(1, buf, 1, 0)"
. auto/func
@ -113,7 +107,7 @@ ngx_func_test="struct tm t; time_t c=0; localtime_r(&c, &t)"
ngx_func="posix_memalign()"
ngx_func_inc="#include <stdlib.h>"
ngx_func_test="void *p, int n; n = posix_memalign(&p, 4096, 4096)"
ngx_func_test="void *p; int n; n = posix_memalign(&p, 4096, 4096)"
. auto/func
@ -123,13 +117,76 @@ ngx_func_test="void *p; p = memalign(4096, 4096)"
. auto/func
ngx_func="msghdr.msg_control"
ngx_func_inc="#include <sys/socket.h>"
ngx_func_test="struct msghdr msg; msg.msg_control = NULL"
. auto/func
ngx_feature="mmap(MAP_ANON|MAP_SHARED)"
ngx_feature_name="MAP_ANON"
ngx_feature_inc="#include <sys/mman.h>"
ngx_feature_test="void *p;
p = mmap(NULL, 4096, PROT_READ|PROT_WRITE,
MAP_ANON|MAP_SHARED, -1, 0);
if (p == MAP_FAILED) return 1;"
ngx_feature_run=yes
. auto/feature
ngx_func="FIONBIO"
ngx_func_inc="#include <sys/filio.h>"
ngx_func_test="int i; i = FIONBIO"
. auto/func
ngx_feature='mmap("/dev/zero", MAP_SHARED)'
ngx_feature_name="MAP_DEVZERO"
ngx_feature_inc="#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>"
ngx_feature_test='void *p; int fd;
fd = open("/dev/zero", O_RDWR);
p = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (p == MAP_FAILED) return 1;'
. auto/feature
ngx_feature="System V shared memory"
ngx_feature_name="SYSVSHM"
ngx_feature_inc="#include <sys/ipc.h>
#include <sys/shm.h>"
ngx_feature_test="int id;
id = shmget(IPC_PRIVATE, 4096, (SHM_R|SHM_W|IPC_CREAT));
if (id == -1) return 1;
shmctl(id, IPC_RMID, NULL);"
. auto/feature
ngx_feature="struct sockaddr_in.sin_len"
ngx_feature_name="sin_len"
ngx_feature_inc="#include <sys/socket.h>
#include <netinet/in.h>"
ngx_feature_test="struct sockaddr_in sa; sa.sin_len = 5"
ngx_feature_run=no
. auto/feature
ngx_feature="struct msghdr.msg_control"
ngx_feature_name="msghdr_msg_control"
ngx_feature_inc="#include <sys/socket.h>"
ngx_feature_test="struct msghdr msg; msg.msg_control = NULL"
. auto/feature
case $PLATFORM in
Linux:*)
ngx_feature_inc="#include <sys/ioctl.h>"
;;
*)
ngx_feature_inc="#include <sys/filio.h>"
;;
esac
ngx_feature="ioctl(FIONBIO)"
ngx_feature_name="FIONBIO"
ngx_feature_test="int i; i = FIONBIO"
. auto/feature
ngx_feature="struct tm.tm_gmtoff"
ngx_feature_name="gmtoff"
ngx_feature_inc="#include <time.h>"
ngx_feature_test="struct tm tm; tm.tm_gmtoff = 0"
. auto/feature

View File

@ -19,6 +19,7 @@ typedef struct ngx_connection_s ngx_connection_t;
#include <ngx_time.h>
#include <ngx_socket.h>
#include <ngx_errno.h>
#include <ngx_shared.h>
#include <ngx_process.h>
#include <ngx_thread.h>
#include <ngx_user.h>

View File

@ -123,15 +123,20 @@ void ngx_time_update(time_t s)
ngx_cached_http_time.data = p;
#if (HAVE_TIMEZONE)
#if (HAVE_GETTIMEZONE)
ngx_gmtoff = ngx_timezone();
ngx_gmtoff = ngx_gettimezone();
ngx_gmtime(ngx_cached_time + ngx_gmtoff * 60, &tm);
#elif (HAVE_GMTOFF)
ngx_localtime(&tm);
ngx_gmtoff = tm.ngx_tm_gmtoff / 60;
#else
ngx_localtime(&tm);
ngx_gmtoff = tm.ngx_tm_gmtoff / 60;
ngx_gmtoff = ngx_timezone(tm.ngx_tm_isdst);
#endif

View File

@ -187,6 +187,7 @@ static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle)
size = 128 /* ngx_accept_mutex */
+ 128; /* ngx_connection_counter */
#if 0
shared = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
if (shared == MAP_FAILED) {
@ -194,6 +195,11 @@ static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle)
"mmap(MAP_ANON|MAP_SHARED) failed");
return NGX_ERROR;
}
#endif
if (!(shared = ngx_create_shared_memory(size, cycle->log))) {
return NGX_ERROR;
}
ngx_accept_mutex_ptr = (ngx_atomic_t *) shared;
ngx_connection_counter = (ngx_atomic_t *) (shared + 128);
@ -611,7 +617,7 @@ static void *ngx_event_create_conf(ngx_cycle_t *cycle)
NGX_CONF_ERROR);
ecf->connections = NGX_CONF_UNSET_UINT;
ecf->use = NGX_CONF_UNSET;
ecf->use = NGX_CONF_UNSET_UINT;
ecf->multi_accept = NGX_CONF_UNSET;
ecf->accept_mutex = NGX_CONF_UNSET;
ecf->accept_mutex_delay = NGX_CONF_UNSET_MSEC;
@ -694,9 +700,9 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
return NGX_CONF_ERROR;
}
ngx_conf_unsigned_init_value(ecf->connections, DEFAULT_CONNECTIONS);
ngx_conf_init_unsigned_value(ecf->connections, DEFAULT_CONNECTIONS);
ngx_conf_unsigned_init_value(ecf->use, m);
ngx_conf_init_unsigned_value(ecf->use, m);
ngx_conf_init_ptr_value(ecf->name, module->name->data);
#endif

View File

@ -943,7 +943,8 @@ static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r)
* in CPU cache
*/
ua = ngx_strstr(r->headers_in.user_agent->value.data, "MSIE");
ua = (u_char *) ngx_strstr(r->headers_in.user_agent->value.data,
"MSIE");
if (ua
&& ua + 8 < r->headers_in.user_agent->value.data
+ r->headers_in.user_agent->value.len)

View File

@ -41,11 +41,6 @@
#include <netinet/tcp.h> /* TCP_CORK */
/* Linux has no <sys/filio.h> so autoconfigure does not find FIONBIO */
#ifndef HAVE_FIONBIO
#define HAVE_FIONBIO 1
#endif
#include <ngx_auto_config.h>

91
src/os/unix/ngx_shared.c Normal file
View File

@ -0,0 +1,91 @@
#include <ngx_config.h>
#include <ngx_core.h>
#if (HAVE_MAP_ANON)
void *ngx_create_shared_memory(size_t size, ngx_log_t *log)
{
void *p;
p = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
if (p == MAP_FAILED) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
"mmap(MAP_ANON|MAP_SHARED, " SIZE_T_FMT ") failed",
size);
return NULL;
}
return p;
}
#elif (HAVE_MAP_DEVZERO)
void *ngx_create_shared_memory(size_t size, ngx_log_t *log)
{
void *p;
ngx_fd_t fd;
fd = open("/dev/zero", O_RDWR);
if (fd == -1) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
"open(/dev/zero) failed");
return NULL;
}
p = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (p == MAP_FAILED) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
"mmap(/dev/zero, MAP_SHARED, " SIZE_T_FMT ") failed",
size);
p = NULL;
}
if (close(fd) == -1) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "close() failed");
}
return p;
}
#elif (HAVE_SYSVSHM)
#include <sys/ipc.h>
#include <sys/shm.h>
void *ngx_create_shared_memory(size_t size, ngx_log_t *log)
{
int id;
void *p;
id = shmget(IPC_PRIVATE, size, (SHM_R|SHM_W|IPC_CREAT));
if (id == -1) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
"shmget(" SIZE_T_FMT ") failed", size);
return NULL;
}
ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "shmget id: %d", id);
p = shmat(id, NULL, 0);
if (p == (void *) -1) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "shmat() failed");
p = NULL;
}
if (shmctl(id, IPC_RMID, NULL) == -1) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "shmctl(IPC_RMID) failed");
p = NULL;
}
return p;
}
#endif

12
src/os/unix/ngx_shared.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef _NGX_SHARED_H_INCLUDED_
#define _NGX_SHARED_H_INCLUDED_
#include <ngx_config.h>
#include <ngx_core.h>
void *ngx_create_shared_memory(size_t size, ngx_log_t *log);
#endif /* _NGX_SHARED_H_INCLUDED_ */

View File

@ -9,7 +9,6 @@
typedef uint64_t ngx_epoch_msec_t;
typedef ngx_int_t ngx_msec_t;
#define NGX_MAX_MSEC (ngx_msec_t) -1
typedef struct tm ngx_tm_t;
@ -20,11 +19,7 @@ typedef struct tm ngx_tm_t;
#define ngx_tm_mon tm_mon
#define ngx_tm_year tm_year
#define ngx_tm_wday tm_wday
#define ngx_tm_gmtoff tm_gmtoff
#ifndef SOLARIS
#define ngx_tm_zone tm_zone
#endif
#define ngx_tm_isdst tm_isdst
#define ngx_tm_sec_t int
#define ngx_tm_min_t int
@ -35,16 +30,14 @@ typedef struct tm ngx_tm_t;
#define ngx_tm_wday_t int
#if (HAVE_GMTOFF)
#define ngx_tm_gmtoff tm_gmtoff
#define ngx_tm_zone tm_zone
#endif
#if (SOLARIS)
#define HAVE_TIMEZONE 1
#define ngx_timezone() (- (daylight ? altzone : timezone) / 60)
#elif defined __linux__
#define HAVE_TIMEZONE 1
#define ngx_timezone() (- timezone / 60 + daylight * 60)
#define ngx_timezone(isdst) (- (isdst ? altzone : timezone) / 60)
#endif

12
src/os/win32/ngx_shared.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef _NGX_SHARED_H_INCLUDED_
#define _NGX_SHARED_H_INCLUDED_
#include <ngx_config.h>
#include <ngx_core.h>
void *ngx_create_shared_memory(size_t size, ngx_log_t *log);
#endif /* _NGX_SHARED_H_INCLUDED_ */

View File

@ -31,7 +31,7 @@ void ngx_gettimeofday(struct timeval *tp)
}
ngx_int_t ngx_timezone(void)
ngx_int_t ngx_gettimezone(void)
{
TIME_ZONE_INFORMATION tz;

View File

@ -9,7 +9,6 @@
typedef uint64_t ngx_epoch_msec_t;
typedef ngx_int_t ngx_msec_t;
#define NGX_MAX_MSEC (ngx_msec_t) -1
typedef SYSTEMTIME ngx_tm_t;
@ -32,11 +31,11 @@ typedef FILETIME ngx_mtime_t;
#define ngx_tm_wday_t u_short
#define ngx_msleep Sleep
#define ngx_msleep Sleep
#define HAVE_TIMEZONE 1
#define HAVE_GETIMEZONE 1
ngx_int_t ngx_timezone(void);
ngx_int_t ngx_gettimezone(void);
void ngx_gettimeofday(struct timeval *tp);