summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2004-11-11 14:07:14 +0000
committerIgor Sysoev <igor@sysoev.ru>2004-11-11 14:07:14 +0000
commit1b73583ba2c0e4b72d951218827e0c621427d389 (patch)
tree9e4d204e2cce91560d5cb8908b8a1a9f2c1d92ee
parentd6f24959428caed68a509a19ca4fd866d978a69c (diff)
downloadnginx-1b73583ba2c0e4b72d951218827e0c621427d389.tar.gz
nginx-0.1.5-RELEASE importrelease-0.1.5
*) Bugfix: on Solaris and Linux there may be too many "recvmsg() returned not enough data" alerts. *) Bugfix: there were the "writev() failed (22: Invalid argument)" errors on Solaris in proxy mode without sendfile. On other platforms that do not support sendfile at all the process got caught in an endless loop. *) Bugfix: segmentation fault on Solaris in proxy mode and using sendfile. *) Bugfix: segmentation fault on Solaris. *) Bugfix: on-line upgrade did not work on Linux. *) Bugfix: the ngx_http_autoindex_module module did not escape the spaces, the quotes, and the percent signs in the directory listing. *) Change: the decrease of the copy operations. *) Feature: the userid_p3p directive.
-rw-r--r--auto/cc/bcc18
-rw-r--r--auto/cc/conf20
-rw-r--r--auto/cc/gcc3
-rw-r--r--auto/cc/icc3
-rw-r--r--auto/cc/msvc48
-rw-r--r--auto/cc/name13
-rw-r--r--auto/cc/owc15
-rw-r--r--auto/feature1
-rw-r--r--auto/lib/md5/conf4
-rw-r--r--auto/lib/pcre/conf4
-rw-r--r--auto/lib/zlib/conf4
-rw-r--r--auto/make30
-rw-r--r--auto/modules18
-rw-r--r--auto/options14
-rw-r--r--auto/os/conf6
-rw-r--r--auto/os/linux7
-rw-r--r--auto/os/win323
-rw-r--r--auto/sources7
-rwxr-xr-xauto/unix72
-rw-r--r--docs/xml/nginx/changes.xml86
-rw-r--r--src/core/nginx.c61
-rw-r--r--src/core/nginx.h2
-rw-r--r--src/core/ngx_conf_file.c90
-rw-r--r--src/core/ngx_conf_file.h5
-rw-r--r--src/core/ngx_config.h13
-rw-r--r--src/core/ngx_connection.c68
-rw-r--r--src/core/ngx_connection.h4
-rw-r--r--src/core/ngx_cycle.c74
-rw-r--r--src/core/ngx_cycle.h5
-rw-r--r--src/core/ngx_file.c7
-rw-r--r--src/core/ngx_inet.c24
-rw-r--r--src/core/ngx_log.c193
-rw-r--r--src/core/ngx_log.h11
-rw-r--r--src/core/ngx_output_chain.c20
-rw-r--r--src/core/ngx_palloc.c8
-rw-r--r--src/core/ngx_regex.c4
-rw-r--r--src/core/ngx_string.c377
-rw-r--r--src/core/ngx_string.h29
-rw-r--r--src/core/ngx_times.c85
-rw-r--r--src/event/modules/ngx_aio_module.c4
-rw-r--r--src/event/modules/ngx_devpoll_module.c12
-rw-r--r--src/event/modules/ngx_epoll_module.c14
-rw-r--r--src/event/modules/ngx_iocp_module.c100
-rw-r--r--src/event/modules/ngx_kqueue_module.c9
-rw-r--r--src/event/modules/ngx_poll_module.c12
-rw-r--r--src/event/modules/ngx_rtsig_module.c4
-rw-r--r--src/event/modules/ngx_select_module.c24
-rw-r--r--src/event/ngx_event.c29
-rw-r--r--src/event/ngx_event.h6
-rw-r--r--src/event/ngx_event_accept.c29
-rw-r--r--src/event/ngx_event_acceptex.c94
-rw-r--r--src/event/ngx_event_connect.c8
-rw-r--r--src/event/ngx_event_connect.h2
-rw-r--r--src/event/ngx_event_connectex.c2
-rw-r--r--src/event/ngx_event_mutex.c7
-rw-r--r--src/event/ngx_event_openssl.c26
-rw-r--r--src/event/ngx_event_pipe.c35
-rw-r--r--src/event/ngx_event_posted.c13
-rw-r--r--src/event/ngx_event_posted.h6
-rw-r--r--src/event/ngx_event_timer.c5
-rw-r--r--src/event/ngx_event_timer.h4
-rw-r--r--src/http/modules/ngx_http_access_handler.c9
-rw-r--r--src/http/modules/ngx_http_autoindex_handler.c24
-rw-r--r--src/http/modules/ngx_http_charset_filter.c16
-rw-r--r--src/http/modules/ngx_http_chunked_filter.c33
-rw-r--r--src/http/modules/ngx_http_gzip_filter.c79
-rw-r--r--src/http/modules/ngx_http_headers_filter.c6
-rw-r--r--src/http/modules/ngx_http_index_handler.c18
-rw-r--r--src/http/modules/ngx_http_not_modified_filter.c2
-rw-r--r--src/http/modules/ngx_http_range_filter.c358
-rw-r--r--src/http/modules/ngx_http_rewrite_handler.c22
-rw-r--r--src/http/modules/ngx_http_static_handler.c17
-rw-r--r--src/http/modules/ngx_http_status_handler.c10
-rw-r--r--src/http/modules/ngx_http_userid_filter.c177
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_cache.c9
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.c110
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.h2
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_upstream.c34
-rw-r--r--src/http/ngx_http.c19
-rw-r--r--src/http/ngx_http.h8
-rw-r--r--src/http/ngx_http_core_module.c86
-rw-r--r--src/http/ngx_http_file_cache.c2
-rw-r--r--src/http/ngx_http_header_filter.c13
-rw-r--r--src/http/ngx_http_log_handler.c35
-rw-r--r--src/http/ngx_http_parse.c73
-rw-r--r--src/http/ngx_http_request.c232
-rw-r--r--src/http/ngx_http_request.h5
-rw-r--r--src/http/ngx_http_request_body.c4
-rw-r--r--src/http/ngx_http_script.c8
-rw-r--r--src/http/ngx_http_write_filter.c28
-rw-r--r--src/os/unix/ngx_aio_write_chain.c7
-rw-r--r--src/os/unix/ngx_alloc.c17
-rw-r--r--src/os/unix/ngx_channel.c7
-rw-r--r--src/os/unix/ngx_errno.c33
-rw-r--r--src/os/unix/ngx_errno.h4
-rw-r--r--src/os/unix/ngx_files.c110
-rw-r--r--src/os/unix/ngx_freebsd_init.c18
-rw-r--r--src/os/unix/ngx_freebsd_rfork_thread.c110
-rw-r--r--src/os/unix/ngx_freebsd_rfork_thread.h6
-rw-r--r--src/os/unix/ngx_freebsd_sendfile_chain.c6
-rw-r--r--src/os/unix/ngx_linux_config.h1
-rw-r--r--src/os/unix/ngx_linux_sendfile_chain.c4
-rw-r--r--src/os/unix/ngx_posix_init.c2
-rw-r--r--src/os/unix/ngx_process.c30
-rw-r--r--src/os/unix/ngx_process.h1
-rw-r--r--src/os/unix/ngx_process_cycle.c49
-rw-r--r--src/os/unix/ngx_pthread_thread.c55
-rw-r--r--src/os/unix/ngx_shared.c8
-rw-r--r--src/os/unix/ngx_socket.h2
-rw-r--r--src/os/unix/ngx_solaris_sendfilev_chain.c5
-rw-r--r--src/os/unix/ngx_thread.h14
-rw-r--r--src/os/unix/ngx_writev_chain.c18
-rw-r--r--src/os/win32/nginx.icobin0 -> 518 bytes
-rw-r--r--src/os/win32/nginx.rc16
-rw-r--r--src/os/win32/ngx_alloc.c5
-rw-r--r--src/os/win32/ngx_atomic.h2
-rw-r--r--src/os/win32/ngx_errno.c130
-rw-r--r--src/os/win32/ngx_errno.h2
-rw-r--r--src/os/win32/ngx_files.c20
-rw-r--r--src/os/win32/ngx_gui.c85
-rw-r--r--src/os/win32/ngx_gui.h27
-rw-r--r--src/os/win32/ngx_os.h2
-rw-r--r--src/os/win32/ngx_process.h1
-rw-r--r--src/os/win32/ngx_process_cycle.c207
-rw-r--r--src/os/win32/ngx_socket.h8
-rw-r--r--src/os/win32/ngx_thread.c68
-rw-r--r--src/os/win32/ngx_thread.h39
-rw-r--r--src/os/win32/ngx_win32_config.h15
-rw-r--r--src/os/win32/ngx_win32_init.c102
-rw-r--r--src/os/win32/ngx_wsarecv.c105
-rw-r--r--src/os/win32/ngx_wsasend_chain.c203
-rw-r--r--src/os/win32/tray.icobin0 -> 198 bytes
132 files changed, 2963 insertions, 1921 deletions
diff --git a/auto/cc/bcc b/auto/cc/bcc
index 5765c4713..a76b68f70 100644
--- a/auto/cc/bcc
+++ b/auto/cc/bcc
@@ -32,17 +32,31 @@ CFLAGS="$CFLAGS -w!"
# disable logo
CFLAGS="$CFLAGS -q"
+
# precompiled headers
CORE_DEPS="$CORE_DEPS $OBJS/ngx_config.csm"
NGX_PCH="$OBJS/ngx_config.csm"
NGX_BUILD_PCH="-H=$OBJS/ngx_config.csm"
NGX_USE_PCH="-Hu -H=$OBJS/ngx_config.csm"
-LINK="\$(CC)"
+
+# Win32 GUI mode application
+LINK="\$(CC) -laa"
+
+
+# the resource file
+NGX_RES="$OBJS/nginx.res"
+NGX_RCC="brcc32 -fo$OBJS/nginx.res \$(CORE_INCS) $NGX_WIN32_RC"
+# the pragma allows to link the resource file using bcc32 and
+# to avoid the direct ilink32 calling and the c0w32.obj's WinMain/main problem
+NGX_PRAGMA="#pragma resource \"$OBJS/nginx.res\""
+
ngx_include_opt="-I"
ngx_objout="-o"
ngx_binout="-e"
ngx_objext="obj"
ngx_binext=".exe"
-ngx_dirsep='\\'
+
+ngx_regex_dirsep='\\'
+ngx_dirsep="\\"
diff --git a/auto/cc/conf b/auto/cc/conf
index 77eeda79e..acb68f8a5 100644
--- a/auto/cc/conf
+++ b/auto/cc/conf
@@ -64,8 +64,8 @@ else
# . auto/cc/acc
# ;;
- msvc)
- # MSVC 6.0 SP2
+ msvc*)
+ # MSVC++ 6.0 SP2, MSVC++ Toolkit 2003
. auto/cc/msvc
;;
@@ -93,6 +93,22 @@ CFLAGS="$CFLAGS $NGX_CC_OPT"
if [ "$PLATFORM" != win32 ]; then
+ if test -n "$NGX_LD_OPT"; then
+ ngx_feature=--with-ld-opt=\"$NGX_LD_OPT\"
+ ngx_feature_name=DUMMY
+ ngx_feature_run=no
+ ngx_feature_incs=
+ ngx_feature_libs=
+ ngx_feature_test=
+ . auto/feature
+
+ if [ $ngx_found = no ]; then
+ echo $0: error: the invalid value in --with-ld-opt=\"$NGX_LD_OPT\"
+ echo
+ exit 1
+ fi
+ fi
+
ngx_feature="gcc variadic macros"
ngx_feature_name=HAVE_GCC_VARIADIC_MACROS
ngx_feature_run=yes
diff --git a/auto/cc/gcc b/auto/cc/gcc
index 61f048b7b..756e3977a 100644
--- a/auto/cc/gcc
+++ b/auto/cc/gcc
@@ -104,6 +104,3 @@ if [ ".$CPP" = "." ]; then
fi
LINK="\$(CC)"
-
-
-CC_STRONG="-Wall -Werror"
diff --git a/auto/cc/icc b/auto/cc/icc
index 94d5cddc5..89c6f3500 100644
--- a/auto/cc/icc
+++ b/auto/cc/icc
@@ -64,6 +64,3 @@ CFLAGS="$CFLAGS -Werror"
CFLAGS="$CFLAGS -g"
LINK="\$(CC)"
-
-
-CC_STRONG="-w1 -Werror"
diff --git a/auto/cc/msvc b/auto/cc/msvc
index d47d4b2a0..8272cac9a 100644
--- a/auto/cc/msvc
+++ b/auto/cc/msvc
@@ -2,7 +2,7 @@
# Copyright (C) Igor Sysoev
-# MSVC 6.0 SP2
+# MSVC 6.0 SP2, MSVC Toolkit 2003 (7.1)
# optimizations
@@ -31,8 +31,8 @@ case $CPU in
;;
pentium4)
- # optimize for Pentium 4
- #CPU_OPT="-G7"
+ # optimize for Pentium 4, MSVC 7
+ CPU_OPT="-G7"
;;
esac
@@ -47,30 +47,48 @@ CFLAGS="$CFLAGS -W4"
# stop on warning
CFLAGS="$CFLAGS -WX"
-# link with libcmt.lib, multithreaded
-#LIBC="-MT"
-# link with msvcrt.dll
-LIBC="-MD"
-
-CFLAGS="$CFLAGS $LIBC"
-
# disable logo
CFLAGS="$CFLAGS -nologo"
+
LINK="\$(CC)"
-# link flags
+# the link flags
CORE_LINK="$CORE_LINK -link -verbose:lib"
+if [ $NGX_CC_NAME = msvc7 ]; then
+ # link with libcmt.lib, multithreaded
+ LIBC="-MT"
+else
+ # link with msvcrt.dll
+ LIBC="-MD"
+fi
+
+CFLAGS="$CFLAGS $LIBC"
+
+# Win32 GUI mode application
+CORE_LIBS="$CORE_LIBS kernel32.lib user32.lib"
+CORE_LINK="$CORE_LINK -subsystem:windows -entry:mainCRTStartup"
+
# debug
CFLAGS="$CFLAGS -Yd"
CORE_LINK="$CORE_LINK -debug -debugtype:coff"
+
# precompiled headers
-CORE_DEPS="$CORE_DEPS $OBJS/ngx_config.pch"
-NGX_PCH="$OBJS/ngx_config.pch"
-NGX_BUILD_PCH="-Ycngx_config.h -Fp$OBJS/ngx_config.pch"
-NGX_USE_PCH="-Yungx_config.h -Fp$OBJS/ngx_config.pch"
+if [ $NGX_CC_NAME != msvc7 ]; then
+ CORE_DEPS="$CORE_DEPS $OBJS/ngx_config.pch"
+ NGX_PCH="$OBJS/ngx_config.pch"
+ NGX_BUILD_PCH="-Ycngx_config.h -Fp$OBJS/ngx_config.pch"
+ NGX_USE_PCH="-Yungx_config.h -Fp$OBJS/ngx_config.pch"
+fi
+
+
+# the resource file
+NGX_RES="$OBJS/nginx.res"
+NGX_RCC="rc -fo$NGX_RES \$(CORE_INCS) $NGX_WIN32_RC"
+CORE_LINK="$NGX_RES $CORE_LINK"
+
ngx_objout="-Fo"
ngx_binout="-Fe"
diff --git a/auto/cc/name b/auto/cc/name
index b9744799c..cbed6a741 100644
--- a/auto/cc/name
+++ b/auto/cc/name
@@ -6,8 +6,17 @@ echo $ngx_n "checking for C compiler ...$ngx_c"
if [ $CC = cl ]; then
- NGX_CC_NAME=msvc
- echo " using Microsoft Visual C compiler"
+ if `$NGX_WINE $CC -v 2>&1 \
+ | grep '^Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13' \
+ 2>&1 >/dev/null`; then
+
+ NGX_CC_NAME=msvc7
+ echo " using Microsoft Visual C++ 7 compiler"
+
+ else
+ NGX_CC_NAME=msvc
+ echo " using Microsoft Visual C++ compiler"
+ fi
else
if [ $CC = wcl386 ]; then
diff --git a/auto/cc/owc b/auto/cc/owc
index 0c8194dbb..789ffadae 100644
--- a/auto/cc/owc
+++ b/auto/cc/owc
@@ -59,18 +59,25 @@ CFLAGS="$CFLAGS -d2"
CFLAGS="$CFLAGS -zq"
# Open Watcom C 1.2
-#have=HAVE_C99_VARIADIC_MACROS . auto/have
+#have=NGX_HAVE_C99_VARIADIC_MACROS . auto/have
-# precompiled headers
+
+# the precompiled headers
CORE_DEPS="$CORE_DEPS $OBJS/ngx_config.pch"
NGX_PCH="$OBJS/ngx_config.pch"
NGX_BUILD_PCH="-fhq=$OBJS/ngx_config.pch"
NGX_USE_PCH="-fh=$OBJS/ngx_config.pch"
+
LINK="\$(CC)"
-# link flags
-CORE_LINK="$CORE_LINK -l=nt"
+# the link flags, built target is NT GUI mode application
+CORE_LINK="$CORE_LINK -l=nt_win"
+
+
+# the resource file
+NGX_RCC="wrc \$(CORE_INCS) -fo=$OBJS/nginx.res $NGX_WIN32_RC $OBJS/nginx.exe"
+
ngx_include_opt="-i="
ngx_objout="-fo"
diff --git a/auto/feature b/auto/feature
index 78676ef09..410f5398f 100644
--- a/auto/feature
+++ b/auto/feature
@@ -35,6 +35,7 @@ END
ngx_test="$CC $CC_TEST_FLAGS $CC_WARN $CC_AUX_FLAGS \
-o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"
+
eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1"
diff --git a/auto/lib/md5/conf b/auto/lib/md5/conf
index 623986f0f..27fd64127 100644
--- a/auto/lib/md5/conf
+++ b/auto/lib/md5/conf
@@ -17,12 +17,12 @@ if [ $MD5 != NONE ]; then
case "$NGX_CC_NAME" in
- msvc | owc | bcc)
+ msvc* | owc* | bcc)
LINK_DEPS="$LINK_DEPS $MD5/md5.lib"
CORE_LIBS="$CORE_LIBS $MD5/md5.lib"
;;
- icc)
+ icc*)
LINK_DEPS="$LINK_DEPS $MD5/libmd5.a"
# to allow -ipo optimization we link with the *.o but not library
diff --git a/auto/lib/pcre/conf b/auto/lib/pcre/conf
index cd516e1e7..cf26be27a 100644
--- a/auto/lib/pcre/conf
+++ b/auto/lib/pcre/conf
@@ -9,7 +9,7 @@ if [ $PCRE != NONE ]; then
case "$NGX_CC_NAME" in
- msvc | owc | bcc)
+ msvc* | owc* | bcc)
have=NGX_PCRE . auto/have
have=PCRE_STATIC . auto/have
CORE_DEPS="$CORE_DEPS $PCRE/pcre.h"
@@ -17,7 +17,7 @@ if [ $PCRE != NONE ]; then
CORE_LIBS="$CORE_LIBS $PCRE/pcre.lib"
;;
- icc)
+ icc*)
have=NGX_PCRE . auto/have
CORE_DEPS="$CORE_DEPS $PCRE/pcre.h"
diff --git a/auto/lib/zlib/conf b/auto/lib/zlib/conf
index f833d6165..797a2d309 100644
--- a/auto/lib/zlib/conf
+++ b/auto/lib/zlib/conf
@@ -7,12 +7,12 @@ if [ $ZLIB != NONE ]; then
case "$NGX_CC_NAME" in
- msvc | owc | bcc)
+ msvc* | owc* | bcc)
LINK_DEPS="$LINK_DEPS $ZLIB/zlib.lib"
CORE_LIBS="$CORE_LIBS $ZLIB/zlib.lib"
;;
- icc)
+ icc*)
LINK_DEPS="$LINK_DEPS $ZLIB/libz.a"
# to allow -ipo optimization we link with the *.o but not library
diff --git a/auto/make b/auto/make
index 8744d1f5f..c165078cf 100644
--- a/auto/make
+++ b/auto/make
@@ -132,7 +132,15 @@ ngx_all_objs=`echo $ngx_all_srcs \
ngx_modules_obj=`echo $ngx_modules_c | sed -e "s/\(.*\.\)c/\1$ngx_objext/"`
-ngx_deps=`echo $ngx_all_objs $ngx_modules_obj $LINK_DEPS \
+
+if test -n "$NGX_RES"; then
+ ngx_res=$NGX_RES
+else
+ ngx_res="$NGX_RC $NGX_ICONS"
+ ngx_rcc=`echo $NGX_RCC | sed -e "s/\//$ngx_regex_dirsep/g"`
+fi
+
+ngx_deps=`echo $ngx_all_objs $ngx_modules_obj $ngx_res $LINK_DEPS \
| sed -e "s/ *\([^ ][^ ]*\)/$ngx_regex_cont\1/g" \
-e "s/\//$ngx_regex_dirsep/g"`
@@ -146,10 +154,12 @@ ngx_libs=${CORE_LIBS:+`echo $NGX_LD_OPT $CORE_LIBS \
ngx_link=${CORE_LINK:+`echo $CORE_LINK \
| sed -e "s/\//$ngx_regex_dirsep/g" -e "s/^/$ngx_regex_cont/"`}
+
cat << END >> $NGX_MAKEFILE
$NGX_OBJS${ngx_dirsep}nginx${ngx_binext}: $ngx_deps$ngx_spacer
\$(LINK) ${ngx_binout}$NGX_OBJS${ngx_dirsep}nginx$ngx_cont$ngx_objs$ngx_libs$ngx_link
+ $ngx_rcc
END
@@ -256,6 +266,24 @@ END
fi
+# Win32 resource file
+
+if test -n "$NGX_RES"; then
+
+ ngx_res=`echo "$NGX_RES: $NGX_RC $NGX_ICONS" \
+ | sed -e "s/\//$ngx_regex_dirsep/g"`
+ ngx_rcc=`echo $NGX_RCC | sed -e "s/\//$ngx_regex_dirsep/g"`
+
+ cat << END >> $NGX_MAKEFILE
+
+$ngx_res
+ $ngx_rcc
+
+END
+
+fi
+
+
# the precompiled headers
if test -n "$NGX_PCH"; then
diff --git a/auto/modules b/auto/modules
index 7d79205fe..39dfa9df2 100644
--- a/auto/modules
+++ b/auto/modules
@@ -154,9 +154,14 @@ if [ $IMAP = YES ]; then
fi
-echo "#include <ngx_config.h>" > $NGX_MODULES_C
-echo "#include <ngx_core.h>" >> $NGX_MODULES_C
-echo >> $NGX_MODULES_C
+cat << END > $NGX_MODULES_C
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+$NGX_PRAGMA
+
+END
for mod in $modules
do
@@ -171,5 +176,8 @@ do
echo " &$mod," >> $NGX_MODULES_C
done
-echo " NULL" >> $NGX_MODULES_C
-echo "};" >> $NGX_MODULES_C
+cat << END >> $NGX_MODULES_C
+ NULL
+};
+
+END
diff --git a/auto/options b/auto/options
index 40a09b9bd..72e5b36bf 100644
--- a/auto/options
+++ b/auto/options
@@ -26,6 +26,9 @@ TEST_BUILD_DEVPOLL=NO
TEST_BUILD_EPOLL=NO
TEST_BUILD_RTSIG=NO
+PLATFORM=
+NGX_WINE=
+
EVENT_FOUND=NO
EVENT_RTSIG=NO
@@ -195,9 +198,8 @@ if [ $HTTP = NO ]; then
fi
-if [ ".$PLATFORM" = ".win32" -a $EVENT_POLL = YES ]; then
- EVENT_POLL=NO
- echo "$0: warning: --with-poll_module option is ignored for win32"
+if [ ".$PLATFORM" = ".win32" ]; then
+ NGX_WINE=$WINE
fi
@@ -211,12 +213,6 @@ if test -z "$NGX_GROUP"; then
fi
-if test -z "$NGX_USER"; then
- NGX_USER=nobody
- NGX_GROUP=nobody
-fi
-
-
case ".$SBIN_PATH" in
./*)
;;
diff --git a/auto/os/conf b/auto/os/conf
index 5154f2bba..5dcf400da 100644
--- a/auto/os/conf
+++ b/auto/os/conf
@@ -45,6 +45,12 @@ esac
if [ $PLATFORM != win32 ]; then
+ if test -z "$NGX_USER"; then
+ NGX_USER=nobody
+ NGX_GROUP=nobody
+ fi
+
+
ngx_feature="/dev/poll"
ngx_feature_name="devpoll"
ngx_feature_run=no
diff --git a/auto/os/linux b/auto/os/linux
index e68a0d27d..8518c6170 100644
--- a/auto/os/linux
+++ b/auto/os/linux
@@ -20,6 +20,13 @@ ngx_spacer='
CC_AUX_FLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64"
+
+if test -z "$NGX_USER"; then
+ NGX_USER=nobody
+ NGX_GROUP=nogroup
+fi
+
+
# Linux kernel version
version=`grep "#define LINUX_VERSION_CODE" /usr/include/linux/version.h \
diff --git a/auto/os/win32 b/auto/os/win32
index 9e83e67fe..dfbb246c8 100644
--- a/auto/os/win32
+++ b/auto/os/win32
@@ -15,7 +15,8 @@ CORE_INCS="$WIN32_INCS"
CORE_DEPS="$WIN32_DEPS"
CORE_SRCS="$WIN32_SRCS $IOCP_SRCS"
OS_CONFIG="$WIN32_CONFIG"
-CORE_LIBS="$CORE_LIBS ws2_32.lib"
+CORE_LIBS="$CORE_LIBS shell32.lib ws2_32.lib"
+NGX_ICONS="$NGX_WIN32_ICONS"
EVENT_MODULES="$EVENT_MODULES $IOCP_MODULE"
EVENT_FOUND=YES
diff --git a/auto/sources b/auto/sources
index bf5829f3b..2729f1bd7 100644
--- a/auto/sources
+++ b/auto/sources
@@ -175,8 +175,10 @@ WIN32_DEPS="$CORE_DEPS $EVENT_DEPS \
src/os/win32/ngx_shared.h \
src/os/win32/ngx_process.h \
src/os/win32/ngx_atomic.h \
+ src/os/win32/ngx_thread.h \
src/os/win32/ngx_socket.h \
src/os/win32/ngx_os.h \
+ src/os/win32/ngx_gui.h \
src/os/win32/ngx_process_cycle.h"
WIN32_CONFIG=src/os/win32/ngx_win32_config.h
@@ -187,14 +189,19 @@ WIN32_SRCS="$CORE_SRCS $EVENT_SRCS \
src/os/win32/ngx_files.c \
src/os/win32/ngx_time.c \
src/os/win32/ngx_process.c \
+ src/os/win32/ngx_thread.c \
src/os/win32/ngx_socket.c \
src/os/win32/ngx_wsarecv.c \
src/os/win32/ngx_wsarecv_chain.c \
src/os/win32/ngx_wsasend_chain.c \
src/os/win32/ngx_win32_init.c \
+ src/os/win32/ngx_gui.c \
src/os/win32/ngx_process_cycle.c \
src/event/ngx_event_acceptex.c"
+NGX_WIN32_ICONS="src/os/win32/nginx.ico src/os/win32/tray.ico"
+NGX_WIN32_RC="src/os/win32/nginx.rc"
+
HTTP_MODULES="ngx_http_module \
ngx_http_core_module \
diff --git a/auto/unix b/auto/unix
index ec0e3952d..af9ee01df 100755
--- a/auto/unix
+++ b/auto/unix
@@ -8,17 +8,17 @@ ngx_fmt_collect=yes
# C types
ngx_type="int"; . auto/types/sizeof
-ngx_formats="%d"; . auto/fmt/fmt
+#ngx_formats="%d"; . auto/fmt/fmt
ngx_type="long"; . auto/types/sizeof
-ngx_formats="%ld"; . auto/fmt/fmt
+#ngx_formats="%ld"; . auto/fmt/fmt
ngx_type="long long"; . auto/types/sizeof
-ngx_formats="%lld %qd"; . auto/fmt/fmt
+#ngx_formats="%lld %qd"; . auto/fmt/fmt
ngx_type="void *"; . auto/types/sizeof; ngx_ptr_size=$ngx_size
-ngx_fmt_name=PTR_FMT;
-eval ngx_formats=\${ngx_${ngx_ptr_size}_fmt}; . auto/fmt/ptrfmt
+#ngx_fmt_name=PTR_FMT;
+#eval ngx_formats=\${ngx_${ngx_ptr_size}_fmt}; . auto/fmt/ptrfmt
# POSIX types
@@ -46,28 +46,28 @@ ngx_type="rlim_t"; ngx_types="int"; . auto/types/typedef
# printf() formats
-CC_WARN=$CC_STRONG
-ngx_fmt_collect=no
-
-ngx_fmt_name=OFF_T_FMT; ngx_type="off_t"; . auto/types/sizeof
+#CC_WARN=$CC_STRONG
+#ngx_fmt_collect=no
+#
+#ngx_fmt_name=OFF_T_FMT; ngx_type="off_t"; . auto/types/sizeof
ngx_param=OFF_T_MAX_VALUE; ngx_value=$ngx_max_value; . auto/types/value
-eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt
-
-ngx_fmt_name=TIME_T_FMT; ngx_type="time_t"; . auto/types/sizeof
+#eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt
+#
+#ngx_fmt_name=TIME_T_FMT; ngx_type="time_t"; . auto/types/sizeof
ngx_param=TIME_T_SIZE; ngx_value=$ngx_size; . auto/types/value
ngx_param=TIME_T_LEN; ngx_value=$ngx_max_len; . auto/types/value
-eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt
-
-ngx_fmt_name=SIZE_T_FMT; ngx_type="size_t"; . auto/types/sizeof
-eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt
-
-ngx_fmt_name=SIZE_T_X_FMT; . auto/fmt/xfmt
-
-ngx_fmt_name=PID_T_FMT; ngx_type="pid_t"; . auto/types/sizeof
-eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt
-
-ngx_fmt_name=RLIM_T_FMT; ngx_type="rlim_t"; . auto/types/sizeof
-eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt
+#eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt
+#
+#ngx_fmt_name=SIZE_T_FMT; ngx_type="size_t"; . auto/types/sizeof
+#eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt
+#
+#ngx_fmt_name=SIZE_T_X_FMT; . auto/fmt/xfmt
+#
+#ngx_fmt_name=PID_T_FMT; ngx_type="pid_t"; . auto/types/sizeof
+#eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt
+#
+#ngx_fmt_name=RLIM_T_FMT; ngx_type="rlim_t"; . auto/types/sizeof
+#eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt
# syscalls, libc calls and some features
@@ -93,19 +93,23 @@ ngx_feature_test="char buf[1]; ssize_t n; n = pwrite(1, buf, 1, 0)"
ngx_feature="strerror_r()"
ngx_feature_name="strerror_r"
-ngx_feature_run=no
+ngx_feature_run=yes
ngx_feature_incs="#include <string.h>"
ngx_feature_libs=
-ngx_feature_test="char buf[20]; int n; n = strerror_r(1, buf, 20)"
+ngx_feature_test="char buf[32]; int n; n = strerror_r(1, buf, 32);
+ if (n > 32) return 1;"
. auto/feature
-ngx_feature="gnu_strerror_r()"
+# GNU style strerror_r() returns not length, but pointer
+
+ngx_feature="gnu style strerror_r()"
ngx_feature_name="gnu_strerror_r"
-ngx_feature_run=no
+ngx_feature_run=yes
ngx_feature_incs="#include <string.h>"
ngx_feature_libs=
-ngx_feature_test="char buf[20], *str; str = strerror_r(1, buf, 20)"
+ngx_feature_test="char buf[32]; int n; n = strerror_r(1, buf, 32);
+ if (n < 32) return 1;"
. auto/feature
@@ -184,16 +188,6 @@ ngx_feature_test="int id;
. auto/feature
-ngx_feature="struct sockaddr_in.sin_len"
-ngx_feature_name="sin_len"
-ngx_feature_run=no
-ngx_feature_incs="#include <sys/socket.h>
-#include <netinet/in.h>"
-ngx_feature_libs=
-ngx_feature_test="struct sockaddr_in sa; sa.sin_len = 5"
-. auto/feature
-
-
ngx_feature="struct msghdr.msg_control"
ngx_feature_name="msghdr_msg_control"
ngx_feature_run=no
diff --git a/docs/xml/nginx/changes.xml b/docs/xml/nginx/changes.xml
index 44293f540..52360471c 100644
--- a/docs/xml/nginx/changes.xml
+++ b/docs/xml/nginx/changes.xml
@@ -6,6 +6,92 @@
title="nginx">
+<changes ver="0.1.5" date="11.11.2004">
+
+<change type="bugfix">
+<para lang="ru">
+ÎÁ Solaris É Linux ÍÏÇÌÏ ÂÙÔØ ÏÞÅÎØ ÍÎÏÇÏ ÓÏÏÂÝÅÎÉÊ "recvmsg() returned
+not enough data".
+</para>
+<para lang="en">
+on Solaris and Linux there may be too many "recvmsg() returned not enough data"
+alerts.
+</para>
+</change>
+
+<change type="bugfix">
+<para lang="ru">
+× ÒÅÖÉÍÅ ÐÒÏËÓÉ ÂÅÚ ÉÓÐÏÌØÚÏ×ÁÎÉÑ sendfile ÎÁ Solaris ×ÏÚÎÉËÁÌÁ
+ÏÛÉÂËÁ "writev() failed (22: Invalid argument)". îÁ ÄÒÕÇÉÈ ÐÌÁÔÆÏÒÍÁÈ,
+ÎÅ ÐÏÄÄÅÒÖÉ×ÁÀÝÉÈ sendfile, ÐÒÏÃÅÓÓ ÚÁÃÉËÌÉ×ÁÌÓÑ.
+</para>
+<para lang="en">
+there were the "writev() failed (22: Invalid argument)" errors on
+Solaris in proxy mode without sendfile. On other platforms that do not
+support sendfile at all the process got caught in an endless loop.
+</para>
+</change>
+
+<change type="bugfix">
+<para lang="ru">
+ÐÒÉ ÉÓÐÏÌØÚÏ×ÁÎÉÉ sendfile × ÒÅÖÉÍÅ ÐÒÏËÓÉ ÎÁ Solaris ×ÏÚÎÉËÁÌ
+segmentation fault.
+</para>
+<para lang="en">
+segmentation fault on Solaris in proxy mode and using sendfile.
+</para>
+</change>
+
+<change type="bugfix">
+<para lang="ru">
+segmentation fault ÎÁ Solaris.
+</para>
+<para lang="en">
+segmentation fault on Solaris.
+</para>
+</change>
+
+<change type="bugfix">
+<para lang="ru">
+ÏÂÎÏ×ÌÅÎÉÅ ÉÓÐÏÌÎÑÅÍÏÇÏ ÆÁÊÌÁ ÎÁ ÌÅÔÕ ÎÅ ÒÁÂÏÔÁÌÏ ÎÁ Linux.
+</para>
+<para lang="en">
+on-line upgrade did not work on Linux.
+</para>
+</change>
+
+<change type="bugfix">
+<para lang="ru">
+× ÓÐÉÓËÅ ÆÁÊÌÏ×, ×ÙÄÁ×ÁÅÍÏÍ ÍÏÄÕÌÅÍ ngx_http_autoindex_module,
+ÎÅ ÐÅÒÅËÏÄÉÒÏ×ÁÌÉÓØ ÐÒÏÂÅÌÙ, ËÁ×ÙÞËÉ É ÚÎÁËÉ ÐÒÏÃÅÎÔÁ.
+</para>
+<para lang="en">
+the ngx_http_autoindex_module module did not escape the spaces,
+the quotes, and the percent signs in the directory listing.
+</para>
+</change>
+
+<change type="change">
+<para lang="ru">
+ÕÍÅÎØÛÅÎÉÅ ÏÐÅÒÁÃÉÊ ËÏÐÉÒÏ×ÁÎÉÑ.
+</para>
+<para lang="en">
+the decrease of the copy operations.
+</para>
+</change>
+
+<change type="feature">
+<para lang="ru">
+ÄÉÒÅËÔÉ×Á userid_p3p.
+</para>
+<para lang="en">
+the userid_p3p directive.
+</para>
+</change>
+
+</changes>
+
+
<changes ver="0.1.4" date="26.10.2004">
<change type="bugfix">
diff --git a/src/core/nginx.c b/src/core/nginx.c
index ab85b2373..53ac666cd 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -18,6 +18,13 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf);
static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
+static ngx_conf_enum_t ngx_debug_points[] = {
+ { ngx_string("stop"), NGX_DEBUG_POINTS_STOP },
+ { ngx_string("abort"), NGX_DEBUG_POINTS_ABORT },
+ { ngx_null_string, 0 }
+};
+
+
static ngx_command_t ngx_core_commands[] = {
{ ngx_string("daemon"),
@@ -41,6 +48,13 @@ static ngx_command_t ngx_core_commands[] = {
offsetof(ngx_core_conf_t, worker_processes),
NULL },
+ { ngx_string("debug_points"),
+ NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_enum_slot,
+ 0,
+ offsetof(ngx_core_conf_t, debug_points),
+ &ngx_debug_points },
+
#if (NGX_THREADS)
{ ngx_string("worker_threads"),
@@ -97,6 +111,7 @@ ngx_module_t ngx_core_module = {
ngx_uint_t ngx_max_module;
+
int main(int argc, char *const *argv, char *const *envp)
{
ngx_int_t i;
@@ -118,7 +133,7 @@ int main(int argc, char *const *argv, char *const *envp)
ngx_pid = ngx_getpid();
- if (!(log = ngx_log_init_stderr())) {
+ if (!(log = ngx_log_init())) {
return 1;
}
@@ -165,7 +180,7 @@ int main(int argc, char *const *argv, char *const *envp)
if (cycle == NULL) {
if (ngx_test_config) {
ngx_log_error(NGX_LOG_EMERG, log, 0,
- "the configuration file %s test failed",
+ "the configuration file \"%s\" test failed",
init_cycle.conf_file.data);
}
@@ -174,7 +189,7 @@ int main(int argc, char *const *argv, char *const *envp)
if (ngx_test_config) {
ngx_log_error(NGX_LOG_INFO, log, 0,
- "the configuration file %s was tested successfully",
+ "the configuration file \"%s\" was tested successfully",
cycle->conf_file.data);
return 0;
}
@@ -187,7 +202,7 @@ int main(int argc, char *const *argv, char *const *envp)
ngx_process = ccf->master ? NGX_PROCESS_MASTER : NGX_PROCESS_SINGLE;
-#if (WIN32)
+#if (NGX_WIN32)
#if 0
@@ -241,11 +256,14 @@ static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle)
return NGX_OK;
}
- ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
+ ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
"using inherited sockets from \"%s\"", inherited);
- ngx_init_array(cycle->listening, cycle->pool,
- 10, sizeof(ngx_listening_t), NGX_ERROR);
+ if (ngx_array_init(&cycle->listening, cycle->pool, 10,
+ sizeof(ngx_listening_t)) == NGX_ERROR)
+ {
+ return NGX_ERROR;
+ }
for (p = inherited, v = p; *p; p++) {
if (*p == ':' || *p == ';') {
@@ -260,7 +278,7 @@ static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle)
v = p + 1;
- if (!(ls = ngx_push_array(&cycle->listening))) {
+ if (!(ls = ngx_array_push(&cycle->listening))) {
return NGX_ERROR;
}
@@ -276,7 +294,8 @@ static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle)
ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv)
{
- char *env[3], *var, *p;
+ char *env[3], *var;
+ u_char *p;
ngx_uint_t i;
ngx_pid_t pid;
ngx_exec_ctx_t ctx;
@@ -290,20 +309,22 @@ ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv)
+ cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2,
cycle->log);
- p = (char *) ngx_cpymem(var, NGINX_VAR "=", sizeof(NGINX_VAR));
+ p = ngx_cpymem(var, NGINX_VAR "=", sizeof(NGINX_VAR));
ls = cycle->listening.elts;
for (i = 0; i < cycle->listening.nelts; i++) {
- p += ngx_snprintf(p, NGX_INT32_LEN + 2, "%u;", ls[i].fd);
+ p = ngx_sprintf(p, "%ud;", ls[i].fd);
}
+ *p = '\0';
+
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, "inherited: %s", var);
env[0] = var;
#if (NGX_SETPROCTITLE_USES_ENV)
- /* allocate spare 300 bytes for the new binary process title */
+ /* allocate the spare 300 bytes for the new binary process title */
env[1] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
@@ -430,12 +451,13 @@ static void *ngx_core_module_create_conf(ngx_cycle_t *cycle)
ccf->daemon = NGX_CONF_UNSET;
ccf->master = NGX_CONF_UNSET;
ccf->worker_processes = NGX_CONF_UNSET;
+ ccf->debug_points = NGX_CONF_UNSET;
+ ccf->user = (ngx_uid_t) NGX_CONF_UNSET;
+ ccf->group = (ngx_gid_t) NGX_CONF_UNSET;
#if (NGX_THREADS)
ccf->worker_threads = NGX_CONF_UNSET;
- ccf->thread_stack_size = NGX_CONF_UNSET;
+ ccf->thread_stack_size = NGX_CONF_UNSET_SIZE;
#endif
- ccf->user = (ngx_uid_t) NGX_CONF_UNSET;
- ccf->group = (ngx_gid_t) NGX_CONF_UNSET;
return ccf;
}
@@ -445,7 +467,7 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
{
ngx_core_conf_t *ccf = conf;
-#if !(WIN32)
+#if !(NGX_WIN32)
struct passwd *pwd;
struct group *grp;
#endif
@@ -453,6 +475,7 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
ngx_conf_init_value(ccf->daemon, 1);
ngx_conf_init_value(ccf->master, 1);
ngx_conf_init_value(ccf->worker_processes, 1);
+ ngx_conf_init_value(ccf->debug_points, 0);
#if (NGX_THREADS)
ngx_conf_init_value(ccf->worker_threads, 0);
@@ -460,9 +483,9 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
ngx_conf_init_size_value(ccf->thread_stack_size, 2 * 1024 * 1024);
#endif
-#if !(WIN32)
+#if !(NGX_WIN32)
- if (ccf->user == (uid_t) NGX_CONF_UNSET) {
+ if (ccf->user == (uid_t) NGX_CONF_UNSET && geteuid() == 0) {
pwd = getpwnam(NGX_USER);
if (pwd == NULL) {
@@ -509,7 +532,7 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
-#if (WIN32)
+#if (NGX_WIN32)
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
"\"user\" is not supported, ignored");
diff --git a/src/core/nginx.h b/src/core/nginx.h
index 0d42998f4..2be26e06b 100644
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -8,7 +8,7 @@
#define _NGINX_H_INCLUDED_
-#define NGINX_VER "nginx/0.1.4"
+#define NGINX_VER "nginx/0.1.5"
#define NGINX_VAR "NGINX"
#define NGX_NEWPID_EXT ".newbin"
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index fb629a439..3c7898ae2 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -73,7 +73,7 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
fd = ngx_open_file(filename->data, NGX_FILE_RDONLY, NGX_FILE_OPEN);
if (fd == NGX_INVALID_FILE) {
ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
- ngx_open_file_n " %s failed", filename->data);
+ ngx_open_file_n " \"%s\" failed", filename->data);
return NGX_CONF_ERROR;
}
@@ -84,7 +84,7 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) {
ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
- ngx_fd_info_n " %s failed", filename->data);
+ ngx_fd_info_n " \"%s\" failed", filename->data);
}
if (!(cf->conf_file->buffer = ngx_create_temp_buf(cf->pool, 1024))) {
@@ -103,8 +103,12 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
rc = ngx_conf_read_token(cf);
/*
- * ngx_conf_read_token() returns NGX_OK, NGX_ERROR,
- * NGX_CONF_FILE_DONE or NGX_CONF_BLOCK_DONE
+ * ngx_conf_read_token() may return
+ * NGX_ERROR there is error
+ * NGX_OK the token terminated by ";" was found
+ * NGX_CONF_BLOCK_START the token terminated by "{" was found
+ * NGX_CONF_BLOCK_DONE the "}" was found
+ * NGX_CONF_FILE_DONE the configuration file is done
*/
#if 0
@@ -115,13 +119,16 @@ ngx_log_debug(cf->log, "token %d" _ rc);
break;
}
- if (rc != NGX_OK) {
+ if (rc != NGX_OK && rc != NGX_CONF_BLOCK_START) {
break;
}
if (cf->handler) {
- /* custom handler, i.e. used in http "types { ... }" directive */
+ /*
+ * the custom handler, i.e., that is used in the http's
+ * "types { ... }" directive
+ */
rv = (*cf->handler)(cf, NULL, cf->handler_conf);
if (rv == NGX_CONF_OK) {
@@ -182,6 +189,31 @@ ngx_log_debug(cf->log, "command '%s'" _ cmd->name.data);
break;
}
+ if (!(cmd->type & NGX_CONF_BLOCK) && rc != NGX_OK)
+ {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "directive \"%s\" in %s:%d "
+ "is not terminated by \";\"",
+ name->data,
+ cf->conf_file->file.name.data,
+ cf->conf_file->line);
+ rc = NGX_ERROR;
+ break;
+ }
+
+ if ((cmd->type & NGX_CONF_BLOCK)
+ && rc != NGX_CONF_BLOCK_START)
+ {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "directive \"%s\" in %s:%d "
+ "has not the opening \"{\"",
+ name->data,
+ cf->conf_file->file.name.data,
+ cf->conf_file->line);
+ rc = NGX_ERROR;
+ break;
+ }
+
/* is the directive's argument count right ? */
if (cmd->type & NGX_CONF_ANY) {
@@ -396,10 +428,14 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _
continue;
}
- if (ch == ';' || ch == '{') {
+ if (ch == ';') {
return NGX_OK;
}
+ if (ch == '{') {
+ return NGX_CONF_BLOCK_START;
+ }
+
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
"unexpected '%c' in %s:%d",
ch, cf->conf_file->file.name.data,
@@ -427,6 +463,10 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _
return NGX_ERROR;
}
+ if (ch == '{') {
+ return NGX_CONF_BLOCK_START;
+ }
+
return NGX_OK;
case '}':
@@ -538,10 +578,14 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _
ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data);
#endif
- if (ch == ';' || ch == '{') {
+ if (ch == ';') {
return NGX_OK;
}
+ if (ch == '{') {
+ return NGX_CONF_BLOCK_START;
+ }
+
found = 0;
}
}
@@ -575,6 +619,18 @@ ngx_int_t ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name)
return NGX_OK;
}
+#if (NGX_WIN32)
+
+ if (name->len > 2
+ && name->data[1] == ':'
+ && ((name->data[0] >= 'a' && name->data[0] <= 'z')
+ || (name->data[0] >= 'A' && name->data[0] <= 'Z')))
+ {
+ return NGX_OK;
+ }
+
+#endif
+
old = *name;
name->len = cycle->root.len + old.len;
@@ -664,20 +720,22 @@ ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
void ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err,
char *fmt, ...)
{
- int len;
- char errstr[NGX_MAX_CONF_ERRSTR];
+ u_char errstr[NGX_MAX_CONF_ERRSTR], *buf, *last;
va_list args;
+ last = errstr + NGX_MAX_CONF_ERRSTR;
+
va_start(args, fmt);
- len = ngx_vsnprintf(errstr, sizeof(errstr) - 1, fmt, args);
+ buf = ngx_vsnprintf(errstr, last - errstr, fmt, args);
va_end(args);
+ *buf = '\0';
+
if (err) {
- len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
- " (%d: ", err);
- len += ngx_strerror_r(err, errstr + len, sizeof(errstr) - len - 1);
- errstr[len++] = ')';
- errstr[len] = '\0';
+ buf = ngx_snprintf(buf, last - buf - 1, " (%d: ", err);
+ buf = ngx_strerror_r(err, buf, last - buf - 1);
+ *buf++ = ')';
+ *buf = '\0';
}
ngx_log_error(level, cf->log, 0, "%s in %s:%d",
diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h
index 3a3db52b9..0e94056af 100644
--- a/src/core/ngx_conf_file.h
+++ b/src/core/ngx_conf_file.h
@@ -59,8 +59,9 @@
#define NGX_CONF_OK NULL
#define NGX_CONF_ERROR (char *) -1
-#define NGX_CONF_BLOCK_DONE 1
-#define NGX_CONF_FILE_DONE 2
+#define NGX_CONF_BLOCK_START 1
+#define NGX_CONF_BLOCK_DONE 2
+#define NGX_CONF_FILE_DONE 3
#define NGX_MODULE 0, 0
diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h
index 3590fae7a..9faf00a2d 100644
--- a/src/core/ngx_config.h
+++ b/src/core/ngx_config.h
@@ -39,7 +39,7 @@
#endif
-#if !(WIN32)
+#if !(NGX_WIN32)
#define ngx_signal_helper(n) SIG##n
#define ngx_signal_value(n) ngx_signal_helper(n)
@@ -72,8 +72,6 @@ typedef int ngx_int_t;
typedef u_int ngx_uint_t;
typedef int ngx_flag_t;
#define NGX_INT_T_LEN sizeof("-2147483648") - 1
-#define NGX_INT_T_FMT "d"
-#define NGX_UINT_T_FMT "u"
#else
@@ -81,8 +79,6 @@ typedef long ngx_int_t;
typedef u_long ngx_uint_t;
typedef long ngx_flag_t;
#define NGX_INT_T_LEN sizeof("-9223372036854775808") - 1
-#define NGX_INT_T_FMT "lld"
-#define NGX_UINT_T_FMT "llu"
#endif
@@ -131,5 +127,12 @@ typedef long ngx_flag_t;
#define NGX_MAXHOSTNAMELEN MAXHOSTNAMELEN
*/
+#if ((__GNU__ == 2) && (__GNUC_MINOR__ < 8))
+#define NGX_MAX_UINT32_VALUE 0xffffffffLL
+#else
+#define NGX_MAX_UINT32_VALUE 0xffffffff
+#endif
+
+
#endif /* _NGX_CONFIG_H_INCLUDED_ */
diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c
index 19f56292a..06fd85cde 100644
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -30,28 +30,27 @@ ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf,
return NULL;
}
-#if (HAVE_SIN_LEN)
- addr_in->sin_len = sizeof(struct sockaddr_in);
-#endif
addr_in->sin_family = AF_INET;
addr_in->sin_addr.s_addr = addr;
addr_in->sin_port = htons(port);
- if (!(ls->addr_text.data = ngx_palloc(cf->pool, INET_ADDRSTRLEN + 6))) {
+
+ ls->addr_text.data = ngx_palloc(cf->pool,
+ INET_ADDRSTRLEN - 1 + sizeof(":65535") - 1);
+ if (ls->addr_text.data == NULL) {
return NULL;
}
len = ngx_inet_ntop(AF_INET, &addr, ls->addr_text.data, INET_ADDRSTRLEN);
- ls->addr_text.len = ngx_snprintf((char *) ls->addr_text.data + len,
- 6, ":%d", port);
+
+ ls->addr_text.len = ngx_sprintf(ls->addr_text.data + len, ":%d", port)
+ - ls->addr_text.data;
+
ls->fd = (ngx_socket_t) -1;
ls->family = AF_INET;
ls->type = SOCK_STREAM;
ls->protocol = IPPROTO_IP;
-#if (WIN32)
- ls->flags = WSA_FLAG_OVERLAPPED;
-#endif
ls->sockaddr = (struct sockaddr *) addr_in;
ls->socklen = sizeof(struct sockaddr_in);
ls->addr = offsetof(struct sockaddr_in, sin_addr);
@@ -63,6 +62,7 @@ ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf,
ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle)
{
+ size_t len;
ngx_uint_t i;
ngx_listening_t *ls;
struct sockaddr_in *addr_in;
@@ -95,20 +95,26 @@ ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle)
ls[i].ignore = 1;
continue;
}
+
ls[i].addr_text_max_len = INET_ADDRSTRLEN;
- ls[i].addr_text.data = ngx_palloc(cycle->pool, ls[i].addr_text_max_len);
+
+ ls[i].addr_text.data = ngx_palloc(cycle->pool, INET_ADDRSTRLEN - 1
+ + sizeof(":65535") - 1);
if (ls[i].addr_text.data == NULL) {
return NGX_ERROR;
}
ls[i].family = addr_in->sin_family;
- ls[i].addr_text.len = ngx_sock_ntop(ls[i].family, ls[i].sockaddr,
- ls[i].addr_text.data,
- ls[i].addr_text_max_len);
- if (ls[i].addr_text.len == 0) {
+ len = ngx_sock_ntop(ls[i].family, ls[i].sockaddr,
+ ls[i].addr_text.data, INET_ADDRSTRLEN);
+ if (len == 0) {
return NGX_ERROR;
}
+
+ ls[i].addr_text.len = ngx_sprintf(ls[i].addr_text.data + len, ":%d",
+ ntohs(addr_in->sin_port))
+ - ls[i].addr_text.data;
}
return NGX_OK;
@@ -157,16 +163,15 @@ ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
continue;
}
- s = ngx_socket(ls[i].family, ls[i].type, ls[i].protocol,
- ls[i].flags);
+ s = ngx_socket(ls[i].family, ls[i].type, ls[i].protocol);
if (s == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- ngx_socket_n " %s failed", ls[i].addr_text.data);
+ ngx_socket_n " %V failed", &ls[i].addr_text);
return NGX_ERROR;
}
-#if (WIN32)
+#if (NGX_WIN32)
/*
* Winsock assignes a socket number divisible by 4
* so to find a connection we divide a socket number by 4.
@@ -182,8 +187,8 @@ ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
(const void *) &reuseaddr, sizeof(int)) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- "setsockopt(SO_REUSEADDR) %s failed",
- ls[i].addr_text.data);
+ "setsockopt(SO_REUSEADDR) %V failed",
+ &ls[i].addr_text);
return NGX_ERROR;
}
@@ -192,8 +197,8 @@ ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
if (!(ngx_event_flags & NGX_USE_AIO_EVENT)) {
if (ngx_nonblocking(s) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- ngx_nonblocking_n " %s failed",
- ls[i].addr_text.data);
+ ngx_nonblocking_n " %V failed",
+ &ls[i].addr_text);
return NGX_ERROR;
}
}
@@ -202,8 +207,8 @@ ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
if (ls[i].nonblocking) {
if (ngx_nonblocking(s) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- ngx_nonblocking_n " %s failed",
- ls[i].addr_text.data);
+ ngx_nonblocking_n " %V failed",
+ &ls[i].addr_text);
return NGX_ERROR;
}
}
@@ -212,15 +217,15 @@ ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
if (bind(s, ls[i].sockaddr, ls[i].socklen) == -1) {
err = ngx_socket_errno;
ngx_log_error(NGX_LOG_EMERG, log, err,
- "bind() to %s failed", ls[i].addr_text.data);
+ "bind() to %V failed", &ls[i].addr_text);
if (err != NGX_EADDRINUSE)
return NGX_ERROR;
if (ngx_close_socket(s) == -1)
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- ngx_close_socket_n " %s failed",
- ls[i].addr_text.data);
+ ngx_close_socket_n " %V failed",
+ &ls[i].addr_text);
failed = 1;
continue;
@@ -228,7 +233,7 @@ ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
if (listen(s, ls[i].backlog) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- "listen() to %s failed", ls[i].addr_text.data);
+ "listen() to %V failed", &ls[i].addr_text);
return NGX_ERROR;
}
@@ -273,7 +278,7 @@ void ngx_close_listening_sockets(ngx_cycle_t *cycle)
for (i = 0; i < cycle->listening.nelts; i++) {
fd = ls[i].fd;
-#if (WIN32)
+#if (NGX_WIN32)
/*
* Winsock assignes a socket number divisible by 4
* so to find a connection we divide a socket number by 4.
@@ -296,8 +301,7 @@ void ngx_close_listening_sockets(ngx_cycle_t *cycle)
if (ngx_close_socket(ls[i].fd) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_socket_errno,
- ngx_close_socket_n " %s failed",
- ls[i].addr_text.data);
+ ngx_close_socket_n " %V failed", &ls[i].addr_text);
}
cycle->connections[fd].fd = (ngx_socket_t) -1;
@@ -408,7 +412,7 @@ ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text)
}
if (err == NGX_ECONNRESET
-#if !(WIN32)
+#if !(NGX_WIN32)
|| err == NGX_EPIPE
#endif
|| err == NGX_ENOTCONN
diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h
index 8e2ba3970..e2257ac6c 100644
--- a/src/core/ngx_connection.h
+++ b/src/core/ngx_connection.h
@@ -24,7 +24,6 @@ typedef struct {
int family;
int type;
int protocol;
- int flags; /* Winsock2 flags */
void (*handler)(ngx_connection_t *c); /* handler of accepted
connection */
@@ -48,9 +47,6 @@ typedef struct {
unsigned inherited:1; /* inherited from previous process */
unsigned nonblocking_accept:1;
unsigned nonblocking:1;
-#if 0
- unsigned overlapped:1; /* Winsock2 overlapped */
-#endif
unsigned shared:1; /* shared between threads or processes */
#if (HAVE_DEFERRED_ACCEPT)
unsigned deferred_accept:1;
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index a1402f123..85d945809 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -9,6 +9,7 @@
#include <ngx_event.h>
+static ngx_int_t ngx_cmp_sockaddr(struct sockaddr *s1, struct sockaddr *s2);
static void ngx_clean_old_cycles(ngx_event_t *ev);
@@ -195,7 +196,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
failed = 0;
-#if !(WIN32)
+#if !(NGX_WIN32)
if (ngx_create_pidfile(cycle, old_cycle) == NGX_ERROR) {
failed = 1;
}
@@ -204,6 +205,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
if (!failed) {
+ /* open the new files */
+
part = &cycle->open_files.part;
file = part->elts;
@@ -227,7 +230,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
- "log: %0X %d \"%s\"",
+ "log: %p %d \"%s\"",
&file[i], file[i].fd, file[i].name.data);
if (file[i].fd == NGX_INVALID_FILE) {
@@ -238,7 +241,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
break;
}
-#if (WIN32)
+#if (NGX_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",
@@ -266,6 +269,9 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
}
if (!failed) {
+
+ /* handle the listening sockets */
+
if (old_cycle->listening.nelts) {
ls = old_cycle->listening.elts;
for (i = 0; i < old_cycle->listening.nelts; i++) {
@@ -274,16 +280,17 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
nls = cycle->listening.elts;
for (n = 0; n < cycle->listening.nelts; n++) {
+
for (i = 0; i < old_cycle->listening.nelts; i++) {
if (ls[i].ignore) {
continue;
}
- if (ngx_memcmp(nls[n].sockaddr,
- ls[i].sockaddr, ls[i].socklen) == 0)
+ if (ngx_cmp_sockaddr(nls[n].sockaddr, ls[i].sockaddr)
+ == NGX_OK)
{
fd = ls[i].fd;
-#if (WIN32)
+#if (NGX_WIN32)
/*
* Winsock assignes a socket number divisible by 4 so
* to find a connection we divide a socket number by 4.
@@ -294,10 +301,10 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
if (fd >= (ngx_socket_t) cycle->connection_n) {
ngx_log_error(NGX_LOG_EMERG, log, 0,
"%d connections is not enough to hold "
- "an open listening socket on %s, "
+ "an open listening socket on %V, "
"required at least %d connections",
cycle->connection_n,
- ls[i].addr_text.data, fd);
+ &ls[i].addr_text, fd);
failed = 1;
break;
}
@@ -372,8 +379,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
if (ngx_close_socket(ls[i].fd) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- ngx_close_socket_n " %s failed",
- ls[i].addr_text.data);
+ ngx_close_socket_n " %V failed",
+ &ls[i].addr_text);
}
}
@@ -384,12 +391,12 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
/* commit the new cycle configuration */
-#if !(WIN32)
+#if !(NGX_WIN32)
if (!ngx_test_config && cycle->log->file->fd != STDERR_FILENO) {
ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
- "dup2: %0X %d \"%s\"",
+ "dup2: %p %d \"%s\"",
cycle->log->file,
cycle->log->file->fd, cycle->log->file->name.data);
@@ -426,8 +433,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
if (ngx_close_socket(ls[i].fd) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- ngx_close_socket_n " %s failed",
- ls[i].addr_text.data);
+ ngx_close_socket_n " %V failed",
+ &ls[i].addr_text);
}
}
@@ -512,13 +519,38 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
}
-#if !(WIN32)
+static ngx_int_t ngx_cmp_sockaddr(struct sockaddr *s1, struct sockaddr *s2)
+{
+ struct sockaddr_in *sin1, *sin2;
+
+ /* AF_INET only */
+
+ if (s1->sa_family != AF_INET || s2->sa_family != AF_INET) {
+ return NGX_DECLINED;
+ }
+
+ sin1 = (struct sockaddr_in *) s1;
+ sin2 = (struct sockaddr_in *) s2;
+
+ if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) {
+ return NGX_DECLINED;
+ }
+
+ if (sin1->sin_port != sin2->sin_port) {
+ return NGX_DECLINED;
+ }
+
+ return NGX_OK;
+}
+
+
+#if !(NGX_WIN32)
ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle)
{
ngx_uint_t trunc;
size_t len;
- u_char *name, pid[NGX_INT64_LEN + 1];
+ u_char *name, pid[NGX_INT64_LEN];
ngx_file_t file;
ngx_core_conf_t *ccf, *old_ccf;
@@ -548,8 +580,6 @@ ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle)
}
}
- len = ngx_snprintf((char *) pid, NGX_INT64_LEN + 1, PID_T_FMT, ngx_pid);
-
ngx_memzero(&file, sizeof(ngx_file_t));
file.name = (ngx_inherited && getppid() > 1) ? ccf->newpid : ccf->pid;
file.log = cycle->log;
@@ -566,6 +596,8 @@ ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle)
}
if (!ngx_test_config) {
+ len = ngx_sprintf(pid, "%P", ngx_pid) - pid;
+
if (ngx_write_file(&file, pid, len, 0) == NGX_ERROR) {
return NGX_ERROR;
}
@@ -615,7 +647,7 @@ void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
ngx_uint_t i;
ngx_list_part_t *part;
ngx_open_file_t *file;
-#if !(WIN32)
+#if !(NGX_WIN32)
ngx_file_info_t fi;
#endif
@@ -649,7 +681,7 @@ void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
continue;
}
-#if (WIN32)
+#if (NGX_WIN32)
if (ngx_file_append_mode(fd) == NGX_ERROR) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
ngx_file_append_mode_n " \"%s\" failed",
@@ -730,7 +762,7 @@ void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
file[i].fd = fd;
}
-#if !(WIN32)
+#if !(NGX_WIN32)
if (cycle->log->file->fd != STDERR_FILENO) {
if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h
index 45b7b23b0..2baf82904 100644
--- a/src/core/ngx_cycle.h
+++ b/src/core/ngx_cycle.h
@@ -12,6 +12,10 @@
#include <ngx_core.h>
+#define NGX_DEBUG_POINTS_STOP 1
+#define NGX_DEBUG_POINTS_ABORT 2
+
+
struct ngx_cycle_s {
void ****conf_ctx;
ngx_pool_t *pool;
@@ -40,6 +44,7 @@ typedef struct {
ngx_flag_t master;
ngx_int_t worker_processes;
+ ngx_int_t debug_points;
ngx_uid_t user;
ngx_gid_t group;
diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c
index c7ee51372..8e1edbd1f 100644
--- a/src/core/ngx_file.c
+++ b/src/core/ngx_file.c
@@ -55,9 +55,8 @@ int ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path,
num = ngx_next_temp_number(0);
for ( ;; ) {
- ngx_snprintf((char *)
- (file->name.data + path->name.len + 1 + path->len),
- 11, "%010u", num);
+ ngx_sprintf(file->name.data + path->name.len + 1 + path->len,
+ "%010ud%Z", num);
ngx_create_hashed_filename(file, path);
@@ -83,7 +82,7 @@ int ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path,
if ((path->level[0] == 0)
|| (err != NGX_ENOENT
-#if (WIN32)
+#if (NGX_WIN32)
&& err != NGX_ENOTDIR
#endif
)) {
diff --git a/src/core/ngx_inet.c b/src/core/ngx_inet.c
index bf8a788ea..5cabb49b5 100644
--- a/src/core/ngx_inet.c
+++ b/src/core/ngx_inet.c
@@ -9,6 +9,17 @@
#include <ngx_core.h>
+/*
+ * ngx_sock_ntop() and ngx_inet_ntop() may be implemented as
+ * "ngx_sprintf(text, "%ud.%ud.%ud.%ud", p[0], p[1], p[2], p[3])",
+ * however, they were implemented long before the ngx_sprintf() appeared
+ * and they are faster by 1.5-2.5 times, so it is worth to keep them.
+ *
+ * By the way, the implementation using ngx_sprintf() is faster by 2.5-3 times
+ * than using FreeBSD libc's snrpintf().
+ */
+
+
ngx_inline static size_t ngx_sprint_uchar(u_char *text, u_char c, size_t len)
{
size_t n;
@@ -105,15 +116,8 @@ size_t ngx_sock_ntop(int family, struct sockaddr *addr, u_char *text,
text[n] = '\0';
return n;
-
-#if 0
- return ngx_snprintf((char *) text,
- len > INET_ADDRSTRLEN ? INET_ADDRSTRLEN : len,
- "%u.%u.%u.%u", p[0], p[1], p[2], p[3]);
-#endif
}
-
size_t ngx_inet_ntop(int family, void *addr, u_char *text, size_t len)
{
u_char *p;
@@ -163,12 +167,6 @@ size_t ngx_inet_ntop(int family, void *addr, u_char *text, size_t len)
text[n] = '\0';
return n;
-
-#if 0
- return ngx_snprintf((char *) text,
- len > INET_ADDRSTRLEN ? INET_ADDRSTRLEN : len,
- "%u.%u.%u.%u", p[0], p[1], p[2], p[3]);
-#endif
}
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index f1c0e97f3..521ba7aa3 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -8,7 +8,7 @@
#include <ngx_core.h>
-static void ngx_log_write(ngx_log_t *log, char *errstr, size_t len);
+static void ngx_log_write(ngx_log_t *log, u_char *errstr, size_t len);
static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
@@ -38,7 +38,7 @@ ngx_module_t ngx_errlog_module = {
ngx_errlog_commands, /* module directives */
NGX_CORE_MODULE, /* module type */
NULL, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
@@ -65,121 +65,104 @@ void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, va_list args)
#endif
{
- char errstr[MAX_ERROR_STR];
- size_t len, max;
#if (NGX_HAVE_VARIADIC_MACROS)
- va_list args;
+ va_list args;
#endif
+ u_char errstr[NGX_MAX_ERROR_STR], *p, *last;
if (log->file->fd == NGX_INVALID_FILE) {
return;
}
+ last = errstr + NGX_MAX_ERROR_STR;
+
ngx_memcpy(errstr, ngx_cached_err_log_time.data,
ngx_cached_err_log_time.len);
-#if (WIN32)
- max = MAX_ERROR_STR - 2;
-#else
- max = MAX_ERROR_STR - 1;
-#endif
-
- len = ngx_cached_err_log_time.len;
+ p = errstr + ngx_cached_err_log_time.len;
- len += ngx_snprintf(errstr + len, max - len, " [%s] ", err_levels[level]);
+ p = ngx_sprintf(p, " [%s] ", err_levels[level]);
/* pid#tid */
- len += ngx_snprintf(errstr + len, max - len,
- PID_T_FMT "#" TID_T_FMT ": ", ngx_log_pid, ngx_log_tid);
+ p = ngx_sprintf(p, "%P#" NGX_TID_T_FMT ": ", ngx_log_pid, ngx_log_tid);
if (log->data && *(int *) log->data != -1) {
- len += ngx_snprintf(errstr + len, max - len,
- "*%u ", *(u_int *) log->data);
+ p = ngx_sprintf(p, "*%ud ", *(u_int *) log->data);
}
#if (NGX_HAVE_VARIADIC_MACROS)
va_start(args, fmt);
- len += ngx_vsnprintf(errstr + len, max - len, fmt, args);
+ p = ngx_vsnprintf(p, last - p, fmt, args);
va_end(args);
#else
- len += ngx_vsnprintf(errstr + len, max - len, fmt, args);
+ p = ngx_vsnprintf(p, last - p, fmt, args);
#endif
if (err) {
- if (len > max - 50) {
+ if (p > last - 50) {
/* leave a space for an error code */
- len = max - 50;
- errstr[len++] = '.';
- errstr[len++] = '.';
- errstr[len++] = '.';
+ p = last - 50;
+ *p++ = '.';
+ *p++ = '.';
+ *p++ = '.';
}
-#if (WIN32)
+#if (NGX_WIN32)
+
if ((unsigned) err >= 0x80000000) {
- len += ngx_snprintf(errstr + len, max - len, " (%X: ", err);
- } else {
- len += ngx_snprintf(errstr + len, max - len, " (%d: ", err);
- }
-#else
- len += ngx_snprintf(errstr + len, max - len, " (%d: ", err);
-#endif
+ p = ngx_snprintf(p, last - p, " (%Xd: ", err);
- if (len >= max) {
- ngx_log_write(log, errstr, max);
- return;
+ } else {
+ p = ngx_snprintf(p, last - p, " (%d: ", err);
}
- len += ngx_strerror_r(err, errstr + len, max - len);
+#else
- if (len >= max) {
- ngx_log_write(log, errstr, max);
- return;
- }
+ p = ngx_snprintf(p, last - p, " (%d: ", err);
- errstr[len++] = ')';
+#endif
- if (len >= max) {
- ngx_log_write(log, errstr, max);
- return;
- }
+ p = ngx_strerror_r(err, p, last - p);
- } else {
- if (len >= max) {
- ngx_log_write(log, errstr, max);
- return;
+ if (p < last) {
+ *p++ = ')';
}
}
if (level != NGX_LOG_DEBUG && log->handler) {
- len += log->handler(log->data, errstr + len, max - len);
-
- if (len >= max) {
- len = max;
- }
+ p = log->handler(log->data, p, last - p);
}
- ngx_log_write(log, errstr, len);
+ ngx_log_write(log, errstr, p - errstr);
}
-static void ngx_log_write(ngx_log_t *log, char *errstr, size_t len)
+static void ngx_log_write(ngx_log_t *log, u_char *errstr, size_t len)
{
-#if (WIN32)
+#if (NGX_WIN32)
u_long written;
+ if (len >= NGX_MAX_ERROR_STR - 1) {
+ len = NGX_MAX_ERROR_STR - 2;
+ }
+
errstr[len++] = CR;
errstr[len++] = LF;
WriteFile(log->file->fd, errstr, len, &written, NULL);
#else
+ if (len == NGX_MAX_ERROR_STR) {
+ len--;
+ }
+
errstr[len++] = LF;
write(log->file->fd, errstr, len);
@@ -192,7 +175,7 @@ static void ngx_log_write(ngx_log_t *log, char *errstr, size_t len)
void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, ...)
{
- va_list args;
+ va_list args;
if (log->log_level >= level) {
va_start(args, fmt);
@@ -204,108 +187,50 @@ void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
void ngx_log_debug_core(ngx_log_t *log, ngx_err_t err, const char *fmt, ...)
{
- va_list args;
+ va_list args;
va_start(args, fmt);
ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, args);
va_end(args);
}
-
-void ngx_assert_core(ngx_log_t *log, const char *fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
- ngx_log_error_core(NGX_LOG_ALERT, log, 0, fmt, args);
- va_end(args);
-}
-
#endif
-ngx_log_t *ngx_log_init_stderr()
+ngx_log_t *ngx_log_init()
{
-#if (WIN32)
-
- ngx_stderr_fileno = GetStdHandle(STD_ERROR_HANDLE);
- ngx_stderr.fd = ngx_stderr_fileno;
-
- if (ngx_stderr_fileno == NGX_INVALID_FILE) {
-
- /* TODO: where can we log error ? */
-
- return NULL;
-
- } else if (ngx_stderr_fileno == NULL) {
-
- /* there are no associated standard handles */
-
- /* TODO: where can we can log possible errors ? */
-
- ngx_stderr.fd = NGX_INVALID_FILE;
- }
-
-#else
-
- ngx_stderr.fd = STDERR_FILENO;
-
-#endif
-
ngx_log.file = &ngx_stderr;
ngx_log.log_level = NGX_LOG_NOTICE;
- return &ngx_log;
-}
-
+#if (NGX_WIN32)
-#if 0
+ ngx_stderr.fd = ngx_open_file(NGX_ERROR_LOG_PATH, NGX_FILE_RDWR,
+ NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
-ngx_int_t ngx_log_init_error_log()
-{
- ngx_fd_t fd;
-
-#ifdef NGX_ERROR_LOG_PATH
-
- fd = ngx_open_file(NGX_ERROR_LOG_PATH, NGX_FILE_RDWR,
- NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
-
- if (fd == NGX_INVALID_FILE) {
- ngx_log_error(NGX_LOG_EMERG, (&ngx_log), ngx_errno,
- ngx_open_file_n " \"" NGX_ERROR_LOG_PATH "\" failed");
- return NGX_ERROR;
+ if (ngx_stderr.fd == NGX_INVALID_FILE) {
+ ngx_message_box("nginx", MB_OK, ngx_errno,
+ "Could not open error log file: "
+ ngx_open_file_n " \"" NGX_ERROR_LOG_PATH "\" failed");
+ return NULL;
}
-#if (WIN32)
-
- if (ngx_file_append_mode(fd) == NGX_ERROR) {
- ngx_log_error(NGX_LOG_EMERG, (&ngx_log), ngx_errno,
- ngx_file_append_mode_n " \"" NGX_ERROR_LOG_PATH
- "\" failed");
- return NGX_ERROR;
+ if (ngx_file_append_mode(ngx_stderr.fd) == NGX_ERROR) {
+ ngx_message_box("nginx", MB_OK, ngx_errno,
+ "Could not open error log file: "
+ ngx_file_append_mode_n " \"" NGX_ERROR_LOG_PATH
+ "\" failed");
+ return NULL;
}
#else
- if (dup2(fd, STDERR_FILENO) == NGX_ERROR) {
- ngx_log_error(NGX_LOG_EMERG, (&ngx_log), ngx_errno,
- "dup2(STDERR) failed");
- return NGX_ERROR;
- }
-
-#endif
-
-#else /* no NGX_ERROR_LOG_PATH */
-
- ngx_log.log_level = NGX_LOG_INFO;
+ ngx_stderr.fd = STDERR_FILENO;
#endif
- return NGX_OK;
+ return &ngx_log;
}
-#endif
-
ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args)
{
diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h
index 5ddd8fc65..c54c18723 100644
--- a/src/core/ngx_log.h
+++ b/src/core/ngx_log.h
@@ -40,7 +40,7 @@
#define NGX_LOG_DEBUG_ALL 0x7ffffff0
-typedef size_t (*ngx_log_handler_pt) (void *ctx, char *buf, size_t len);
+typedef u_char *(*ngx_log_handler_pt) (void *ctx, u_char *buf, size_t len);
struct ngx_log_s {
@@ -50,7 +50,8 @@ struct ngx_log_s {
ngx_log_handler_pt handler;
};
-#define MAX_ERROR_STR 2048
+
+#define NGX_MAX_ERROR_STR 2048
/*********************************/
@@ -88,7 +89,6 @@ void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, va_list args);
void ngx_log_debug_core(ngx_log_t *log, ngx_err_t err, const char *fmt, ...);
-void ngx_assert_core(ngx_log_t *log, const char *fmt, ...);
#endif /* VARIADIC MACROS */
@@ -195,10 +195,7 @@ void ngx_assert_core(ngx_log_t *log, const char *fmt, ...);
#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_stderr();
-#if 0
-ngx_int_t ngx_log_init_error_log();
-#endif
+ngx_log_t *ngx_log_init();
ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args);
char *ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log);
diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c
index 23b7846b9..30dda35be 100644
--- a/src/core/ngx_output_chain.c
+++ b/src/core/ngx_output_chain.c
@@ -162,7 +162,11 @@ ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in)
ctx->in = ctx->in->next;
}
- ngx_alloc_link_and_set_buf(cl, ctx->buf, ctx->pool, NGX_ERROR);
+ if (!(cl = ngx_alloc_chain_link(ctx->pool))) {
+ return NGX_ERROR;
+ }
+ cl->buf = ctx->buf;
+ cl->next = NULL;
*last_out = cl;
last_out = &cl->next;
ctx->buf = NULL;
@@ -266,7 +270,7 @@ static ngx_int_t ngx_output_chain_copy_buf(ngx_buf_t *dst, ngx_buf_t *src,
if ((size_t) n != size) {
ngx_log_error(NGX_LOG_ALERT, src->file->log, 0,
- ngx_read_file_n " reads only %d of %d from file",
+ ngx_read_file_n " reads only %z of %uz from file",
n, size);
if (n == 0) {
return NGX_ERROR;
@@ -306,20 +310,24 @@ ngx_int_t ngx_chain_writer(void *data, ngx_chain_t *in)
for (/* void */; in; in = in->next) {
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0,
- "WRITER buf: %d", ngx_buf_size(in->buf));
+ "chain writer buf size: %uz", ngx_buf_size(in->buf));
- ngx_alloc_link_and_set_buf(cl, in->buf, ctx->pool, NGX_ERROR);
+ if (!(cl = ngx_alloc_chain_link(ctx->pool))) {
+ return NGX_ERROR;
+ }
+ cl->buf = in->buf;
+ cl->next = NULL;
*ctx->last = cl;
ctx->last = &cl->next;
}
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0,
- "WRITER0: %X", ctx->out);
+ "chain writer in: %p", ctx->out);
ctx->out = ngx_send_chain(ctx->connection, ctx->out, ctx->limit);
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0,
- "WRITER1: %X", ctx->out);
+ "chain writer out: %p", ctx->out);
if (ctx->out == NGX_CHAIN_ERROR) {
return NGX_ERROR;
diff --git a/src/core/ngx_palloc.c b/src/core/ngx_palloc.c
index e41e971f9..ed13de513 100644
--- a/src/core/ngx_palloc.c
+++ b/src/core/ngx_palloc.c
@@ -33,8 +33,7 @@ void ngx_destroy_pool(ngx_pool_t *pool)
for (l = pool->large; l; l = l->next) {
- ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
- "free: " PTR_FMT, l->alloc);
+ ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, "free: %p", l->alloc);
if (l->alloc) {
free(l->alloc);
@@ -50,8 +49,7 @@ void ngx_destroy_pool(ngx_pool_t *pool)
for (p = pool, n = pool->next; /* void */; p = n, n = n->next) {
ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
- "free: " PTR_FMT ", unused: " SIZE_T_FMT,
- p, p->end - p->last);
+ "free: %p, unused: %uz", p, p->end - p->last);
if (n == NULL) {
break;
@@ -164,7 +162,7 @@ ngx_int_t ngx_pfree(ngx_pool_t *pool, void *p)
for (l = pool->large; l; l = l->next) {
if (p == l->alloc) {
ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
- "free: " PTR_FMT, l->alloc);
+ "free: %p", l->alloc);
free(l->alloc);
l->alloc = NULL;
diff --git a/src/core/ngx_regex.c b/src/core/ngx_regex.c
index 27dad8d06..35b489229 100644
--- a/src/core/ngx_regex.c
+++ b/src/core/ngx_regex.c
@@ -53,11 +53,11 @@ ngx_regex_t *ngx_regex_compile(ngx_str_t *pattern, ngx_int_t options,
if (re == NULL) {
if ((size_t) erroff == pattern->len) {
- ngx_snprintf((char *) err->data, err->len - 1,
+ ngx_snprintf(err->data, err->len - 1,
"pcre_compile() failed: %s in \"%s\"",
errstr, pattern->data);
} else {
- ngx_snprintf((char *) err->data, err->len - 1,
+ ngx_snprintf(err->data, err->len - 1,
"pcre_compile() failed: %s in \"%s\" at \"%s\"",
errstr, pattern->data, pattern->data + erroff);
}
diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c
index 390ca431d..94eadfbe2 100644
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -30,42 +30,92 @@ u_char *ngx_cpystrn(u_char *dst, u_char *src, size_t n)
/*
* supported formats:
- * %[0][width]O off_t
- * %[0][width]T time_t
- * %[0][width]S ssize_t
- * %[0][width]uS size_t
- * %[0][width]uxS size_t in hex
- * %[0][width]l long
- * %[0][width]d int
- * %[0][width]i ngx_int_t
- * %[0][width]ui ngx_uint_t
- * %[0][width]uxi ngx_uint_t in hex
- * %s null-terminated string
- * %c char
- * %% %
+ * %[0][width]O off_t
+ * %[0][width]T time_t
+ * %[0][width][u][x|X]z ssize_t/size_t
+ * %[0][width][u][x|X]d int/u_int
+ * %[0][width][u][x|X]l long
+ * %[0][width|m][u][x|X]i ngx_int_t/ngx_uint_t
+ * %[0][width][u][x|X]D int32_t/uint32_t
+ * %[0][width][u][x|X]L int64_t/uint64_t
+ * %P ngx_pid_t
+ * %r rlim_t
+ * %p pointer
+ * %V pointer to ngx_str_t
+ * %s null-terminated string
+ * %Z '\0'
+ * %c char
+ * %% %
*
+ * TODO:
+ * %M ngx_msec_t
+ * %A ngx_atomic_t
+ *
+ * reserved:
+ * %t ptrdiff_t
+ * %S null-teminated wchar string
+ * %C wchar
*/
-u_char *ngx_sprintf(u_char *buf, char *fmt, ...)
+
+u_char *ngx_sprintf(u_char *buf, const char *fmt, ...)
{
- u_char *p, c, temp[NGX_MAX_INT_LEN];
- int d;
- long l;
- off_t offset;
- size_t size, len;
- ssize_t ssize;
- time_t sec;
- va_list arg;
- ngx_int_t i;
- ngx_uint_t ui, zero, width, sign, hexadecimal;
- static u_char hex[] = "0123456789abcdef";
+ u_char *p;
+ va_list args;
+
+ va_start(args, fmt);
+ p = ngx_vsnprintf(buf, /* STUB */ 65536, fmt, args);
+ va_end(args);
+
+ return p;
+}
+
+
+u_char *ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...)
+{
+ u_char *p;
+ va_list args;
+
+ va_start(args, fmt);
+ p = ngx_vsnprintf(buf, max, fmt, args);
+ va_end(args);
+
+ return p;
+}
+
+
+u_char *ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args)
+{
+ u_char *p, zero, *last, temp[NGX_MAX_INT_LEN];
+ int d;
+ size_t len;
+ uint32_t ui32;
+ int64_t i64;
+ uint64_t ui64;
+ ngx_str_t *s;
+ ngx_uint_t width, sign, hexadecimal;
+ static u_char hex[] = "0123456789abcdef";
+ static u_char HEX[] = "0123456789ABCDEF";
+
+ if (max == 0) {
+ return buf;
+ }
- va_start(arg, fmt);
+ last = buf + max;
+
+ while (*fmt && buf < last) {
+
+ /*
+ * "buf < last" means that we could copy at least one character:
+ * the plain character, "%%", "%c", and minus without the checking
+ */
- while (*fmt) {
if (*fmt == '%') {
- zero = (*++fmt == '0') ? 1 : 0;
+ i64 = 0;
+ ui64 = 0;
+
+ zero = (u_char) ((*++fmt == '0') ? '0' : ' ');
width = 0;
sign = 1;
hexadecimal = 0;
@@ -85,8 +135,15 @@ u_char *ngx_sprintf(u_char *buf, char *fmt, ...)
fmt++;
continue;
+ case 'X':
+ hexadecimal = 2;
+ sign = 0;
+ fmt++;
+ continue;
+
case 'x':
hexadecimal = 1;
+ sign = 0;
fmt++;
continue;
@@ -100,133 +157,112 @@ u_char *ngx_sprintf(u_char *buf, char *fmt, ...)
switch (*fmt) {
- case 'O':
- offset = va_arg(arg, off_t);
+ case 'V':
+ s = va_arg(args, ngx_str_t *);
- if (offset < 0) {
- *buf++ = '-';
- offset = -offset;
- }
-
- do {
- *--p = (u_char) (offset % 10 + '0');
- } while (offset /= 10);
+ len = (buf + s->len < last) ? s->len : (size_t) (last - buf);
+ buf = ngx_cpymem(buf, s->data, len);
+ fmt++;
- break;
+ continue;
- case 'T':
- sec = va_arg(arg, time_t);
+ case 's':
+ p = va_arg(args, u_char *);
- if (sec < 0) {
- *buf++ = '-';
- sec = -sec;
+ while (*p && buf < last) {
+ *buf++ = *p++;
}
+ fmt++;
- do {
- *--p = (u_char) (sec % 10 + '0');
- } while (sec /= 10);
+ continue;
+ case 'O':
+ i64 = (int64_t) va_arg(args, off_t);
+ sign = 1;
break;
- case 'S':
- if (sign) {
- ssize = va_arg(arg, ssize_t);
-
- if (ssize < 0) {
- *buf++ = '-';
- size = (size_t) -ssize;
+ case 'P':
+ i64 = (int64_t) va_arg(args, ngx_pid_t);
+ sign = 1;
+ break;
- } else {
- size = (size_t) ssize;
- }
+ case 'T':
+ i64 = (int64_t) va_arg(args, time_t);
+ sign = 1;
+ break;
+ case 'z':
+ if (sign) {
+ i64 = (int64_t) va_arg(args, ssize_t);
} else {
- size = va_arg(arg, size_t);
+ ui64 = (uint64_t) va_arg(args, size_t);
}
+ break;
- if (hexadecimal) {
- do {
- *--p = hex[size & 0xf];
- } while (size >>= 4);
-
+ case 'i':
+ if (sign) {
+ i64 = (int64_t) va_arg(args, ngx_int_t);
} else {
- do {
- *--p = (u_char) (size % 10 + '0');
- } while (size /= 10);
+ ui64 = (uint64_t) va_arg(args, ngx_uint_t);
}
-
break;
- case 'l':
- l = va_arg(arg, long);
-
- if (l < 0) {
- *buf++ = '-';
- l = -l;
+ case 'd':
+ if (sign) {
+ i64 = (int64_t) va_arg(args, int);
+ } else {
+ ui64 = (uint64_t) va_arg(args, u_int);
}
-
- do {
- *--p = (u_char) (l % 10 + '0');
- } while (l /= 10);
-
break;
- case 'd':
- d = va_arg(arg, int);
-
- if (d < 0) {
- *buf++ = '-';
- d = -d;
+ case 'l':
+ if (sign) {
+ i64 = (int64_t) va_arg(args, long);
+ } else {
+ ui64 = (uint64_t) va_arg(args, u_long);
}
-
- do {
- *--p = (u_char) (d % 10 + '0');
- } while (d /= 10);
-
break;
- case 'i':
+ case 'D':
if (sign) {
- i = va_arg(arg, ngx_int_t);
-
- if (i < 0) {
- *buf++ = '-';
- ui = (ngx_uint_t) -i;
-
- } else {
- ui = (ngx_uint_t) i;
- }
-
+ i64 = (int64_t) va_arg(args, int32_t);
} else {
- ui = va_arg(arg, ngx_uint_t);
+ ui64 = (uint64_t) va_arg(args, uint32_t);
}
+ break;
- if (hexadecimal) {
- do {
- *--p = hex[ui & 0xf];
- } while (ui >>= 4);
-
+ case 'L':
+ if (sign) {
+ i64 = va_arg(args, int64_t);
} else {
- do {
- *--p = (u_char) (ui % 10 + '0');
- } while (ui /= 10);
+ ui64 = va_arg(args, uint64_t);
}
-
break;
- case 's':
- p = va_arg(arg, u_char *);
+#if !(NGX_WIN32)
+ case 'r':
+ i64 = (int64_t) va_arg(args, rlim_t);
+ sign = 1;
+ break;
+#endif
+
+ case 'p':
+ ui64 = (uintptr_t) va_arg(args, void *);
+ hexadecimal = 2;
+ sign = 0;
+ zero = '0';
+ width = 8;
+ break;
- while (*p) {
- *buf++ = *p++;
- }
+ case 'c':
+ d = va_arg(args, int);
+ *buf++ = (u_char) (d & 0xff);
fmt++;
continue;
- case 'c':
- d = va_arg(arg, int);
- *buf++ = (u_char) (d & 0xff);
+ case 'Z':
+ *buf++ = '\0';
fmt++;
continue;
@@ -243,15 +279,71 @@ u_char *ngx_sprintf(u_char *buf, char *fmt, ...)
continue;
}
+ if (sign) {
+ if (i64 < 0) {
+ *buf++ = '-';
+ ui64 = (uint64_t) -i64;
+
+ } else {
+ ui64 = (uint64_t) i64;
+ }
+ }
+
+ if (hexadecimal == 1) {
+ do {
+
+ /* the "(uint32_t)" cast disables the BCC's warning */
+ *--p = hex[(uint32_t) (ui64 & 0xf)];
+
+ } while (ui64 >>= 4);
+
+ } else if (hexadecimal == 2) {
+ do {
+
+ /* the "(uint32_t)" cast disables the BCC's warning */
+ *--p = HEX[(uint32_t) (ui64 & 0xf)];
+
+ } while (ui64 >>= 4);
+
+ } else if (ui64 <= NGX_MAX_UINT32_VALUE) {
+
+ /*
+ * To divide 64-bit number and to find the remainder
+ * on the x86 platform gcc and icc call the libc functions
+ * [u]divdi3() and [u]moddi3(), they call another function
+ * in return. On FreeBSD it is the qdivrem() function,
+ * its source code is about 170 lines of the code.
+ * The glibc counterpart is about 150 lines of the code.
+ *
+ * For 32-bit numbers gcc and icc use the inlined
+ * multiplication and shifts. For example, unsigned
+ * "i32 / 10" is compiled to "(i32 * 0xCCCCCCCD) >> 35".
+ */
+
+ ui32 = (uint32_t) ui64;
+
+ do {
+ *--p = (u_char) (ui32 % 10 + '0');
+ } while (ui32 /= 10);
+
+ } else {
+ do {
+ *--p = (u_char) (ui64 % 10 + '0');
+ } while (ui64 /= 10);
+ }
+
len = (temp + NGX_MAX_INT_LEN) - p;
- c = (u_char) (zero ? '0' : ' ');
+ while (len++ < width && buf < last) {
+ *buf++ = zero;
+ }
- while (len++ < width) {
- *buf++ = c;
+ len = (temp + NGX_MAX_INT_LEN) - p;
+ if (buf + len > last) {
+ len = last - buf;
}
- buf = ngx_cpymem(buf, p, ((temp + NGX_MAX_INT_LEN) - p));
+ buf = ngx_cpymem(buf, p, len);
fmt++;
@@ -260,10 +352,6 @@ u_char *ngx_sprintf(u_char *buf, char *fmt, ...)
}
}
- va_end(arg);
-
- *buf = '\0';
-
return buf;
}
@@ -505,12 +593,14 @@ ngx_int_t ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src)
}
-ngx_int_t ngx_escape_uri(u_char *dst, u_char *src, size_t size)
+ngx_uint_t ngx_escape_uri(u_char *dst, u_char *src, size_t size,
+ ngx_uint_t type)
{
- ngx_int_t n;
- ngx_uint_t i;
+ ngx_uint_t i, n;
+ uint32_t *escape;
static u_char hex[] = "0123456789abcdef";
- static uint32_t escape[] =
+
+ static uint32_t uri[] =
{ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
/* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
@@ -527,6 +617,31 @@ ngx_int_t ngx_escape_uri(u_char *dst, u_char *src, size_t size)
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ };
+ static uint32_t html[] =
+ { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
+
+ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
+ 0x80000021, /* 0000 0000 0000 0000 0000 0000 1010 0101 */
+
+ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
+
+ /* ~}| {zyx wvut srqp onml kjih gfed cba` */
+ 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
+
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
+ 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ };
+
+
+ if (type == NGX_ESCAPE_HTML) {
+ escape = html;
+
+ } else {
+ escape = uri;
+ }
+
if (dst == NULL) {
/* find the number of the characters to be escaped */
@@ -555,5 +670,5 @@ ngx_int_t ngx_escape_uri(u_char *dst, u_char *src, size_t size)
}
}
- return NGX_OK;
+ return 0;
}
diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h
index d7caaaf3d..51e0fd027 100644
--- a/src/core/ngx_string.h
+++ b/src/core/ngx_string.h
@@ -22,16 +22,13 @@ typedef struct {
#define ngx_null_string { 0, NULL }
-#if (WIN32)
+#if (NGX_WIN32)
#define ngx_strncasecmp(s1, s2, n) \
strnicmp((const char *) s1, (const char *) s2, n)
#define ngx_strcasecmp(s1, s2) \
stricmp((const char *) s1, (const char *) s2)
-#define ngx_snprintf _snprintf
-#define ngx_vsnprintf _vsnprintf
-
#else
#define ngx_strncasecmp(s1, s2, n) \
@@ -39,21 +36,20 @@ typedef struct {
#define ngx_strcasecmp(s1, s2) \
strcasecmp((const char *) s1, (const char *) s2)
-#define ngx_snprintf snprintf
-#define ngx_vsnprintf vsnprintf
-
#endif
-#define ngx_strncmp(s1, s2, n) \
- strncmp((const char *) s1, (const char *) s2, n)
+#define ngx_strncmp(s1, s2, n) strncmp((const char *) s1, (const char *) s2, n)
+
/* msvc and icc compile strcmp() to inline loop */
#define ngx_strcmp(s1, s2) strcmp((const char *) s1, (const char *) s2)
+
#define ngx_strstr(s1, s2) strstr((const char *) s1, (const char *) s2)
#define ngx_strlen(s) strlen((const char *) s)
+
/*
* msvc and icc compile memset() to the inline "rep stos"
* while ZeroMemory() and bzero() are the calls.
@@ -62,15 +58,20 @@ typedef struct {
#define ngx_memzero(buf, n) memset(buf, 0, n)
#define ngx_memset(buf, c, n) memset(buf, c, n)
+
/* msvc and icc compile memcpy() to the inline "rep movs" */
#define ngx_memcpy(dst, src, n) memcpy(dst, src, n)
#define ngx_cpymem(dst, src, n) ((u_char *) memcpy(dst, src, n)) + n
+
/* msvc and icc compile memcmp() to the inline loop */
#define ngx_memcmp memcmp
+
u_char *ngx_cpystrn(u_char *dst, u_char *src, size_t n);
-u_char *ngx_sprintf(u_char *buf, char *fmt, ...);
+u_char *ngx_sprintf(u_char *buf, const char *fmt, ...);
+u_char *ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...);
+u_char *ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args);
ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n);
ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n);
@@ -86,7 +87,13 @@ void ngx_md5_text(u_char *text, u_char *md5);
void ngx_encode_base64(ngx_str_t *dst, ngx_str_t *src);
ngx_int_t ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src);
-ngx_int_t ngx_escape_uri(u_char *dst, u_char *src, size_t size);
+
+
+#define NGX_ESCAPE_URI 0
+#define NGX_ESCAPE_HTML 1
+
+ngx_uint_t ngx_escape_uri(u_char *dst, u_char *src, size_t size,
+ ngx_uint_t type);
#define ngx_qsort qsort
diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c
index 40dbbdbaf..f06d64476 100644
--- a/src/core/ngx_times.c
+++ b/src/core/ngx_times.c
@@ -94,7 +94,7 @@ void ngx_time_init()
ngx_old_elapsed_msec = 0;
ngx_elapsed_msec = 0;
-#if !(WIN32)
+#if !(NGX_WIN32)
tzset();
#endif
@@ -150,15 +150,14 @@ void ngx_time_update(time_t s)
p = cached_http_time[slot];
- ngx_snprintf((char *) p, sizeof("Mon, 28 Sep 1970 06:00:00 GMT"),
- "%s, %02d %s %4d %02d:%02d:%02d GMT",
- week[ngx_cached_gmtime.ngx_tm_wday],
- ngx_cached_gmtime.ngx_tm_mday,
- months[ngx_cached_gmtime.ngx_tm_mon - 1],
- ngx_cached_gmtime.ngx_tm_year,
- ngx_cached_gmtime.ngx_tm_hour,
- ngx_cached_gmtime.ngx_tm_min,
- ngx_cached_gmtime.ngx_tm_sec);
+ ngx_sprintf(p, "%s, %02d %s %4d %02d:%02d:%02d GMT",
+ week[ngx_cached_gmtime.ngx_tm_wday],
+ ngx_cached_gmtime.ngx_tm_mday,
+ months[ngx_cached_gmtime.ngx_tm_mon - 1],
+ ngx_cached_gmtime.ngx_tm_year,
+ ngx_cached_gmtime.ngx_tm_hour,
+ ngx_cached_gmtime.ngx_tm_min,
+ ngx_cached_gmtime.ngx_tm_sec);
ngx_cached_http_time.data = p;
@@ -183,24 +182,22 @@ void ngx_time_update(time_t s)
p = cached_err_log_time[slot];
- ngx_snprintf((char *) p, sizeof("1970/09/28 12:00:00"),
- "%4d/%02d/%02d %02d:%02d:%02d",
- tm.ngx_tm_year, tm.ngx_tm_mon,
- tm.ngx_tm_mday, tm.ngx_tm_hour,
- tm.ngx_tm_min, tm.ngx_tm_sec);
+ ngx_sprintf(p, "%4d/%02d/%02d %02d:%02d:%02d",
+ tm.ngx_tm_year, tm.ngx_tm_mon,
+ tm.ngx_tm_mday, tm.ngx_tm_hour,
+ tm.ngx_tm_min, tm.ngx_tm_sec);
ngx_cached_err_log_time.data = p;
p = cached_http_log_time[slot];
- ngx_snprintf((char *) p, sizeof("28/Sep/1970:12:00:00 +0600"),
- "%02d/%s/%d:%02d:%02d:%02d %c%02d%02d",
- tm.ngx_tm_mday, months[tm.ngx_tm_mon - 1],
- tm.ngx_tm_year, tm.ngx_tm_hour,
- tm.ngx_tm_min, tm.ngx_tm_sec,
- ngx_gmtoff < 0 ? '-' : '+',
- abs(ngx_gmtoff / 60), abs(ngx_gmtoff % 60));
+ ngx_sprintf(p, "%02d/%s/%d:%02d:%02d:%02d %c%02d%02d",
+ tm.ngx_tm_mday, months[tm.ngx_tm_mon - 1],
+ tm.ngx_tm_year, tm.ngx_tm_hour,
+ tm.ngx_tm_min, tm.ngx_tm_sec,
+ ngx_gmtoff < 0 ? '-' : '+',
+ abs(ngx_gmtoff / 60), abs(ngx_gmtoff % 60));
ngx_cached_http_log_time.data = p;
@@ -213,9 +210,6 @@ void ngx_time_update(time_t s)
u_char *ngx_http_time(u_char *buf, time_t t)
-#if 0
-size_t ngx_http_time(u_char *buf, time_t t)
-#endif
{
ngx_tm_t tm;
@@ -229,25 +223,10 @@ size_t ngx_http_time(u_char *buf, time_t t)
tm.ngx_tm_hour,
tm.ngx_tm_min,
tm.ngx_tm_sec);
-
-#if 0
- return ngx_snprintf((char *) buf, sizeof("Mon, 28 Sep 1970 06:00:00 GMT"),
- "%s, %02d %s %4d %02d:%02d:%02d GMT",
- week[tm.ngx_tm_wday],
- tm.ngx_tm_mday,
- months[tm.ngx_tm_mon - 1],
- tm.ngx_tm_year,
- tm.ngx_tm_hour,
- tm.ngx_tm_min,
- tm.ngx_tm_sec);
-#endif
}
u_char *ngx_http_cookie_time(u_char *buf, time_t t)
-#if 0
-size_t ngx_http_cookie_time(u_char *buf, time_t t)
-#endif
{
ngx_tm_t tm;
@@ -270,32 +249,6 @@ size_t ngx_http_cookie_time(u_char *buf, time_t t)
tm.ngx_tm_hour,
tm.ngx_tm_min,
tm.ngx_tm_sec);
-
-#if 0
- if (tm.ngx_tm_year > 2037) {
- return ngx_snprintf((char *) buf,
- sizeof("Mon, 28-Sep-1970 06:00:00 GMT"),
- "%s, %02d-%s-%d %02d:%02d:%02d GMT",
- week[tm.ngx_tm_wday],
- tm.ngx_tm_mday,
- months[tm.ngx_tm_mon - 1],
- tm.ngx_tm_year,
- tm.ngx_tm_hour,
- tm.ngx_tm_min,
- tm.ngx_tm_sec);
- } else {
- return ngx_snprintf((char *) buf,
- sizeof("Mon, 28-Sep-70 06:00:00 GMT"),
- "%s, %02d-%s-%02d %02d:%02d:%02d GMT",
- week[tm.ngx_tm_wday],
- tm.ngx_tm_mday,
- months[tm.ngx_tm_mon - 1],
- tm.ngx_tm_year % 100,
- tm.ngx_tm_hour,
- tm.ngx_tm_min,
- tm.ngx_tm_sec);
- }
-#endif
}
diff --git a/src/event/modules/ngx_aio_module.c b/src/event/modules/ngx_aio_module.c
index 483d6752b..398c57102 100644
--- a/src/event/modules/ngx_aio_module.c
+++ b/src/event/modules/ngx_aio_module.c
@@ -110,6 +110,10 @@ static int ngx_aio_del_connection(ngx_connection_t *c, u_int flags)
return NGX_OK;
}
+ if (flags & NGX_CLOSE_EVENT) {
+ return NGX_OK;
+ }
+
rc = aio_cancel(c->fd, NULL);
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "aio_cancel: %d", rc);
diff --git a/src/event/modules/ngx_devpoll_module.c b/src/event/modules/ngx_devpoll_module.c
index ea1d19b20..663e2bfef 100644
--- a/src/event/modules/ngx_devpoll_module.c
+++ b/src/event/modules/ngx_devpoll_module.c
@@ -208,7 +208,7 @@ static int ngx_devpoll_add_event(ngx_event_t *ev, int event, u_int flags)
#if (NGX_DEBUG)
c = ev->data;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
- "devpoll add event: fd:%d ev:%04X", c->fd, event);
+ "devpoll add event: fd:%d ev:%04Xd", c->fd, event);
#endif
ev->active = 1;
@@ -229,7 +229,7 @@ static int ngx_devpoll_del_event(ngx_event_t *ev, int event, u_int flags)
#endif
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
- "devpoll del event: fd:%d ev:%04X", c->fd, event);
+ "devpoll del event: fd:%d ev:%04Xd", c->fd, event);
if (ngx_devpoll_set_event(ev, POLLREMOVE, flags) == NGX_ERROR) {
return NGX_ERROR;
@@ -268,7 +268,7 @@ static int ngx_devpoll_set_event(ngx_event_t *ev, int event, u_int flags)
c = ev->data;
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0,
- "devpoll fd:%d ev:%04X fl:%04X", c->fd, event, flags);
+ "devpoll fd:%d ev:%04Xd fl:%04Xd", c->fd, event, flags);
if (nchanges >= max_changes) {
ngx_log_error(NGX_LOG_WARN, ev->log, 0,
@@ -453,13 +453,13 @@ int ngx_devpoll_process_events(ngx_cycle_t *cycle)
}
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "devpoll: fd:%d, ev:%04X, rev:%04X",
+ "devpoll: fd:%d, ev:%04Xd, rev:%04Xd",
event_list[i].fd,
event_list[i].events, event_list[i].revents);
if (event_list[i].revents & (POLLERR|POLLHUP|POLLNVAL)) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
- "ioctl(DP_POLL) error fd:%d ev:%04X rev:%04X",
+ "ioctl(DP_POLL) error fd:%d ev:%04Xd rev:%04Xd",
event_list[i].fd,
event_list[i].events, event_list[i].revents);
}
@@ -468,7 +468,7 @@ int ngx_devpoll_process_events(ngx_cycle_t *cycle)
{
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
"strange ioctl(DP_POLL) events "
- "fd:%d ev:%04X rev:%04X",
+ "fd:%d ev:%04Xd rev:%04Xd",
event_list[i].fd,
event_list[i].events, event_list[i].revents);
}
diff --git a/src/event/modules/ngx_epoll_module.c b/src/event/modules/ngx_epoll_module.c
index 45791e9c7..8096932ec 100644
--- a/src/event/modules/ngx_epoll_module.c
+++ b/src/event/modules/ngx_epoll_module.c
@@ -232,7 +232,7 @@ static int ngx_epoll_add_event(ngx_event_t *ev, int event, u_int flags)
ee.data.ptr = (void *) ((uintptr_t) c | ev->instance);
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0,
- "epoll add event: fd:%d op:%d ev:%08X",
+ "epoll add event: fd:%d op:%d ev:%08XD",
c->fd, op, ee.events);
if (epoll_ctl(ep, op, c->fd, &ee) == -1) {
@@ -291,7 +291,7 @@ static int ngx_epoll_del_event(ngx_event_t *ev, int event, u_int flags)
}
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0,
- "epoll del event: fd:%d op:%d ev:%08X",
+ "epoll del event: fd:%d op:%d ev:%08XD",
c->fd, op, ee.events);
if (epoll_ctl(ep, op, c->fd, &ee) == -1) {
@@ -314,7 +314,7 @@ static int ngx_epoll_add_connection(ngx_connection_t *c)
ee.data.ptr = (void *) ((uintptr_t) c | c->read->instance);
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "epoll add connection: fd:%d ev:%08X", c->fd, ee.events);
+ "epoll add connection: fd:%d ev:%08XD", c->fd, ee.events);
if (epoll_ctl(ep, EPOLL_CTL_ADD, c->fd, &ee) == -1) {
ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
@@ -513,7 +513,7 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle)
*/
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "epoll: stale event " PTR_FMT, c);
+ "epoll: stale event %p", c);
continue;
}
@@ -522,18 +522,18 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle)
#endif
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0,
- "epoll: fd:%d ev:%04X d:" PTR_FMT,
+ "epoll: fd:%d ev:%04XD d:%p",
c->fd, event_list[i].events, event_list[i].data);
if (event_list[i].events & (EPOLLERR|EPOLLHUP)) {
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0,
- "epoll_wait() error on fd:%d ev:%04X",
+ "epoll_wait() error on fd:%d ev:%04XD",
c->fd, event_list[i].events);
}
if (event_list[i].events & ~(EPOLLIN|EPOLLOUT|EPOLLERR|EPOLLHUP)) {
ngx_log_error(NGX_LOG_ALERT, log, 0,
- "strange epoll_wait() events fd:%d ev:%04X",
+ "strange epoll_wait() events fd:%d ev:%04XD",
c->fd, event_list[i].events);
}
diff --git a/src/event/modules/ngx_iocp_module.c b/src/event/modules/ngx_iocp_module.c
index 1d15c93f8..4a3cd9fe9 100644
--- a/src/event/modules/ngx_iocp_module.c
+++ b/src/event/modules/ngx_iocp_module.c
@@ -82,7 +82,7 @@ ngx_os_io_t ngx_iocp_io = {
ngx_overlapped_wsarecv,
NULL,
NULL,
- ngx_wsasend_chain,
+ ngx_overlapped_wsasend_chain,
0
};
@@ -138,7 +138,7 @@ static ngx_int_t ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key)
c->write->active = 1;
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0,
- "iocp add: fd:%d k:%d ov:" PTR_FMT, c->fd, key, &ev->ovlp);
+ "iocp add: fd:%d k:%d ov:%p", c->fd, key, &ev->ovlp);
if (CreateIoCompletionPort((HANDLE) c->fd, iocp, key, 0) == NULL) {
ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
@@ -152,10 +152,16 @@ static ngx_int_t ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key)
static ngx_int_t ngx_iocp_del_connection(ngx_connection_t *c, u_int flags)
{
+#if 0
+ if (flags & NGX_CLOSE_EVENT) {
+ return NGX_OK;
+ }
+
if (CancelIo((HANDLE) c->fd) == 0) {
ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, "CancelIo() failed");
return NGX_ERROR;
}
+#endif
return NGX_OK;
}
@@ -195,12 +201,19 @@ static ngx_int_t ngx_iocp_process_events(ngx_cycle_t *cycle)
ngx_time_update(tv.tv_sec);
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "iocp: %d b:%d k:%d ov:" PTR_FMT, rc, bytes, key, ovlp);
+ "iocp: %d b:%d k:%d ov:%p", rc, bytes, key, ovlp);
delta = ngx_elapsed_msec;
ngx_elapsed_msec = (ngx_epoch_msec_t) tv.tv_sec * 1000
+ tv.tv_usec / 1000 - ngx_start_msec;
+ if (timer != INFINITE) {
+ delta = ngx_elapsed_msec - delta;
+
+ ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
+ "iocp timer: %d, delta: %d", timer, (int) delta);
+ }
+
if (err) {
if (ovlp == NULL) {
if (err != WAIT_TIMEOUT) {
@@ -210,49 +223,76 @@ static ngx_int_t ngx_iocp_process_events(ngx_cycle_t *cycle)
return NGX_ERROR;
}
- } else {
- ovlp->error = err;
+ if (timer != INFINITE && delta) {
+ ngx_event_expire_timers((ngx_msec_t) delta);
+ }
+
+ return NGX_OK;
}
- }
- if (timer != INFINITE) {
- delta = ngx_elapsed_msec - delta;
+ ovlp->error = err;
+ }
- ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "iocp timer: %d, delta: %d", timer, (int) delta);
+ if (ovlp == NULL) {
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
+ "GetQueuedCompletionStatus() returned no operation");
+ return NGX_ERROR;
}
- if (ovlp) {
- ev = ovlp->event;
- ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "iocp event:" PTR_FMT, ev);
+ ev = ovlp->event;
- switch (key) {
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, err, "iocp event:%p", ev);
- case NGX_IOCP_ACCEPT:
- if (bytes) {
- ev->ready = 1;
- }
- break;
- case NGX_IOCP_IO:
- ev->complete = 1;
- ev->ready = 1;
- break;
+ if (err == ERROR_NETNAME_DELETED /* the socket was closed */
+ || err == ERROR_OPERATION_ABORTED /* the operation was canceled */)
+ {
- case NGX_IOCP_CONNECT:
- ev->ready = 1;
+ /*
+ * the WSA_OPERATION_ABORTED completion notification
+ * for a file descriptor that was closed
+ */
+
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, err,
+ "iocp: aborted event %p", ev);
+
+ if (timer != INFINITE && delta) {
+ ngx_event_expire_timers((ngx_msec_t) delta);
}
- ev->available = bytes;
+ return NGX_OK;
+ }
- ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "iocp event handler: " PTR_FMT, ev->event_handler);
+ if (err) {
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
+ "GetQueuedCompletionStatus() returned operation error");
+ }
- ev->event_handler(ev);
+ switch (key) {
+
+ case NGX_IOCP_ACCEPT:
+ if (bytes) {
+ ev->ready = 1;
+ }
+ break;
+
+ case NGX_IOCP_IO:
+ ev->complete = 1;
+ ev->ready = 1;
+ break;
+
+ case NGX_IOCP_CONNECT:
+ ev->ready = 1;
}
+ ev->available = bytes;
+
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
+ "iocp event handler: %p", ev->event_handler);
+
+ ev->event_handler(ev);
+
if (timer != INFINITE && delta) {
ngx_event_expire_timers((ngx_msec_t) delta);
}
diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c
index e6bebb559..e0fae6f93 100644
--- a/src/event/modules/ngx_kqueue_module.c
+++ b/src/event/modules/ngx_kqueue_module.c
@@ -367,7 +367,7 @@ static ngx_int_t ngx_kqueue_set_event(ngx_event_t *ev, int filter, u_int flags)
c = ev->data;
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "kevent set event: %d: ft:%d fl:%04X",
+ "kevent set event: %d: ft:%d fl:%04Xd",
c->fd, filter, flags);
if (nchanges >= max_changes) {
@@ -599,7 +599,7 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle)
*/
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "kevent: stale event " PTR_FMT, ev);
+ "kevent: stale event %p", ev);
continue;
}
@@ -776,9 +776,8 @@ static ngx_inline void ngx_kqueue_dump_event(ngx_log_t *log, struct kevent *kev)
{
ngx_log_debug6(NGX_LOG_DEBUG_EVENT, log, 0,
(kev->ident > 0x8000000 && kev->ident != (unsigned) -1) ?
- "kevent: " PTR_FMT ": ft:%d fl:%04X ff:%08X d:%d ud:"
- PTR_FMT:
- "kevent: %d: ft:%d fl:%04X ff:%08X d:%d ud:" PTR_FMT,
+ "kevent: %p: ft:%d fl:%04Xd ff:%08Xd d:%d ud:%p":
+ "kevent: %d: ft:%d fl:%04Xd ff:%08Xd d:%d ud:%p",
kev->ident, kev->filter,
kev->flags, kev->fflags,
kev->data, kev->udata);
diff --git a/src/event/modules/ngx_poll_module.c b/src/event/modules/ngx_poll_module.c
index bf78e8f37..18f72c3b5 100644
--- a/src/event/modules/ngx_poll_module.c
+++ b/src/event/modules/ngx_poll_module.c
@@ -302,7 +302,7 @@ static ngx_int_t ngx_poll_process_events(ngx_cycle_t *cycle)
if (cycle->log->log_level & NGX_LOG_DEBUG_ALL) {
for (i = 0; i < nevents; i++) {
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "poll: %d: fd:%d ev:%04X",
+ "poll: %d: fd:%d ev:%04Xd",
i, event_list[i].fd, event_list[i].events);
}
}
@@ -380,13 +380,13 @@ static ngx_int_t ngx_poll_process_events(ngx_cycle_t *cycle)
#if 0
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "poll: %d: fd:%d ev:%04X rev:%04X",
+ "poll: %d: fd:%d ev:%04Xd rev:%04Xd",
i, event_list[i].fd,
event_list[i].events, event_list[i].revents);
#else
if (event_list[i].revents) {
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "poll: %d: fd:%d ev:%04X rev:%04X",
+ "poll: %d: fd:%d ev:%04Xd rev:%04Xd",
i, event_list[i].fd,
event_list[i].events, event_list[i].revents);
}
@@ -394,7 +394,7 @@ static ngx_int_t ngx_poll_process_events(ngx_cycle_t *cycle)
if (event_list[i].revents & POLLNVAL) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
- "poll() error fd:%d ev:%04X rev:%04X",
+ "poll() error fd:%d ev:%04Xd rev:%04Xd",
event_list[i].fd,
event_list[i].events, event_list[i].revents);
}
@@ -402,7 +402,7 @@ static ngx_int_t ngx_poll_process_events(ngx_cycle_t *cycle)
if (event_list[i].revents & ~(POLLIN|POLLOUT|POLLERR|POLLHUP|POLLNVAL))
{
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
- "strange poll() events fd:%d ev:%04X rev:%04X",
+ "strange poll() events fd:%d ev:%04Xd rev:%04Xd",
event_list[i].fd,
event_list[i].events, event_list[i].revents);
}
@@ -529,7 +529,7 @@ static ngx_int_t ngx_poll_process_events(ngx_cycle_t *cycle)
for ( ;; ) {
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "accept event " PTR_FMT, ev);
+ "accept event %p", ev);
if (ev == NULL) {
break;
diff --git a/src/event/modules/ngx_rtsig_module.c b/src/event/modules/ngx_rtsig_module.c
index 4f2f48097..3c0ea9511 100644
--- a/src/event/modules/ngx_rtsig_module.c
+++ b/src/event/modules/ngx_rtsig_module.c
@@ -383,7 +383,7 @@ ngx_int_t ngx_rtsig_process_events(ngx_cycle_t *cycle)
} else {
err = 0;
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "rtsig signo:%d fd:%d band:%X",
+ "rtsig signo:%d fd:%d band:%04Xd",
signo, si.si_fd, si.si_band);
}
@@ -434,7 +434,7 @@ ngx_int_t ngx_rtsig_process_events(ngx_cycle_t *cycle)
ngx_accept_mutex_unlock();
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "rtsig: stale event " PTR_FMT, c);
+ "rtsig: stale event %p", c);
return NGX_OK;
}
diff --git a/src/event/modules/ngx_select_module.c b/src/event/modules/ngx_select_module.c
index 06ca4b32d..14e6f81a3 100644
--- a/src/event/modules/ngx_select_module.c
+++ b/src/event/modules/ngx_select_module.c
@@ -23,7 +23,7 @@ static fd_set master_write_fd_set;
static fd_set work_read_fd_set;
static fd_set work_write_fd_set;
-#if (WIN32)
+#if (NGX_WIN32)
static int max_read;
static int max_write;
#else
@@ -114,7 +114,7 @@ static ngx_int_t ngx_select_init(ngx_cycle_t *cycle)
ngx_event_flags = NGX_USE_LEVEL_EVENT|NGX_USE_ONESHOT_EVENT;
-#if (WIN32)
+#if (NGX_WIN32)
max_read = max_write = 0;
#else
max_fd = -1;
@@ -150,7 +150,7 @@ static ngx_int_t ngx_select_add_event(ngx_event_t *ev, int event, u_int flags)
return NGX_OK;
}
-#if (WIN32)
+#if (NGX_WIN32)
if ((event == NGX_READ_EVENT) && (max_read >= FD_SETSIZE)
|| (event == NGX_WRITE_EVENT) && (max_write >= FD_SETSIZE))
@@ -211,7 +211,7 @@ static ngx_int_t ngx_select_del_event(ngx_event_t *ev, int event, u_int flags)
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
"select del event fd:%d ev:%d", c->fd, event);
-#if (WIN32)
+#if (NGX_WIN32)
if (event == NGX_READ_EVENT) {
FD_CLR(c->fd, &master_read_fd_set);
@@ -280,7 +280,7 @@ static ngx_int_t ngx_select_process_events(ngx_cycle_t *cycle)
expire = 1;
-#if !(WIN32)
+#if !(NGX_WIN32)
if (ngx_accept_mutex) {
if (ngx_accept_disabled > 0) {
@@ -324,7 +324,7 @@ static ngx_int_t ngx_select_process_events(ngx_cycle_t *cycle)
"select event: fd:%d wr:%d", c->fd, ev->write);
}
-#if !(WIN32)
+#if !(NGX_WIN32)
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"max_fd: %d", max_fd);
#endif
@@ -348,9 +348,9 @@ static ngx_int_t ngx_select_process_events(ngx_cycle_t *cycle)
work_write_fd_set = master_write_fd_set;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "select read fd_set: %08X", *(int *) &work_read_fd_set);
+ "select read fd_set: %08Xd", *(int *) &work_read_fd_set);
-#if (WIN32)
+#if (NGX_WIN32)
ready = select(0, &work_read_fd_set, &work_write_fd_set, NULL, tp);
#else
ready = select(max_fd + 1, &work_read_fd_set, &work_write_fd_set, NULL, tp);
@@ -433,7 +433,7 @@ static ngx_int_t ngx_select_process_events(ngx_cycle_t *cycle)
"select ready %d", ready);
if (err) {
-#if (WIN32)
+#if (NGX_WIN32)
ngx_log_error(NGX_LOG_ALERT, cycle->log, err, "select() failed");
#else
ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT,
@@ -534,7 +534,7 @@ static ngx_int_t ngx_select_process_events(ngx_cycle_t *cycle)
for ( ;; ) {
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "accept event " PTR_FMT, ev);
+ "accept event %p", ev);
if (ev == NULL) {
break;
@@ -597,7 +597,7 @@ static char *ngx_select_init_conf(ngx_cycle_t *cycle, void *conf)
/* disable warning: the default FD_SETSIZE is 1024U in FreeBSD 5.x */
-#if !(WIN32)
+#if !(NGX_WIN32)
if ((unsigned) ecf->connections > FD_SETSIZE) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
"the maximum number of files "
@@ -606,7 +606,7 @@ static char *ngx_select_init_conf(ngx_cycle_t *cycle, void *conf)
}
#endif
-#if (NGX_THREADS)
+#if (NGX_THREADS) && !(NGX_WIN32)
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
"select() is not supported in the threaded mode");
return NGX_CONF_ERROR;
diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c
index f006c6ba5..563cf4213 100644
--- a/src/event/ngx_event.c
+++ b/src/event/ngx_event.c
@@ -191,7 +191,7 @@ ngx_module_t ngx_event_core_module = {
static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle)
{
-#if !(WIN32)
+#if !(NGX_WIN32)
size_t size;
char *shared;
@@ -240,7 +240,7 @@ static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle)
#endif
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "counter: " PTR_FMT ", %d",
+ "counter: %p, %d",
ngx_connection_counter, *ngx_connection_counter);
#endif
@@ -259,7 +259,7 @@ static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle)
ngx_core_conf_t *ccf;
ngx_event_conf_t *ecf;
ngx_event_module_t *module;
-#if (WIN32)
+#if (NGX_WIN32)
ngx_iocp_conf_t *iocpcf;
#endif
@@ -352,7 +352,7 @@ static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle)
fd = s[i].fd;
-#if (WIN32)
+#if (NGX_WIN32)
/*
* Winsock assignes a socket number divisible by 4
* so to find a connection we divide a socket number by 4.
@@ -412,10 +412,10 @@ static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle)
}
}
-#if (WIN32)
+#if (NGX_WIN32)
if (ngx_event_flags & NGX_USE_IOCP_EVENT) {
- rev->event_handler = &ngx_event_acceptex;
+ rev->event_handler = ngx_event_acceptex;
if (ngx_add_event(rev, 0, NGX_IOCP_ACCEPT) == NGX_ERROR) {
return NGX_ERROR;
@@ -429,7 +429,8 @@ static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle)
}
} else {
- rev->event_handler = &ngx_event_accept;
+ rev->event_handler = ngx_event_accept;
+
if (ngx_add_event(rev, NGX_READ_EVENT, 0) == NGX_ERROR) {
return NGX_ERROR;
}
@@ -437,7 +438,7 @@ static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle)
#else
- rev->event_handler = &ngx_event_accept;
+ rev->event_handler = ngx_event_accept;
if (ngx_accept_mutex) {
continue;
@@ -580,7 +581,7 @@ static char *ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd,
ecf->connections = ngx_atoi(value[1].data, value[1].len);
if (ecf->connections == (ngx_uint_t) NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid number \"%s\"", value[1].data);
+ "invalid number \"%V\"", &value[1]);
return NGX_CONF_ERROR;
}
@@ -631,12 +632,12 @@ static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"when the server runs without a master process "
- "the \"%s\" event type must be the same as "
+ "the \"%V\" event type must be the same as "
"in previous configuration - \"%s\" "
"and it can not be changed on the fly, "
"to change it you need to stop server "
"and start it again",
- value[1].data, old_ecf->name);
+ &value[1], old_ecf->name);
return NGX_CONF_ERROR;
}
@@ -647,7 +648,7 @@ static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid event type \"%s\"", value[1].data);
+ "invalid event type \"%V\"", &value[1]);
return NGX_CONF_ERROR;
}
@@ -681,7 +682,7 @@ static char *ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd,
if (h == NULL || h->h_addr_list[0] == NULL) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "host %s not found", value[1].data);
+ "host \"%s\" not found", value[1].data);
return NGX_CONF_ERROR;
}
@@ -755,7 +756,7 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
#elif (HAVE_SELECT)
-#if (WIN32)
+#if (NGX_WIN32)
ngx_conf_init_unsigned_value(ecf->connections, DEFAULT_CONNECTIONS);
#else
ngx_conf_init_unsigned_value(ecf->connections,
diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h
index f341a14c6..191b492d6 100644
--- a/src/event/ngx_event.h
+++ b/src/event/ngx_event.h
@@ -81,7 +81,7 @@ struct ngx_event_s {
unsigned posted_ready:1;
#endif
-#if (WIN32)
+#if (NGX_WIN32)
/* setsockopt(SO_UPDATE_ACCEPT_CONTEXT) was succesfull */
unsigned accept_context_updated:1;
#endif
@@ -473,7 +473,7 @@ ngx_int_t ngx_disable_accept_events(ngx_cycle_t *cycle);
ngx_int_t ngx_enable_accept_events(ngx_cycle_t *cycle);
-#if (WIN32)
+#if (NGX_WIN32)
void ngx_event_acceptex(ngx_event_t *ev);
int ngx_event_post_acceptex(ngx_listening_t *ls, int n);
#endif
@@ -490,7 +490,7 @@ ngx_int_t ngx_send_lowat(ngx_connection_t *c, size_t lowat);
#include <ngx_event_posted.h>
#include <ngx_event_busy_lock.h>
-#if (WIN32)
+#if (NGX_WIN32)
#include <ngx_iocp_module.h>
#endif
diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c
index 9ae5ccd11..085a65eb4 100644
--- a/src/event/ngx_event_accept.c
+++ b/src/event/ngx_event_accept.c
@@ -11,13 +11,13 @@
typedef struct {
- int flag;
- u_char *name;
+ int flag;
+ ngx_str_t *name;
} ngx_accept_log_ctx_t;
static void ngx_close_accepted_socket(ngx_socket_t s, ngx_log_t *log);
-static size_t ngx_accept_log_error(void *data, char *buf, size_t len);
+static u_char *ngx_accept_log_error(void *data, u_char *buf, size_t len);
void ngx_event_accept(ngx_event_t *ev)
@@ -46,8 +46,8 @@ void ngx_event_accept(ngx_event_t *ev)
ls = ev->data;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
- "accept on %s, ready: %d",
- ls->listening->addr_text.data, ev->available);
+ "accept on %V, ready: %d",
+ &ls->listening->addr_text, ev->available);
ev->ready = 0;
accepted = 0;
@@ -88,7 +88,7 @@ void ngx_event_accept(ngx_event_t *ev)
/* -1 disables the connection number logging */
ctx->flag = -1;
- ctx->name = ls->listening->addr_text.data;
+ ctx->name = &ls->listening->addr_text;
log->data = ctx;
log->handler = ngx_accept_log_error;
@@ -114,8 +114,7 @@ void ngx_event_accept(ngx_event_t *ev)
}
ngx_log_error(NGX_LOG_ALERT, ev->log, err,
- "accept() on %s failed",
- ls->listening->addr_text.data);
+ "accept() on %V failed", &ls->listening->addr_text);
if (err == NGX_ECONNABORTED) {
if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
@@ -144,10 +143,10 @@ void ngx_event_accept(ngx_event_t *ev)
if ((ngx_uint_t) s >= ecf->connections) {
ngx_log_error(NGX_LOG_ALERT, ev->log, 0,
- "accept() on %s returned socket #%d while "
+ "accept() on %V returned socket #%d while "
"only %d connections was configured, "
"closing the connection",
- ls->listening->addr_text.data, s, ecf->connections);
+ &ls->listening->addr_text, s, ecf->connections);
ngx_close_accepted_socket(s, log);
ngx_destroy_pool(pool);
@@ -185,7 +184,7 @@ void ngx_event_accept(ngx_event_t *ev)
}
}
-#if (WIN32)
+#if (NGX_WIN32)
/*
* Winsock assignes a socket number divisible by 4
* so to find a connection we divide a socket number by 4.
@@ -193,9 +192,9 @@ void ngx_event_accept(ngx_event_t *ev)
if (s % 4) {
ngx_log_error(NGX_LOG_EMERG, ev->log, 0,
- "accept() on %s returned socket #%d, "
+ "accept() on %V returned socket #%d, "
"not divisible by 4",
- ls->listening->addr_text.data, s);
+ &ls->listening->addr_text, s);
exit(1);
}
@@ -467,9 +466,9 @@ static void ngx_close_accepted_socket(ngx_socket_t s, ngx_log_t *log)
}
-static size_t ngx_accept_log_error(void *data, char *buf, size_t len)
+static u_char *ngx_accept_log_error(void *data, u_char *buf, size_t len)
{
ngx_accept_log_ctx_t *ctx = data;
- return ngx_snprintf(buf, len, " while accept() on %s", ctx->name);
+ return ngx_snprintf(buf, len, " while accept() on %V", ctx->name);
}
diff --git a/src/event/ngx_event_acceptex.c b/src/event/ngx_event_acceptex.c
index 9877b3b2e..486636b44 100644
--- a/src/event/ngx_event_acceptex.c
+++ b/src/event/ngx_event_acceptex.c
@@ -14,22 +14,24 @@ void ngx_event_acceptex(ngx_event_t *rev)
{
ngx_connection_t *c;
- c = (ngx_connection_t *) rev->data;
+ c = rev->data;
+
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "AcceptEx: %d", c->fd);
if (rev->ovlp.error) {
ngx_log_error(NGX_LOG_CRIT, c->log, rev->ovlp.error,
- "AcceptEx() %s failed", c->listening->addr_text.data);
+ "AcceptEx() %V failed", &c->listening->addr_text);
return;
}
/* SO_UPDATE_ACCEPT_CONTEXT is required for shutdown() to work */
if (setsockopt(c->fd, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT,
- (char *)&c->listening->fd, sizeof(ngx_socket_t)) == -1)
+ (char *) &c->listening->fd, sizeof(ngx_socket_t)) == -1)
{
ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno,
- "setsockopt(SO_UPDATE_ACCEPT_CONTEXT) failed for %s",
- c->addr_text.data);
+ "setsockopt(SO_UPDATE_ACCEPT_CONTEXT) failed for %V",
+ &c->addr_text);
} else {
c->accept_context_updated = 1;
}
@@ -49,6 +51,23 @@ void ngx_event_acceptex(ngx_event_t *rev)
c->buffer = NULL;
}
+ if (c->listening->addr_ntop) {
+ c->addr_text.data = ngx_palloc(c->pool,
+ c->listening->addr_text_max_len);
+ if (c->addr_text.data == NULL) {
+ /* TODO: close socket */
+ return;
+ }
+
+ c->addr_text.len = ngx_sock_ntop(c->listening->family, c->sockaddr,
+ c->addr_text.data,
+ c->listening->addr_text_max_len);
+ if (c->addr_text.len == 0) {
+ /* TODO: close socket */
+ return;
+ }
+ }
+
ngx_event_post_acceptex(c->listening, 1);
c->number = ngx_atomic_inc(ngx_connection_counter);
@@ -73,10 +92,10 @@ int ngx_event_post_acceptex(ngx_listening_t *ls, int n)
/* TODO: look up reused sockets */
- s = ngx_socket(ls->family, ls->type, ls->protocol, ls->flags);
+ s = ngx_socket(ls->family, ls->type, ls->protocol);
- ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ls->log, 0,
- ngx_socket_n " s:%d fl:%d", s, ls->flags);
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ls->log, 0,
+ ngx_socket_n " s:%d", s);
if (s == -1) {
ngx_log_error(NGX_LOG_ALERT, ls->log, ngx_socket_errno,
@@ -107,49 +126,60 @@ int ngx_event_post_acceptex(ngx_listening_t *ls, int n)
ngx_memzero(rev, sizeof(ngx_event_t));
ngx_memzero(wev, sizeof(ngx_event_t));
- rev->index = wev->index = NGX_INVALID_INDEX;
+ c->listening = ls;
+
+ rev->index = NGX_INVALID_INDEX;
+ wev->index = NGX_INVALID_INDEX;
rev->ovlp.event = rev;
wev->ovlp.event = wev;
+ rev->event_handler = ngx_event_acceptex;
+
+ rev->data = c;
+ wev->data = c;
- rev->data = wev->data = c;
c->read = rev;
c->write = wev;
- c->listening = ls;
c->fd = s;
-
- c->ctx = ls->ctx;
- c->servers = ls->servers;
-
c->unexpected_eof = 1;
- wev->write = 1;
- rev->event_handler = ngx_event_acceptex;
rev->ready = 1;
+ wev->write = 1;
wev->ready = 1;
- ngx_test_null(c->pool,
- ngx_create_pool(ls->pool_size, ls->log),
- NGX_ERROR);
+ c->ctx = ls->ctx;
+ c->servers = ls->servers;
+
+ c->recv = ngx_recv;
+ c->send_chain = ngx_send_chain;
+
+ if (!(c->pool = ngx_create_pool(ls->pool_size, ls->log))) {
+ return NGX_ERROR;
+ }
- ngx_test_null(c->buffer,
- ngx_create_temp_buf(c->pool,
- ls->post_accept_buffer_size
- + 2 * (c->listening->socklen + 16)),
- NGX_ERROR);
+ c->buffer = ngx_create_temp_buf(c->pool,
+ ls->post_accept_buffer_size
+ + 2 * (c->listening->socklen + 16));
+ if (c->buffer == NULL) {
+ return NGX_ERROR;
+ }
- ngx_test_null(c->local_sockaddr, ngx_palloc(c->pool, ls->socklen),
- NGX_ERROR);
+ if (!(c->local_sockaddr = ngx_palloc(c->pool, ls->socklen))) {
+ return NGX_ERROR;
+ }
- ngx_test_null(c->sockaddr, ngx_palloc(c->pool, ls->socklen),
- NGX_ERROR);
+ if (!(c->sockaddr = ngx_palloc(c->pool, ls->socklen))) {
+ return NGX_ERROR;
+ }
- ngx_test_null(c->log, ngx_palloc(c->pool, sizeof(ngx_log_t)),
- NGX_ERROR);
+ if (!(c->log = ngx_palloc(c->pool, sizeof(ngx_log_t)))) {
+ return NGX_ERROR;
+ }
ngx_memcpy(c->log, ls->log, sizeof(ngx_log_t));
- c->read->log = c->write->log = c->log;
+ c->read->log = c->log;
+ c->write->log = c->log;
if (ngx_add_event(rev, 0, NGX_IOCP_IO) == NGX_ERROR) {
return NGX_ERROR;
diff --git a/src/event/ngx_event_connect.c b/src/event/ngx_event_connect.c
index b41eca771..c06896895 100644
--- a/src/event/ngx_event_connect.c
+++ b/src/event/ngx_event_connect.c
@@ -13,7 +13,7 @@
/* AF_INET only */
-int ngx_event_connect_peer(ngx_peer_connection_t *pc)
+ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc)
{
int rc;
ngx_uint_t instance;
@@ -107,7 +107,7 @@ int ngx_event_connect_peer(ngx_peer_connection_t *pc)
/* ngx_unlock_mutex(pc->peers->mutex); */
- s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0);
+ s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
if (s == -1) {
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
@@ -165,7 +165,7 @@ int ngx_event_connect_peer(ngx_peer_connection_t *pc)
return NGX_ERROR;
}
-#if (WIN32)
+#if (NGX_WIN32)
/*
* Winsock assignes a socket number divisible by 4
* so to find a connection we divide a socket number by 4.
@@ -261,7 +261,7 @@ int ngx_event_connect_peer(ngx_peer_connection_t *pc)
addr.sin_addr.s_addr = peer->addr;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pc->log, 0,
- "connect to %s, #%d", peer->addr_port_text.data, c->number);
+ "connect to %V, #%d", &peer->addr_port_text, c->number);
rc = connect(s, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));
diff --git a/src/event/ngx_event_connect.h b/src/event/ngx_event_connect.h
index 345c2f994..04086941b 100644
--- a/src/event/ngx_event_connect.h
+++ b/src/event/ngx_event_connect.h
@@ -60,7 +60,7 @@ typedef struct {
} ngx_peer_connection_t;
-int ngx_event_connect_peer(ngx_peer_connection_t *pc);
+ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc);
void ngx_event_connect_peer_failed(ngx_peer_connection_t *pc);
diff --git a/src/event/ngx_event_connectex.c b/src/event/ngx_event_connectex.c
index f3ad2f578..30ccf980c 100644
--- a/src/event/ngx_event_connectex.c
+++ b/src/event/ngx_event_connectex.c
@@ -199,7 +199,7 @@ void ngx_iocp_wait_events(int main)
ngx_log_error(NGX_LOG_ALERT, c[n].log, 0,
"WSAWaitForMultipleEvents() "
- "returned unexpected network event %lu",
+ "returned unexpected network event %ul",
ne.lNetworkEvents);
}
}
diff --git a/src/event/ngx_event_mutex.c b/src/event/ngx_event_mutex.c
index ab4e6abc3..2335e5baf 100644
--- a/src/event/ngx_event_mutex.c
+++ b/src/event/ngx_event_mutex.c
@@ -13,7 +13,7 @@ ngx_int_t ngx_event_mutex_timedlock(ngx_event_mutex_t *m, ngx_msec_t timer,
ngx_event_t *ev)
{
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
- "lock event mutex " PTR_FMT " lock:%X", m, m->lock);
+ "lock event mutex %p lock:%XD", m, m->lock);
if (m->lock) {
@@ -48,13 +48,12 @@ ngx_int_t ngx_event_mutex_unlock(ngx_event_mutex_t *m, ngx_log_t *log)
if (m->lock == 0) {
ngx_log_error(NGX_LOG_ALERT, log, 0,
- "tring to unlock the free event mutex " PTR_FMT, m);
+ "tring to unlock the free event mutex %p", m);
return NGX_ERROR;
}
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0,
- "unlock event mutex " PTR_FMT ", next event: " PTR_FMT,
- m, m->events);
+ "unlock event mutex %p, next event: %p", m, m->events);
m->lock = 0;
diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
index 7a7038d4f..b5c5b7256 100644
--- a/src/event/ngx_event_openssl.c
+++ b/src/event/ngx_event_openssl.c
@@ -73,7 +73,7 @@ ngx_int_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size)
}
if (!SSL_is_init_finished(c->ssl->ssl)) {
- handshake = "in SSL handshake";
+ handshake = " in SSL handshake";
} else {
handshake = "";
@@ -269,7 +269,7 @@ static ngx_int_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size)
if (sslerr == SSL_ERROR_WANT_READ) {
if (!SSL_is_init_finished(c->ssl->ssl)) {
- handshake = "in SSL handshake";
+ handshake = " in SSL handshake";
} else {
handshake = "";
@@ -310,6 +310,9 @@ ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c)
}
again = 0;
+#if (NGX_SUPPRESS_WARN)
+ sslerr = 0;
+#endif
for ( ;; ) {
n = SSL_shutdown(c->ssl->ssl);
@@ -366,23 +369,18 @@ ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c)
void ngx_ssl_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
char *fmt, ...)
{
- int len;
- char errstr[NGX_MAX_CONF_ERRSTR];
- va_list args;
+ u_char errstr[NGX_MAX_CONF_ERRSTR], *p, *last;
+ va_list args;
+
+ last = errstr + NGX_MAX_CONF_ERRSTR;
va_start(args, fmt);
- len = ngx_vsnprintf(errstr, sizeof(errstr) - 1, fmt, args);
+ p = ngx_vsnprintf(errstr, sizeof(errstr) - 1, fmt, args);
va_end(args);
- errstr[len++] = ' ';
- errstr[len++] = '(';
- errstr[len++] = 'S';
- errstr[len++] = 'S';
- errstr[len++] = 'L';
- errstr[len++] = ':';
- errstr[len++] = ' ';
+ p = ngx_cpystrn(p, " (SSL: ", last - p);
- ERR_error_string_n(ERR_get_error(), errstr + len, sizeof(errstr) - len - 1);
+ ERR_error_string_n(ERR_get_error(), (char *) p, last - p);
ngx_log_error(level, log, err, "%s)", errstr);
}
diff --git a/src/event/ngx_event_pipe.c b/src/event/ngx_event_pipe.c
index 24bc4d346..273941908 100644
--- a/src/event/ngx_event_pipe.c
+++ b/src/event/ngx_event_pipe.c
@@ -79,7 +79,8 @@ ngx_int_t ngx_event_pipe(ngx_event_pipe_t *p, int do_write)
ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
{
- int n, rc, size;
+ ssize_t n, size;
+ ngx_int_t rc;
ngx_buf_t *b;
ngx_chain_t *chain, *cl, *tl;
@@ -109,7 +110,7 @@ ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
n = p->preread_size;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
- "pipe preread: %d", n);
+ "pipe preread: %z", n);
if (n) {
p->read = 1;
@@ -197,7 +198,7 @@ ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
rc = ngx_event_pipe_write_chain_to_temp_file(p);
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
- "pipe temp offset: %d", p->temp_file->offset);
+ "pipe temp offset: %O", p->temp_file->offset);
if (rc == NGX_AGAIN) {
if (ngx_event_flags & NGX_USE_LEVEL_EVENT
@@ -237,7 +238,7 @@ ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
n = ngx_recv_chain(p->upstream, chain);
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
- "pipe recv chain: %d", n);
+ "pipe recv chain: %z", n);
if (p->free_raw_bufs) {
chain->next = p->free_raw_bufs;
@@ -303,7 +304,7 @@ ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
for (cl = p->busy; cl; cl = cl->next) {
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0,
- "pipe buf busy " PTR_FMT ", pos " PTR_FMT ", size: %d",
+ "pipe buf busy %p, pos %p, size: %z",
cl->buf->start, cl->buf->pos,
cl->buf->last - cl->buf->pos);
}
@@ -311,9 +312,8 @@ ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
for (cl = p->out; cl; cl = cl->next) {
if (cl->buf->in_file && cl->buf->temporary) {
ngx_log_debug5(NGX_LOG_DEBUG_EVENT, p->log, 0,
- "pipe buf out shadow "
- PTR_FMT ", pos " PTR_FMT ", size: %d "
- "file: " OFF_T_FMT ", size: %d",
+ "pipe buf out shadow %p, pos %p, size: %z "
+ "file: %O, size: %z",
cl->buf->start, cl->buf->pos,
cl->buf->last - cl->buf->pos,
cl->buf->file_pos,
@@ -321,13 +321,12 @@ ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
} else if (cl->buf->in_file) {
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,
- "pipe buf out file " OFF_T_FMT ", size: %d",
+ "pipe buf out file %O, size: %z",
cl->buf->file_pos,
cl->buf->file_last - cl->buf->file_pos);
} else {
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0,
- "pipe buf out " PTR_FMT ", pos " PTR_FMT
- ", size: %d",
+ "pipe buf out %p, pos %p, size: %z",
cl->buf->start, cl->buf->pos,
cl->buf->last - cl->buf->pos);
}
@@ -335,14 +334,14 @@ ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
for (cl = p->in; cl; cl = cl->next) {
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0,
- "pipe buf in " PTR_FMT ", pos " PTR_FMT ", size: %d",
+ "pipe buf in %p, pos %p, size: %z",
cl->buf->start, cl->buf->pos,
cl->buf->last - cl->buf->pos);
}
for (cl = p->free_raw_bufs; cl; cl = cl->next) {
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0,
- "pipe buf free " PTR_FMT ", last " PTR_FMT ", size: %d",
+ "pipe buf free %p, last %p, size: %z",
cl->buf->start, cl->buf->last,
cl->buf->end - cl->buf->last);
}
@@ -443,7 +442,7 @@ ngx_int_t ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p)
}
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
- "pipe write busy: " SIZE_T_FMT, bsize);
+ "pipe write busy: %uz", bsize);
out = NULL;
ll = NULL;
@@ -482,7 +481,7 @@ ngx_int_t ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p)
}
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,
- "pipe write: out:" PTR_FMT ", f:%d", out, flush);
+ "pipe write: out:%p, f:%d", out, flush);
if (out == NULL && !flush) {
break;
@@ -553,13 +552,13 @@ static ngx_int_t ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p)
ll = NULL;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
- "pipe offset: %d", p->temp_file->offset);
+ "pipe offset: %O", p->temp_file->offset);
do {
bsize = cl->buf->last - cl->buf->pos;
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0,
- "pipe buf " PTR_FMT ", pos " PTR_FMT ", size: %d",
+ "pipe buf %p, pos %p, size: %z",
cl->buf->start, cl->buf->pos, bsize);
if ((size + bsize > p->temp_file_write_size)
@@ -574,7 +573,7 @@ static ngx_int_t ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p)
} while (cl);
- ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "size: %d", size);
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "size: %z", size);
if (cl) {
p->in = cl;
diff --git a/src/event/ngx_event_posted.c b/src/event/ngx_event_posted.c
index eb064f5ad..aed07faa3 100644
--- a/src/event/ngx_event_posted.c
+++ b/src/event/ngx_event_posted.c
@@ -25,7 +25,7 @@ void ngx_event_process_posted(ngx_cycle_t *cycle)
ev = (ngx_event_t *) ngx_posted_events;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "posted event " PTR_FMT, ev);
+ "posted event %p", ev);
if (ev == NULL) {
return;
@@ -38,7 +38,7 @@ void ngx_event_process_posted(ngx_cycle_t *cycle)
}
-#if (NGX_THREADS)
+#if (NGX_THREADS) && !(NGX_WIN32)
void ngx_wakeup_worker_thread(ngx_cycle_t *cycle)
{
@@ -87,7 +87,7 @@ ngx_int_t ngx_event_thread_process_posted(ngx_cycle_t *cycle)
for ( ;; ) {
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "posted event " PTR_FMT, ev);
+ "posted event %p", ev);
if (ev == NULL) {
return NGX_OK;
@@ -96,7 +96,7 @@ ngx_int_t ngx_event_thread_process_posted(ngx_cycle_t *cycle)
if (ngx_trylock(ev->lock) == 0) {
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "posted event " PTR_FMT " is busy", ev);
+ "posted event %p is busy", ev);
ev = ev->next;
continue;
@@ -105,8 +105,7 @@ ngx_int_t ngx_event_thread_process_posted(ngx_cycle_t *cycle)
if (ev->lock != ev->own_lock) {
if (*(ev->own_lock)) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
- "the own lock of the posted event "
- PTR_FMT " is busy", ev);
+ "the own lock of the posted event %p is busy", ev);
ngx_unlock(ev->lock);
ev = ev->next;
continue;
@@ -153,7 +152,7 @@ ngx_int_t ngx_event_thread_process_posted(ngx_cycle_t *cycle)
}
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "posted event " PTR_FMT " is done", ev);
+ "posted event %p is done", ev);
break;
}
diff --git a/src/event/ngx_event_posted.h b/src/event/ngx_event_posted.h
index 5e29edcf0..86100af94 100644
--- a/src/event/ngx_event_posted.h
+++ b/src/event/ngx_event_posted.h
@@ -22,10 +22,10 @@
ev->next->prev = &ev->next; \
} \
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, \
- "post event " PTR_FMT, ev); \
+ "post event %p", ev); \
} else { \
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, \
- "update posted event " PTR_FMT, ev); \
+ "update posted event %p", ev); \
}
#define ngx_delete_posted_event(ev) \
@@ -35,7 +35,7 @@
} \
ev->prev = NULL; \
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, \
- "delete posted event " PTR_FMT, ev);
+ "delete posted event %p", ev);
diff --git a/src/event/ngx_event_timer.c b/src/event/ngx_event_timer.c
index a09f07f73..c1ca12414 100644
--- a/src/event/ngx_event_timer.c
+++ b/src/event/ngx_event_timer.c
@@ -110,14 +110,13 @@ void ngx_event_expire_timers(ngx_msec_t timer)
*/
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0,
- "event " PTR_FMT " is busy in expire timers",
- ev);
+ "event %p is busy in expire timers", ev);
break;
}
#endif
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
- "event timer del: %d: %d",
+ "event timer del: %d: %i",
ngx_event_ident(ev->data), ev->rbtree_key);
ngx_rbtree_delete((ngx_rbtree_t **) &ngx_event_timer_rbtree,
diff --git a/src/event/ngx_event_timer.h b/src/event/ngx_event_timer.h
index f40e57234..9d6319a34 100644
--- a/src/event/ngx_event_timer.h
+++ b/src/event/ngx_event_timer.h
@@ -89,7 +89,7 @@ ngx_inline static void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer)
if (abs(key - ev->rbtree_key) < 100 / NGX_TIMER_RESOLUTION) {
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0,
- "event timer: %d, old: %d, new: %d",
+ "event timer: %d, old: %i, new: %i",
ngx_event_ident(ev->data), ev->rbtree_key, key);
return;
}
@@ -100,7 +100,7 @@ ngx_inline static void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer)
ev->rbtree_key = key;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
- "event timer add: %d: %d",
+ "event timer add: %d: %i",
ngx_event_ident(ev->data), ev->rbtree_key);
if (ngx_mutex_lock(ngx_event_timer_mutex) == NGX_ERROR) {
diff --git a/src/http/modules/ngx_http_access_handler.c b/src/http/modules/ngx_http_access_handler.c
index 3a323b149..9e5c43c4d 100644
--- a/src/http/modules/ngx_http_access_handler.c
+++ b/src/http/modules/ngx_http_access_handler.c
@@ -97,8 +97,9 @@ static ngx_int_t ngx_http_access_handler(ngx_http_request_t *r)
rule = alcf->rules->elts;
for (i = 0; i < alcf->rules->nelts; i++) {
-ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "%08X %08X %08X",
- addr_in->sin_addr.s_addr, rule[i].mask, rule[i].addr);
+ ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "%08XD %08XD %08XD",
+ addr_in->sin_addr.s_addr, rule[i].mask, rule[i].addr);
if ((addr_in->sin_addr.s_addr & rule[i].mask) == rule[i].addr) {
if (rule[i].deny) {
@@ -157,8 +158,8 @@ static char *ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd,
}
if (ngx_ptocidr(&value[1], &in_cidr) == NGX_ERROR) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid paramter \"%s\"",
- value[1].data);
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid paramter \"%V\"",
+ &value[1]);
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_autoindex_handler.c b/src/http/modules/ngx_http_autoindex_handler.c
index 99aa35d88..c78d4e616 100644
--- a/src/http/modules/ngx_http_autoindex_handler.c
+++ b/src/http/modules/ngx_http_autoindex_handler.c
@@ -24,6 +24,7 @@ typedef struct {
typedef struct {
ngx_str_t name;
+ ngx_uint_t escape;
ngx_uint_t dir;
time_t mtime;
off_t size;
@@ -269,10 +270,13 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r)
}
entry->name.len = len;
+ entry->escape = 2 * ngx_escape_uri(NULL, ngx_de_name(&dir), len,
+ NGX_ESCAPE_HTML);
- if (!(entry->name.data = ngx_palloc(pool, len + 1))) {
+ if (!(entry->name.data = ngx_palloc(pool, len + entry->escape + 1))) {
return ngx_http_autoindex_error(r, &dir, dname.data);
}
+
ngx_cpystrn(entry->name.data, ngx_de_name(&dir), len + 1);
entry->dir = ngx_de_is_dir(&dir);
@@ -298,7 +302,7 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r)
for (i = 0; i < entries.nelts; i++) {
len += sizeof("<a href=\"") - 1
+ 1 /* 1 is for "/" */
- + entry[i].name.len
+ + entry[i].name.len + entry[i].escape
+ sizeof("\">") - 1
+ NGX_HTTP_AUTOINDEX_NAME_LEN
+ sizeof("</a>") - 1
@@ -329,7 +333,17 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r)
for (i = 0; i < entries.nelts; i++) {
b->last = ngx_cpymem(b->last, "<a href=\"", sizeof("<a href=\"") - 1);
- b->last = ngx_cpymem(b->last, entry[i].name.data, entry[i].name.len);
+
+ if (entry[i].escape) {
+ ngx_escape_uri(b->last, entry[i].name.data, entry[i].name.len,
+ NGX_ESCAPE_HTML);
+
+ b->last += entry[i].name.len + entry[i].escape;
+
+ } else {
+ b->last = ngx_cpymem(b->last, entry[i].name.data,
+ entry[i].name.len);
+ }
if (entry[i].dir) {
*b->last++ = '/';
@@ -375,7 +389,7 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r)
} else {
length = entry[i].size;
- if (length > 1024 * 1024 * 1024) {
+ if (length > 1024 * 1024 * 1024 - 1) {
size = (ngx_int_t) (length / (1024 * 1024 * 1024));
if ((length % (1024 * 1024 * 1024))
> (1024 * 1024 * 1024 / 2 - 1))
@@ -384,7 +398,7 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r)
}
scale = 'G';
- } else if (length > 1024 * 1024) {
+ } else if (length > 1024 * 1024 - 1) {
size = (ngx_int_t) (length / (1024 * 1024));
if ((length % (1024 * 1024)) > (1024 * 1024 / 2 - 1)) {
size++;
diff --git a/src/http/modules/ngx_http_charset_filter.c b/src/http/modules/ngx_http_charset_filter.c
index f2e85e530..cf9d3d2be 100644
--- a/src/http/modules/ngx_http_charset_filter.c
+++ b/src/http/modules/ngx_http_charset_filter.c
@@ -125,7 +125,7 @@ ngx_module_t ngx_http_charset_filter_module = {
ngx_http_charset_filter_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_charset_filter_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
@@ -287,8 +287,7 @@ static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd,
if (src == dst) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"\"charset_map\" between the same charsets "
- "\"%s\" and \"%s\"",
- value[1].data, value[2].data);
+ "\"%V\" and \"%V\"", &value[1], &value[2]);
return NGX_CONF_ERROR;
}
@@ -299,8 +298,7 @@ static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd,
{
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"duplicate \"charset_map\" between "
- "\"%s\" and \"%s\"",
- value[1].data, value[2].data);
+ "\"%V\" and \"%V\"", &value[1], &value[2]);
return NGX_CONF_ERROR;
}
}
@@ -357,14 +355,14 @@ static char *ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
src = ngx_hextoi(value[0].data, value[0].len);
if (src == NGX_ERROR || src > 255) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid value \"%s\"", value[0].data);
+ "invalid value \"%V\"", &value[0]);
return NGX_CONF_ERROR;
}
dst = ngx_hextoi(value[1].data, value[1].len);
if (dst == NGX_ERROR || dst > 255) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid value \"%s\"", value[1].data);
+ "invalid value \"%V\"", &value[1]);
return NGX_CONF_ERROR;
}
@@ -525,8 +523,8 @@ static char *ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf)
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
" no \"charset_map\" between the charsets "
- "\"%s\" and \"%s\"",
- charset[i].name.data, charset[n].name.data);
+ "\"%V\" and \"%V\"",
+ &charset[i].name, &charset[n].name);
return NGX_CONF_ERROR;
}
}
diff --git a/src/http/modules/ngx_http_chunked_filter.c b/src/http/modules/ngx_http_chunked_filter.c
index 7881248cc..929a7ed2c 100644
--- a/src/http/modules/ngx_http_chunked_filter.c
+++ b/src/http/modules/ngx_http_chunked_filter.c
@@ -32,7 +32,7 @@ ngx_module_t ngx_http_chunked_filter_module = {
NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_chunked_filter_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
@@ -84,7 +84,11 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
size += ngx_buf_size(cl->buf);
if (cl->buf->flush || ngx_buf_in_memory(cl->buf) || cl->buf->in_file) {
- ngx_test_null(tl, ngx_alloc_chain_link(r->pool), NGX_ERROR);
+
+ if (!(tl = ngx_alloc_chain_link(r->pool))) {
+ return NGX_ERROR;
+ }
+
tl->buf = cl->buf;
*ll = tl;
ll = &tl->next;
@@ -102,30 +106,22 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
return NGX_ERROR;
}
- if (!(chunk = ngx_palloc(r->pool, 11))) {
+ if (!(chunk = ngx_palloc(r->pool, sizeof("00000000" CRLF) - 1))) {
return NGX_ERROR;
}
b->temporary = 1;
b->pos = chunk;
- b->last = ngx_sprintf(chunk, "%uxS" CRLF, size);
-
- out.buf = b;
-#if 0
- ngx_test_null(chunk, ngx_palloc(r->pool, 11), NGX_ERROR);
- len = ngx_snprintf((char *) chunk, 11, SIZE_T_X_FMT CRLF, size);
-
- ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR);
- b->temporary = 1;
- b->pos = chunk;
- b->last = chunk + len;
+ b->last = ngx_sprintf(chunk, "%xz" CRLF, size);
out.buf = b;
-#endif
}
if (cl->buf->last_buf) {
- ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR);
+ if (!(b = ngx_calloc_buf(r->pool))) {
+ return NGX_ERROR;
+ }
+
b->memory = 1;
b->last_buf = 1;
b->pos = (u_char *) CRLF "0" CRLF CRLF;
@@ -147,7 +143,10 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
return ngx_http_next_body_filter(r, out.next);
}
- ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR);
+ if (!(b = ngx_calloc_buf(r->pool))) {
+ return NGX_ERROR;
+ }
+
b->memory = 1;
b->pos = (u_char *) CRLF;
b->last = b->pos + 2;
diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c
index bb3a1f0c6..f8980af52 100644
--- a/src/http/modules/ngx_http_gzip_filter.c
+++ b/src/http/modules/ngx_http_gzip_filter.c
@@ -80,7 +80,7 @@ static ngx_int_t ngx_http_gzip_proxied(ngx_http_request_t *r,
static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items,
u_int size);
static void ngx_http_gzip_filter_free(void *opaque, void *address);
-ngx_inline static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx);
+static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx);
static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf,
uintptr_t data);
@@ -507,7 +507,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
b->pos = gzheader;
b->last = b->pos + 10;
- ngx_alloc_link_and_set_buf(cl, b, r->pool, ngx_http_gzip_error(ctx));
+ if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ return ngx_http_gzip_error(ctx);
+ }
+ cl->buf = b;
+ cl->next = NULL;
ctx->out = cl;
ctx->last_out = &cl->next;
@@ -534,7 +538,7 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
&& !ctx->redo)
{
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "gzip in: " PTR_FMT, ctx->in);
+ "gzip in: %p", ctx->in);
if (ctx->in == NULL) {
break;
@@ -547,7 +551,7 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
ctx->zstream.avail_in = ctx->in_buf->last - ctx->in_buf->pos;
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "gzip in_buf:" PTR_FMT " ni:" PTR_FMT " ai:%d",
+ "gzip in_buf:%p ni:%p ai:%ud",
ctx->in_buf,
ctx->zstream.next_in, ctx->zstream.avail_in);
@@ -608,10 +612,10 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
}
ngx_log_debug6(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "deflate in: ni:%X no:%X ai:%d ao:%d fl:%d redo:%d",
- ctx->zstream.next_in, ctx->zstream.next_out,
- ctx->zstream.avail_in, ctx->zstream.avail_out,
- ctx->flush, ctx->redo);
+ "deflate in: ni:%p no:%p ai:%ud ao:%ud fl:%d redo:%d",
+ ctx->zstream.next_in, ctx->zstream.next_out,
+ ctx->zstream.avail_in, ctx->zstream.avail_out,
+ ctx->flush, ctx->redo);
rc = deflate(&ctx->zstream, ctx->flush);
@@ -622,13 +626,13 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
}
ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "deflate out: ni:%X no:%X ai:%d ao:%d rc:%d",
+ "deflate out: ni:%p no:%p ai:%ud ao:%ud rc:%d",
ctx->zstream.next_in, ctx->zstream.next_out,
ctx->zstream.avail_in, ctx->zstream.avail_out,
rc);
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "gzip in_buf:" PTR_FMT " pos:" PTR_FMT,
+ "gzip in_buf:%p pos:%p",
ctx->in_buf, ctx->in_buf->pos);
@@ -646,8 +650,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
/* zlib wants to output some more gzipped data */
- ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool,
- ngx_http_gzip_error(ctx));
+ if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ return ngx_http_gzip_error(ctx);
+ }
+ cl->buf = ctx->out_buf;
+ cl->next = NULL;
*ctx->last_out = cl;
ctx->last_out = &cl->next;
@@ -663,8 +670,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
ctx->out_buf->flush = 0;
ctx->flush = Z_NO_FLUSH;
- ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool,
- ngx_http_gzip_error(ctx));
+ if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ return ngx_http_gzip_error(ctx);
+ }
+ cl->buf = ctx->out_buf;
+ cl->next = NULL;
*ctx->last_out = cl;
ctx->last_out = &cl->next;
@@ -686,8 +696,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
ngx_pfree(r->pool, ctx->preallocated);
- ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool,
- ngx_http_gzip_error(ctx));
+ if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ return ngx_http_gzip_error(ctx);
+ }
+ cl->buf = ctx->out_buf;
+ cl->next = NULL;
*ctx->last_out = cl;
ctx->last_out = &cl->next;
@@ -703,8 +716,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
b->last_buf = 1;
- ngx_alloc_link_and_set_buf(cl, b, r->pool,
- ngx_http_gzip_error(ctx));
+ if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ return ngx_http_gzip_error(ctx);
+ }
+ cl->buf = b;
+ cl->next = NULL;
*ctx->last_out = cl;
ctx->last_out = &cl->next;
trailer = (struct gztrailer *) b->pos;
@@ -735,8 +751,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
}
if (conf->no_buffer && ctx->in == NULL) {
- ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool,
- ngx_http_gzip_error(ctx));
+ if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ return ngx_http_gzip_error(ctx);
+ }
+ cl->buf = ctx->out_buf;
+ cl->next = NULL;
*ctx->last_out = cl;
ctx->last_out = &cl->next;
@@ -782,10 +801,12 @@ static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size)
ngx_uint_t alloc;
alloc = items * size;
+
if (alloc % 512 != 0) {
/*
- * the zlib deflate_state allocation, it takes about 6K, we allocate 8K
+ * The zlib deflate_state allocation, it takes about 6K,
+ * we allocate 8K. Other allocations are divisible by 512.
*/
alloc = (alloc + ngx_pagesize - 1) & ~(ngx_pagesize - 1);
@@ -797,14 +818,14 @@ static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size)
ctx->allocated -= alloc;
ngx_log_debug4(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0,
- "gzip alloc: n:%d s:%d a:%d p:" PTR_FMT,
+ "gzip alloc: n:%ud s:%ud a:%ud p:%p",
items, size, alloc, p);
return p;
}
ngx_log_error(NGX_LOG_ALERT, ctx->request->connection->log, 0,
- "gzip filter failed to use preallocated memory: %d of %d",
+ "gzip filter failed to use preallocated memory: %ud of %ud",
items * size, ctx->allocated);
p = ngx_palloc(ctx->request->pool, items * size);
@@ -819,7 +840,7 @@ static void ngx_http_gzip_filter_free(void *opaque, void *address)
ngx_http_gzip_ctx_t *ctx = opaque;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0,
- "gzip free: %X", address);
+ "gzip free: %p", address);
#endif
}
@@ -837,8 +858,6 @@ static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf,
return buf + 1;
}
- /* we prefer do not use the FPU */
-
zint = (ngx_uint_t) (ctx->zin / ctx->zout);
zfrac = (ngx_uint_t) ((ctx->zin * 100 / ctx->zout) % 100);
@@ -855,16 +874,10 @@ static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf,
}
return ngx_sprintf(buf, "%ui.%02ui", zint, zfrac);
-
-#if 0
- return buf + ngx_snprintf((char *) buf, NGX_INT32_LEN + 4,
- "%" NGX_UINT_T_FMT ".%02" NGX_UINT_T_FMT,
- zint, zfrac);
-#endif
}
-ngx_inline static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx)
+static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx)
{
deflateEnd(&ctx->zstream);
diff --git a/src/http/modules/ngx_http_headers_filter.c b/src/http/modules/ngx_http_headers_filter.c
index faf81920a..e86f6ae63 100644
--- a/src/http/modules/ngx_http_headers_filter.c
+++ b/src/http/modules/ngx_http_headers_filter.c
@@ -138,12 +138,6 @@ static ngx_int_t ngx_http_headers_filter(ngx_http_request_t *r)
conf->expires)
- cc->value.data;
-#if 0
- cc->value.len = ngx_snprintf((char *) cc->value.data,
- sizeof("max-age=") + TIME_T_LEN,
- "max-age=" TIME_T_FMT,
- conf->expires);
-#endif
}
}
}
diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c
index 60b6c0185..013f62b46 100644
--- a/src/http/modules/ngx_http_index_handler.c
+++ b/src/http/modules/ngx_http_index_handler.c
@@ -143,7 +143,7 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r)
&r->uri, &crc);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
- "http index cache get: " PTR_FMT, ctx->cache);
+ "http index cache get: %p", ctx->cache);
if (ctx->cache && !ctx->cache->expired) {
@@ -251,7 +251,7 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r)
err = ngx_errno;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, err,
- ngx_open_file_n " %s failed", name);
+ ngx_open_file_n " \"%s\" failed", name);
if (err == NGX_ENOTDIR) {
return ngx_http_index_error(r, ctx, err);
@@ -275,7 +275,7 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r)
}
ngx_log_error(NGX_LOG_ERR, log, err,
- ngx_open_file_n " %s failed", name);
+ ngx_open_file_n " \"%s\" failed", name);
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -331,7 +331,7 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r)
ctx->redirect.len--;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
- "http index cache alloc: " PTR_FMT, ctx->cache);
+ "http index cache alloc: %p", ctx->cache);
if (ctx->cache) {
ctx->cache->fd = NGX_INVALID_FILE;
@@ -373,7 +373,7 @@ static ngx_int_t ngx_http_index_test_dir(ngx_http_request_t *r,
}
ngx_log_error(NGX_LOG_CRIT, r->connection->log, err,
- ngx_file_info_n " %s failed", ctx->path.data);
+ ngx_file_info_n " \"%s\" failed", ctx->path.data);
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -502,17 +502,17 @@ static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd,
if (value[1].data[0] == '/' && ilcf->indices.nelts == 0) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "first index \"%s\" in \"%s\" directive "
+ "first index \"%V\" in \"%V\" directive "
"must not be absolute",
- value[1].data, cmd->name.data);
+ &value[1], &cmd->name);
return NGX_CONF_ERROR;
}
for (i = 1; i < cf->args->nelts; i++) {
if (value[i].len == 0) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "index \"%s\" in \"%s\" directive is invalid",
- value[1].data, cmd->name.data);
+ "index \"%V\" in \"%V\" directive is invalid",
+ &value[1], &cmd->name);
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_not_modified_filter.c b/src/http/modules/ngx_http_not_modified_filter.c
index 04d1fde6b..24ea58d90 100644
--- a/src/http/modules/ngx_http_not_modified_filter.c
+++ b/src/http/modules/ngx_http_not_modified_filter.c
@@ -33,7 +33,7 @@ ngx_module_t ngx_http_not_modified_filter_module = {
NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_not_modified_filter_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c
index 082fd3c4a..f96456cef 100644
--- a/src/http/modules/ngx_http_range_filter.c
+++ b/src/http/modules/ngx_http_range_filter.c
@@ -107,11 +107,13 @@ static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r)
{
- ngx_int_t rc;
- ngx_uint_t boundary, suffix, i;
u_char *p;
size_t len;
off_t start, end;
+ ngx_int_t rc;
+ uint32_t boundary;
+ ngx_uint_t suffix, i;
+ ngx_table_elt_t *content_range;
ngx_http_range_t *range;
ngx_http_range_filter_ctx_t *ctx;
@@ -141,8 +143,11 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r)
return ngx_http_next_header_filter(r);
}
- ngx_init_array(r->headers_out.ranges, r->pool, 5, sizeof(ngx_http_range_t),
- NGX_ERROR);
+ if (ngx_array_init(&r->headers_out.ranges, r->pool, 5,
+ sizeof(ngx_http_range_t)) == NGX_ERROR)
+ {
+ return NGX_ERROR;
+ }
rc = 0;
range = NULL;
@@ -180,8 +185,10 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r)
while (*p == ' ') { p++; }
if (*p == ',' || *p == '\0') {
- ngx_test_null(range, ngx_push_array(&r->headers_out.ranges),
- NGX_ERROR);
+ if (!(range = ngx_array_push(&r->headers_out.ranges))) {
+ return NGX_ERROR;
+ }
+
range->start = start;
range->end = r->headers_out.content_length_n;
@@ -223,7 +230,10 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r)
break;
}
- ngx_test_null(range, ngx_push_array(&r->headers_out.ranges), NGX_ERROR);
+ if (!(range = ngx_array_push(&r->headers_out.ranges))) {
+ return NGX_ERROR;
+ }
+
range->start = start;
if (end >= r->headers_out.content_length_n) {
@@ -249,29 +259,26 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r)
r->headers_out.status = rc;
r->headers_out.ranges.nelts = 0;
- r->headers_out.content_range = ngx_list_push(&r->headers_out.headers);
- if (r->headers_out.content_range == NULL) {
+ if (!(content_range = ngx_list_push(&r->headers_out.headers))) {
return NGX_ERROR;
}
- r->headers_out.content_range->key.len = sizeof("Content-Range") - 1;
- r->headers_out.content_range->key.data = (u_char *) "Content-Range";
+ r->headers_out.content_range = content_range;
- r->headers_out.content_range->value.data =
- ngx_palloc(r->pool, 8 + 20 + 1);
- if (r->headers_out.content_range->value.data == NULL) {
+ content_range->key.len = sizeof("Content-Range") - 1;
+ content_range->key.data = (u_char *) "Content-Range";
+
+ content_range->value.data =
+ ngx_palloc(r->pool, sizeof("bytes */") - 1 + NGX_OFF_T_LEN);
+
+ if (content_range->value.data == NULL) {
return NGX_ERROR;
}
- r->headers_out.content_range->value.len =
- ngx_sprintf(r->headers_out.content_range->value.data,
- "bytes */%O", r->headers_out.content_length_n)
- - r->headers_out.content_range->value.data;
-#if 0
- ngx_snprintf((char *) r->headers_out.content_range->value.data,
- 8 + 20 + 1, "bytes */" OFF_T_FMT,
- r->headers_out.content_length_n);
-#endif
+ content_range->value.len = ngx_sprintf(content_range->value.data,
+ "bytes */%O",
+ r->headers_out.content_length_n)
+ - content_range->value.data;
r->headers_out.content_length_n = -1;
if (r->headers_out.content_length) {
@@ -280,177 +287,135 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r)
}
return rc;
+ }
- } else {
- r->headers_out.status = NGX_HTTP_PARTIAL_CONTENT;
+ r->headers_out.status = NGX_HTTP_PARTIAL_CONTENT;
- if (r->headers_out.ranges.nelts == 1) {
+ if (r->headers_out.ranges.nelts == 1) {
- r->headers_out.content_range =
- ngx_list_push(&r->headers_out.headers);
- if (r->headers_out.content_range == NULL) {
- return NGX_ERROR;
- }
+ if (!(content_range = ngx_list_push(&r->headers_out.headers))) {
+ return NGX_ERROR;
+ }
- r->headers_out.content_range->key.len = sizeof("Content-Range") - 1;
- r->headers_out.content_range->key.data = (u_char *) "Content-Range";
+ r->headers_out.content_range = content_range;
- ngx_test_null(r->headers_out.content_range->value.data,
- ngx_palloc(r->pool, 6 + 20 + 1 + 20 + 1 + 20 + 1),
- NGX_ERROR);
+ content_range->key.len = sizeof("Content-Range") - 1;
+ content_range->key.data = (u_char *) "Content-Range";
- /* "Content-Range: bytes SSSS-EEEE/TTTT" header */
+ content_range->value.data =
+ ngx_palloc(r->pool, sizeof("bytes -/") - 1 + 3 * NGX_OFF_T_LEN);
+ if (content_range->value.data == NULL) {
+ return NGX_ERROR;
+ }
- r->headers_out.content_range->value.len =
- ngx_sprintf(r->headers_out.content_range->value.data,
- "bytes %O-%O/%O",
- range->start, range->end - 1,
- r->headers_out.content_length_n)
- - r->headers_out.content_range->value.data;
+ /* "Content-Range: bytes SSSS-EEEE/TTTT" header */
-#if 0
- ngx_snprintf((char *)
- r->headers_out.content_range->value.data,
- 6 + 20 + 1 + 20 + 1 + 20 + 1,
- "bytes " OFF_T_FMT "-" OFF_T_FMT "/" OFF_T_FMT,
- range->start, range->end - 1,
- r->headers_out.content_length_n);
-#endif
+ content_range->value.len = ngx_sprintf(content_range->value.data,
+ "bytes %O-%O/%O",
+ range->start, range->end - 1,
+ r->headers_out.content_length_n)
+ - content_range->value.data;
- r->headers_out.content_length_n = range->end - range->start;
+ r->headers_out.content_length_n = range->end - range->start;
- } else {
+ return ngx_http_next_header_filter(r);
+ }
-#if 0
- /* TODO: what if no content_type ?? */
- if (!(r->headers_out.content_type =
- ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
- {
- return NGX_ERROR;
- }
-#endif
+ /* TODO: what if no content_type ?? */
- ngx_http_create_ctx(r, ctx, ngx_http_range_body_filter_module,
- sizeof(ngx_http_range_filter_ctx_t), NGX_ERROR);
+ ngx_http_create_ctx(r, ctx, ngx_http_range_body_filter_module,
+ sizeof(ngx_http_range_filter_ctx_t), NGX_ERROR);
- len = 4 + 10 + 2 + 14 + r->headers_out.content_type->value.len
- + 2 + 21 + 1;
- if (r->headers_out.charset.len) {
- len += 10 + r->headers_out.charset.len;
- }
+ len = sizeof(CRLF "--0123456789" CRLF "Content-Type: ") - 1
+ + r->headers_out.content_type->value.len
+ + sizeof(CRLF "Content-Range: bytes ") - 1;
- ngx_test_null(ctx->boundary_header.data, ngx_palloc(r->pool, len),
- NGX_ERROR);
+ if (r->headers_out.charset.len) {
+ len += sizeof("; charset=") - 1 + r->headers_out.charset.len;
+ }
- boundary = ngx_next_temp_number(0);
+ if (!(ctx->boundary_header.data = ngx_palloc(r->pool, len))) {
+ return NGX_ERROR;
+ }
- /*
- * The boundary header of the range:
- * CRLF
- * "--0123456789" CRLF
- * "Content-Type: image/jpeg" CRLF
- * "Content-Range: bytes "
- */
+ boundary = ngx_next_temp_number(0);
- if (r->headers_out.charset.len) {
- ctx->boundary_header.len =
- ngx_sprintf(ctx->boundary_header.data,
- CRLF "--%010ui" CRLF
- "Content-Type: %s; charset=%s" CRLF
- "Content-Range: bytes ",
- boundary,
- r->headers_out.content_type->value.data,
- r->headers_out.charset.data)
- - ctx->boundary_header.data;
-#if 0
- ngx_snprintf((char *) ctx->boundary_header.data, len,
- CRLF "--%010" NGX_UINT_T_FMT CRLF
- "Content-Type: %s; charset=%s" CRLF
- "Content-Range: bytes ",
- boundary,
- r->headers_out.content_type->value.data,
- r->headers_out.charset.data);
-#endif
-
- r->headers_out.charset.len = 0;
-
- } else {
- ctx->boundary_header.len =
- ngx_sprintf(ctx->boundary_header.data,
- CRLF "--%010ui" CRLF
- "Content-Type: %s" CRLF
- "Content-Range: bytes ",
- boundary,
- r->headers_out.content_type->value.data)
- - ctx->boundary_header.data;
-
-#if 0
- ngx_snprintf((char *) ctx->boundary_header.data, len,
- CRLF "--%010" NGX_UINT_T_FMT CRLF
- "Content-Type: %s" CRLF
- "Content-Range: bytes ",
- boundary,
- r->headers_out.content_type->value.data);
-
-#endif
- }
+ /*
+ * The boundary header of the range:
+ * CRLF
+ * "--0123456789" CRLF
+ * "Content-Type: image/jpeg" CRLF
+ * "Content-Range: bytes "
+ */
- ngx_test_null(r->headers_out.content_type->value.data,
- ngx_palloc(r->pool, 31 + 10 + 1),
- NGX_ERROR);
-
- /* "Content-Type: multipart/byteranges; boundary=0123456789" */
-
- r->headers_out.content_type->value.len =
- ngx_sprintf(r->headers_out.content_type->value.data,
- "multipart/byteranges; boundary=%010ui",
- boundary)
- - r->headers_out.content_type->value.data;
-#if 0
- ngx_snprintf((char *)
- r->headers_out.content_type->value.data,
- 31 + 10 + 1,
- "multipart/byteranges; boundary=%010"
- NGX_UINT_T_FMT,
- boundary);
-#endif
-
- /* the size of the last boundary CRLF "--0123456789--" CRLF */
- len = 4 + 10 + 4;
-
- range = r->headers_out.ranges.elts;
- for (i = 0; i < r->headers_out.ranges.nelts; i++) {
- ngx_test_null(range[i].content_range.data,
- ngx_palloc(r->pool, 20 + 1 + 20 + 1 + 20 + 5),
- NGX_ERROR);
-
- /* the size of the range: "SSSS-EEEE/TTTT" CRLF CRLF */
-
- range[i].content_range.len =
- ngx_sprintf(range[i].content_range.data,
- "%O-%O/%O" CRLF CRLF,
- range[i].start, range[i].end - 1,
- r->headers_out.content_length_n)
- - range[i].content_range.data;
-#if 0
- ngx_snprintf((char *) range[i].content_range.data,
- 20 + 1 + 20 + 1 + 20 + 5,
- OFF_T_FMT "-" OFF_T_FMT "/" OFF_T_FMT CRLF CRLF,
- range[i].start, range[i].end - 1,
- r->headers_out.content_length_n);
-#endif
-
- len += ctx->boundary_header.len + range[i].content_range.len
- + (size_t) (range[i].end - range[i].start);
- }
+ if (r->headers_out.charset.len) {
+ ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data,
+ CRLF "--%010ud" CRLF
+ "Content-Type: %V; charset=%V" CRLF
+ "Content-Range: bytes ",
+ boundary,
+ &r->headers_out.content_type->value,
+ &r->headers_out.charset)
+ - ctx->boundary_header.data;
- r->headers_out.content_length_n = len;
- r->headers_out.content_length = NULL;
+ r->headers_out.charset.len = 0;
+
+ } else {
+ ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data,
+ CRLF "--%010ud" CRLF
+ "Content-Type: %V" CRLF
+ "Content-Range: bytes ",
+ boundary,
+ &r->headers_out.content_type->value)
+ - ctx->boundary_header.data;
+ }
+
+ r->headers_out.content_type->value.data =
+ ngx_palloc(r->pool, sizeof("Content-Type: multipart/byteranges; "
+ "boundary=0123456789") - 1);
+
+ if (r->headers_out.content_type->value.data == NULL) {
+ return NGX_ERROR;
+ }
+
+ /* "Content-Type: multipart/byteranges; boundary=0123456789" */
+
+ r->headers_out.content_type->value.len =
+ ngx_sprintf(r->headers_out.content_type->value.data,
+ "multipart/byteranges; boundary=%010ud",
+ boundary)
+ - r->headers_out.content_type->value.data;
+
+ /* the size of the last boundary CRLF "--0123456789--" CRLF */
+ len = sizeof(CRLF "--0123456789--" CRLF) - 1;
+
+ range = r->headers_out.ranges.elts;
+ for (i = 0; i < r->headers_out.ranges.nelts; i++) {
+
+ /* the size of the range: "SSSS-EEEE/TTTT" CRLF CRLF */
+
+ range[i].content_range.data =
+ ngx_palloc(r->pool, 3 * NGX_OFF_T_LEN + 2 + 4);
+
+ if (range[i].content_range.data == NULL) {
+ return NGX_ERROR;
}
+
+ range[i].content_range.len = ngx_sprintf(range[i].content_range.data,
+ "%O-%O/%O" CRLF CRLF,
+ range[i].start, range[i].end - 1,
+ r->headers_out.content_length_n)
+ - range[i].content_range.data;
+
+ len += ctx->boundary_header.len + range[i].content_range.len
+ + (size_t) (range[i].end - range[i].start);
}
+ r->headers_out.content_length_n = len;
+ r->headers_out.content_length = NULL;
+
return ngx_http_next_header_filter(r);
}
@@ -496,33 +461,54 @@ static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r,
* "Content-Range: bytes "
*/
- ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR);
+ if (!(b = ngx_calloc_buf(r->pool))) {
+ return NGX_ERROR;
+ }
+
b->memory = 1;
b->pos = ctx->boundary_header.data;
b->last = ctx->boundary_header.data + ctx->boundary_header.len;
- ngx_test_null(hcl, ngx_alloc_chain_link(r->pool), NGX_ERROR);
+ if (!(hcl = ngx_alloc_chain_link(r->pool))) {
+ return NGX_ERROR;
+ }
+
hcl->buf = b;
+
/* "SSSS-EEEE/TTTT" CRLF CRLF */
- ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR);
+ if (!(b = ngx_calloc_buf(r->pool))) {
+ return NGX_ERROR;
+ }
+
b->temporary = 1;
b->pos = range[i].content_range.data;
b->last = range[i].content_range.data + range[i].content_range.len;
- ngx_test_null(rcl, ngx_alloc_chain_link(r->pool), NGX_ERROR);
+ if (!(rcl = ngx_alloc_chain_link(r->pool))) {
+ return NGX_ERROR;
+ }
+
rcl->buf = b;
+
/* the range data */
- ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR);
+ if (!(b = ngx_calloc_buf(r->pool))) {
+ return NGX_ERROR;
+ }
+
b->in_file = 1;
b->file_pos = range[i].start;
b->file_last = range[i].end;
b->file = in->buf->file;
- ngx_alloc_link_and_set_buf(dcl, b, r->pool, NGX_ERROR);
+ if (!(dcl = ngx_alloc_chain_link(r->pool))) {
+ return NGX_ERROR;
+ }
+
+ dcl->buf = b;
*ll = hcl;
hcl->next = rcl;
@@ -532,15 +518,29 @@ static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r,
/* the last boundary CRLF "--0123456789--" CRLF */
- ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR);
+ if (!(b = ngx_calloc_buf(r->pool))) {
+ return NGX_ERROR;
+ }
+
b->temporary = 1;
b->last_buf = 1;
- ngx_test_null(b->pos, ngx_palloc(r->pool, 4 + 10 + 4), NGX_ERROR);
+
+ b->pos = ngx_palloc(r->pool, sizeof(CRLF "--0123456789--" CRLF) - 1);
+ if (b->pos == NULL) {
+ return NGX_ERROR;
+ }
+
b->last = ngx_cpymem(b->pos, ctx->boundary_header.data, 4 + 10);
*b->last++ = '-'; *b->last++ = '-';
*b->last++ = CR; *b->last++ = LF;
- ngx_alloc_link_and_set_buf(hcl, b, r->pool, NGX_ERROR);
+ if (!(hcl = ngx_alloc_chain_link(r->pool))) {
+ return NGX_ERROR;
+ }
+
+ hcl->buf = b;
+ hcl->next = NULL;
+
*ll = hcl;
return ngx_http_next_body_filter(r, out);
diff --git a/src/http/modules/ngx_http_rewrite_handler.c b/src/http/modules/ngx_http_rewrite_handler.c
index aa3a65648..0973ef087 100644
--- a/src/http/modules/ngx_http_rewrite_handler.c
+++ b/src/http/modules/ngx_http_rewrite_handler.c
@@ -146,8 +146,8 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r)
if (rc == NGX_DECLINED) {
if (scf->log) {
ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
- "\"%s\" does not match \"%s\"",
- rule[i].re_name.data, r->uri.data);
+ "\"%V\" does not match \"%V\"",
+ &rule[i].re_name, &r->uri);
}
continue;
@@ -156,15 +156,15 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r)
if (rc < 0) {
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
ngx_regex_exec_n
- " failed: %d on \"%s\" using \"%s\"",
- rc, r->uri.data, rule[i].re_name.data);
+ " failed: %d on \"%V\" using \"%V\"",
+ rc, &r->uri, &rule[i].re_name);
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
if (scf->log) {
ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
- "\"%s\" matches \"%s\"",
- rule[i].re_name.data, r->uri.data);
+ "\"%V\" matches \"%V\"",
+ &rule[i].re_name, &r->uri);
}
if (rule[i].status) {
@@ -177,7 +177,7 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r)
uri.len += matches[2 * n + 1] - matches[2 * n];
}
- if (!(uri.data = ngx_palloc(r->pool, uri.len + 1))) {
+ if (!(uri.data = ngx_palloc(r->pool, uri.len))) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -203,11 +203,9 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r)
}
}
- *p = '\0';
-
if (scf->log) {
ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
- "rewritten uri: \"%s\"", uri.data);
+ "rewritten uri: \"%V\"", &uri);
}
r->uri = uri;
@@ -353,7 +351,7 @@ static char *ngx_http_rewrite_rule(ngx_conf_t *cf, ngx_command_t *cmd,
}
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid parameter \"%s\"", value[3].data);
+ "invalid parameter \"%V\"", &value[3]);
return NGX_CONF_ERROR;
}
@@ -427,7 +425,7 @@ static char *ngx_http_rewrite_rule(ngx_conf_t *cf, ngx_command_t *cmd,
} else {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid parameter \"%s\"", value[3].data);
+ "invalid parameter \"%V\"", &value[3]);
return NGX_CONF_ERROR;
}
}
diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c
index c4ffde3b2..12cf5b39d 100644
--- a/src/http/modules/ngx_http_static_handler.c
+++ b/src/http/modules/ngx_http_static_handler.c
@@ -197,7 +197,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
&name, &file_crc);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
- "http open file cache get: " PTR_FMT, file);
+ "http open file cache get: %p", file);
if (file && !file->expired) {
r->cache = file;
@@ -216,7 +216,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
&name, &redirect_crc);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
- "http redirect cache get: " PTR_FMT, redirect);
+ "http redirect cache get: %p", redirect);
if (redirect && !redirect->expired) {
@@ -247,7 +247,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
/* open file */
-#if (WIN9X)
+#if (NGX_WIN9X)
/* TODO: redirect cache */
@@ -276,7 +276,8 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
}
if (ngx_is_dir(&fi)) {
- ngx_log_debug(log, "HTTP DIR: '%s'" _ name.data);
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
+ "HTTP DIR: \"%s\"", name.data);
if (!(r->headers_out.location =
ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
@@ -384,7 +385,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
location.len--;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
- "http redirect cache alloc: " PTR_FMT, redirect);
+ "http redirect cache alloc: %p", redirect);
if (redirect) {
redirect->fd = NGX_INVALID_FILE;
@@ -403,11 +404,11 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
return NGX_HTTP_MOVED_PERMANENTLY;
}
-#if !(WIN32) /* the not regular files are probably Unix specific */
+#if !(NGX_WIN32) /* the not regular files are probably Unix specific */
if (!ngx_is_file(&fi)) {
ngx_log_error(NGX_LOG_CRIT, log, ngx_errno,
- "%s is not a regular file", name.data);
+ "\"%s\" is not a regular file", name.data);
if (ngx_close_file(fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
@@ -459,7 +460,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
#endif
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
- "http open file cache alloc: " PTR_FMT, file);
+ "http open file cache alloc: %p", file);
if (file) {
file->fd = fd;
diff --git a/src/http/modules/ngx_http_status_handler.c b/src/http/modules/ngx_http_status_handler.c
index 357affff4..ce49ae426 100644
--- a/src/http/modules/ngx_http_status_handler.c
+++ b/src/http/modules/ngx_http_status_handler.c
@@ -171,10 +171,7 @@ static ngx_int_t ngx_http_status(ngx_http_status_ctx_t *ctx)
return NGX_ERROR;
}
- b->last += ngx_snprintf((char *) b->last,
- /* STUB: should be NGX_PID_T_LEN */
- NGX_INT64_LEN + NGX_INT32_LEN,
- PID_T_FMT " %4u", ngx_pid, i);
+ b->last = ngx_sprintf(b->last, "%P %5ui", ngx_pid, i);
switch (r->http_state) {
case NGX_HTTP_INITING_REQUEST_STATE:
@@ -250,10 +247,7 @@ static ngx_int_t ngx_http_status(ngx_http_status_ctx_t *ctx)
return NGX_ERROR;
}
- b->last += ngx_snprintf((char *) b->last,
- /* STUB: should be NGX_PID_T_LEN */
- NGX_INT64_LEN + NGX_INT32_LEN,
- PID_T_FMT " %4u", ngx_pid, i);
+ b->last = ngx_sprintf(b->last, "%P %5ui", ngx_pid, i);
*(b->last++) = ' ';
*(b->last++) = 's';
diff --git a/src/http/modules/ngx_http_userid_filter.c b/src/http/modules/ngx_http_userid_filter.c
index bafdea884..2385ceed2 100644
--- a/src/http/modules/ngx_http_userid_filter.c
+++ b/src/http/modules/ngx_http_userid_filter.c
@@ -27,15 +27,13 @@ typedef struct {
ngx_str_t domain;
ngx_str_t path;
time_t expires;
-
- ngx_int_t p3p;
- ngx_str_t p3p_string;
+ ngx_str_t p3p;
} ngx_http_userid_conf_t;
typedef struct {
- uint32_t uid_got[4];
- uint32_t uid_set[4];
+ uint32_t uid_got[4];
+ uint32_t uid_set[4];
} ngx_http_userid_ctx_t;
@@ -56,8 +54,10 @@ static ngx_int_t ngx_http_userid_pre_conf(ngx_conf_t *cf);
static void *ngx_http_userid_create_conf(ngx_conf_t *cf);
static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent,
void *child);
-char *ngx_conf_check_domain(ngx_conf_t *cf, void *post, void *data);
+char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data);
+char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data);
char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
+char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data);
static uint32_t sequencer_v1 = 1;
@@ -79,8 +79,11 @@ static ngx_conf_enum_t ngx_http_userid_state[] = {
};
-static ngx_conf_post_handler_pt ngx_conf_check_domain_p =
- ngx_conf_check_domain;
+static ngx_conf_post_handler_pt ngx_http_userid_domain_p =
+ ngx_http_userid_domain;
+
+static ngx_conf_post_handler_pt ngx_http_userid_path_p = ngx_http_userid_path;
+static ngx_conf_post_handler_pt ngx_http_userid_p3p_p = ngx_http_userid_p3p;
static ngx_command_t ngx_http_userid_commands[] = {
@@ -111,14 +114,14 @@ static ngx_command_t ngx_http_userid_commands[] = {
ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_userid_conf_t, domain),
- &ngx_conf_check_domain_p },
+ &ngx_http_userid_domain_p },
{ ngx_string("userid_path"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_userid_conf_t, path),
- NULL },
+ &ngx_http_userid_path_p },
{ ngx_string("userid_expires"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
@@ -127,6 +130,13 @@ static ngx_command_t ngx_http_userid_commands[] = {
0,
NULL },
+ { ngx_string("userid_p3p"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_str_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_userid_conf_t, p3p),
+ &ngx_http_userid_p3p_p },
+
ngx_null_command
};
@@ -210,40 +220,44 @@ static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r,
for (i = 0; i < r->headers_in.cookies.nelts; i++) {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "cookie: \"%s\"", cookies[i]->value.data);
+ "cookie: \"%V\"", &cookies[i]->value);
+ if (conf->name.len >= cookies[i]->value.len) {
+ continue;
+ }
+
+ start = cookies[i]->value.data;
end = cookies[i]->value.data + cookies[i]->value.len;
- for (start = cookies[i]->value.data; start < end; /* void */) {
+ while (start < end) {
- if (conf->name.len >= cookies[i]->value.len
- || ngx_strncmp(start, conf->name.data, conf->name.len) != 0)
- {
- start += conf->name.len;
- while (start < end && *start++ != ';') { /* void */ }
+ if (ngx_strncmp(start, conf->name.data, conf->name.len) != 0) {
- for (/* void */; start < end && *start == ' '; start++) { /**/ }
+ while (start < end && *start++ != ';') { /* void */ }
+ while (start < end && *start == ' ') { start++; }
continue;
}
- for (start += conf->name.len; start < end && *start == ' '; start++)
- {
- /* void */
- }
+ start += conf->name.len;
- if (*start != '=') {
+ while (start < end && *start == ' ') { start++; }
+
+ if (start == end || *start++ != '=') {
+ /* the invalid "Cookie" header */
break;
}
- for (start++; start < end && *start == ' '; start++) { /* void */ }
+ while (start < end && *start == ' ') { start++; }
+
+ last = start;
- for (last = start; last < end && *last != ';'; last++) { /**/ }
+ while (last < end && *last++ != ';') { /* void */ }
if (last - start < 22) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "client sent too short userid cookie \"%s\"",
- cookies[i]->value.data);
+ "client sent too short userid cookie \"%V\"",
+ &cookies[i]->value);
break;
}
@@ -259,13 +273,13 @@ static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r,
if (ngx_decode_base64(&dst, &src) == NGX_ERROR) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "client sent invalid userid cookie \"%s\"",
- cookies[i]->value.data);
+ "client sent invalid userid cookie \"%V\"",
+ &cookies[i]->value);
break;
}
ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "uid: %08X%08X%08X%08X",
+ "uid: %08XD%08XD%08XD%08XD",
ctx->uid_got[0], ctx->uid_got[1],
ctx->uid_got[2], ctx->uid_got[3]);
@@ -280,14 +294,13 @@ static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r,
static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
ngx_http_userid_ctx_t *ctx,
ngx_http_userid_conf_t *conf)
-
{
u_char *cookie, *p;
size_t len;
socklen_t slen;
struct sockaddr_in addr_in;
ngx_str_t src, dst;
- ngx_table_elt_t *set_cookie;
+ ngx_table_elt_t *set_cookie, *p3p;
/* TODO: mutex for sequencers */
@@ -333,18 +346,14 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
}
}
- len = conf->name.len + 1 + ngx_base64_encoded_length(16) + 1;
+ len = conf->name.len + 1 + ngx_base64_encoded_length(16) + conf->path.len;
if (conf->expires) {
len += sizeof(expires) - 1 + 2;
}
if (conf->domain.len > 1) {
- len += sizeof("; domain=") - 1 + conf->domain.len;
- }
-
- if (conf->path.len) {
- len += sizeof("; path=") - 1 + conf->path.len;
+ len += conf->domain.len;
}
if (!(cookie = ngx_palloc(r->pool, len))) {
@@ -371,19 +380,10 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
}
if (conf->domain.len > 1) {
- p = ngx_cpymem(p, "; domain=", sizeof("; domain=") - 1);
p = ngx_cpymem(p, conf->domain.data, conf->domain.len);
}
- if (conf->path.len) {
- p = ngx_cpymem(p, "; path=", sizeof("; path=") - 1);
- p = ngx_cpymem(p, conf->path.data, conf->path.len);
- }
-
- *p = '\0';
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "uid cookie: \"%s\"", cookie);
+ p = ngx_cpymem(p, conf->path.data, conf->path.len);
if (!(set_cookie = ngx_list_push(&r->headers_out.headers))) {
return NGX_ERROR;
@@ -394,6 +394,21 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
set_cookie->value.len = p - cookie;
set_cookie->value.data = cookie;
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "uid cookie: \"%V\"", &set_cookie->value);
+
+ if (conf->p3p.len == 1) {
+ return NGX_OK;
+ }
+
+ if (!(p3p = ngx_list_push(&r->headers_out.headers))) {
+ return NGX_ERROR;
+ }
+
+ p3p->key.len = sizeof("P3P") - 1;
+ p3p->key.data = (u_char *) "P3P";
+ p3p->value = conf->p3p;
+
return NGX_OK;
}
@@ -425,9 +440,9 @@ static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf,
*buf++ = '=';
- return buf + ngx_snprintf((char *) buf, 33, "%08X%08X%08X%08X",
- ctx->uid_got[0], ctx->uid_got[1],
- ctx->uid_got[2], ctx->uid_got[3]);
+ return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD",
+ ctx->uid_got[0], ctx->uid_got[1],
+ ctx->uid_got[2], ctx->uid_got[3]);
}
@@ -458,9 +473,9 @@ static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf,
*buf++ = '=';
- return buf + ngx_snprintf((char *) buf, 33, "%08X%08X%08X%08X",
- ctx->uid_set[0], ctx->uid_set[1],
- ctx->uid_set[2], ctx->uid_set[3]);
+ return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD",
+ ctx->uid_set[0], ctx->uid_set[1],
+ ctx->uid_set[2], ctx->uid_set[3]);
}
@@ -510,6 +525,8 @@ static void *ngx_http_userid_create_conf(ngx_conf_t *cf)
conf->domain.date = NULL;
conf->path.len = 0;
conf->path.date = NULL;
+ conf->p3p.len = 0;
+ conf->p3p.date = NULL;
*/
@@ -531,7 +548,8 @@ static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent,
ngx_conf_merge_str_value(conf->name, prev->name, "uid");
ngx_conf_merge_str_value(conf->domain, prev->domain, ".");
- ngx_conf_merge_str_value(conf->path, prev->path, "/");
+ ngx_conf_merge_str_value(conf->path, prev->path, "; path=/");
+ ngx_conf_merge_str_value(conf->p3p, prev->p3p, ".");
ngx_conf_merge_value(conf->service, prev->service, NGX_CONF_UNSET);
ngx_conf_merge_sec_value(conf->expires, prev->expires, 0);
@@ -540,15 +558,49 @@ static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent,
}
-char *ngx_conf_check_domain(ngx_conf_t *cf, void *post, void *data)
+char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data)
{
ngx_str_t *domain = data;
+ u_char *p, *new;
+
if (domain->len == 4 && ngx_strcmp(domain->data, "none") == 0) {
domain->len = 1;
domain->data = (u_char *) ".";
+
+ return NGX_CONF_OK;
+ }
+
+ if (!(new = ngx_palloc(cf->pool, sizeof("; domain=") - 1 + domain->len))) {
+ return NGX_CONF_ERROR;
+ }
+
+ p = ngx_cpymem(new, "; domain=", sizeof("; domain=") - 1);
+ p = ngx_cpymem(p, domain->data, domain->len);
+
+ domain->len += sizeof("; domain=") - 1;
+ domain->data = new;
+
+ return NGX_CONF_OK;
+}
+
+
+char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data)
+{
+ ngx_str_t *path = data;
+
+ u_char *p, *new;
+
+ if (!(new = ngx_palloc(cf->pool, sizeof("; path=") - 1 + path->len))) {
+ return NGX_CONF_ERROR;
}
+ p = ngx_cpymem(new, "; path=", sizeof("; path=") - 1);
+ p = ngx_cpymem(p, path->data, path->len);
+
+ path->len += sizeof("; path=") - 1;
+ path->data = new;
+
return NGX_CONF_OK;
}
@@ -586,3 +638,16 @@ char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_OK;
}
+
+
+char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data)
+{
+ ngx_str_t *p3p = data;
+
+ if (p3p->len == 4 && ngx_strcmp(p3p->data, "none") == 0) {
+ p3p->len = 1;
+ p3p->data = (u_char *) ".";
+ }
+
+ return NGX_CONF_OK;
+}
diff --git a/src/http/modules/proxy/ngx_http_proxy_cache.c b/src/http/modules/proxy/ngx_http_proxy_cache.c
index 0a2a20025..f0b56f548 100644
--- a/src/http/modules/proxy/ngx_http_proxy_cache.c
+++ b/src/http/modules/proxy/ngx_http_proxy_cache.c
@@ -173,8 +173,8 @@ static int ngx_http_proxy_process_cached_header(ngx_http_proxy_ctx_t *p)
ngx_cpystrn(c->status_line.data, p->status_start, c->status_line.len + 1);
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http cache status %d \"%s\"",
- c->status, c->status_line.data);
+ "http cache status %ui \"%V\"",
+ c->status, &c->status_line);
/* TODO: ngx_init_table */
c->headers_in.headers = ngx_create_table(r->pool, 20);
@@ -219,8 +219,7 @@ static int ngx_http_proxy_process_cached_header(ngx_http_proxy_ctx_t *p)
}
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http cache header: \"%s: %s\"",
- h->key.data, h->value.data);
+ "http cache header: \"%V: %V\"", &h->key, &h->value);
continue;
@@ -614,7 +613,7 @@ int ngx_http_proxy_update_cache(ngx_http_proxy_ctx_t *p)
ep = p->upstream->event_pipe;
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0,
- "http cache update len: " OFF_T_FMT ":" OFF_T_FMT,
+ "http cache update len: %O:%O",
p->cache->ctx.length, ep->read_length);
if (p->cache->ctx.length == -1) {
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index 64f7c0794..915d378e6 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -710,26 +710,75 @@ void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p)
}
-size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len)
+u_char *ngx_http_proxy_log_error(void *data, u_char *buf, size_t len)
{
ngx_http_proxy_log_ctx_t *ctx = data;
- ngx_http_request_t *r;
- ngx_peer_connection_t *peer;
+ u_char *p;
+ ngx_int_t escape;
+ ngx_str_t uri;
+ ngx_http_request_t *r;
+ ngx_peer_connection_t *peer;
+ ngx_http_proxy_upstream_conf_t *uc;
r = ctx->proxy->request;
+ uc = ctx->proxy->lcf->upstream;
peer = &ctx->proxy->upstream->peer;
- return ngx_snprintf(buf, len,
- " while %s, client: %s, URL: %s, upstream: %s%s%s%s%s",
- ctx->proxy->action,
- r->connection->addr_text.data,
- r->unparsed_uri.data,
- peer->peers->peers[peer->cur_peer].addr_port_text.data,
- ctx->proxy->lcf->upstream->uri.data,
- r->uri.data + ctx->proxy->lcf->upstream->location->len,
- r->args.len ? "?" : "",
- r->args.len ? r->args.data : (u_char *) "");
+ p = ngx_snprintf(buf, len,
+ " while %s, client: %V, URL: %V, upstream: %V%V",
+ ctx->proxy->action,
+ &r->connection->addr_text,
+ &r->unparsed_uri,
+ &peer->peers->peers[peer->cur_peer].addr_port_text,
+ &ctx->proxy->lcf->upstream->uri);
+ len -= p - buf;
+ buf = p;
+
+ if (r->quoted_uri) {
+ escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len,
+ r->uri.len - uc->location->len,
+ NGX_ESCAPE_URI);
+ } else {
+ escape = 0;
+ }
+
+ if (escape) {
+ if (len >= r->uri.len - uc->location->len + escape) {
+
+ ngx_escape_uri(buf, r->uri.data + uc->location->len,
+ r->uri.len - uc->location->len, NGX_ESCAPE_URI);
+
+ buf += r->uri.len - uc->location->len + escape;
+
+ if (r->args.len == 0) {
+ return buf;
+ }
+
+ len -= r->uri.len - uc->location->len + escape;
+
+ return ngx_snprintf(buf, len, "?%V", &r->args);
+ }
+
+ p = ngx_palloc(r->pool, r->uri.len - uc->location->len + escape);
+ if (p == NULL) {
+ return buf;
+ }
+
+ ngx_escape_uri(p, r->uri.data + uc->location->len,
+ r->uri.len - uc->location->len, NGX_ESCAPE_URI);
+
+ uri.len = r->uri.len - uc->location->len + escape;
+ uri.data = p;
+
+ } else {
+ uri.len = r->uri.len - uc->location->len;
+ uri.data = r->uri.data + uc->location->len;
+
+ }
+
+ return ngx_snprintf(buf, len, "%V%s%V",
+ &uri, r->args.len ? "?" : "", &r->args);
}
@@ -759,8 +808,7 @@ static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r,
*buf++ = '-';
} else {
- buf += ngx_snprintf((char *) buf, TIME_T_LEN,
- TIME_T_FMT, p->state->expired);
+ buf = ngx_sprintf(buf, "%T", p->state->expired);
}
*buf++ = '/';
@@ -769,8 +817,7 @@ static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r,
*buf++ = '-';
} else {
- buf += ngx_snprintf((char *) buf, TIME_T_LEN,
- TIME_T_FMT, p->state->bl_time);
+ buf = ngx_sprintf(buf, "%T", p->state->bl_time);
}
*buf++ = '/';
@@ -783,8 +830,7 @@ static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r,
*buf++ = '-';
} else {
- buf += ngx_snprintf((char *) buf, 4, "%" NGX_UINT_T_FMT,
- p->state->status);
+ buf = ngx_sprintf(buf, "%ui", p->state->status);
}
*buf++ = '/';
@@ -803,8 +849,7 @@ static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r,
*buf++ = '-';
} else {
- buf += ngx_snprintf((char *) buf, TIME_T_LEN,
- TIME_T_FMT, p->state->expires);
+ buf = ngx_sprintf(buf, "%T", p->state->expires);
}
*buf++ = ' ';
@@ -1166,7 +1211,7 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
lcf->peers->peers[i].addr = *(in_addr_t *)(h->h_addr_list[i]);
lcf->peers->peers[i].port = lcf->upstream->port;
- len = INET_ADDRSTRLEN + lcf->upstream->port_text.len + 1;
+ len = INET_ADDRSTRLEN - 1 + 1 + lcf->upstream->port_text.len;
lcf->peers->peers[i].addr_port_text.data =
ngx_palloc(cf->pool, len);
@@ -1181,12 +1226,12 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
lcf->peers->peers[i].addr_port_text.data[len++] = ':';
- ngx_cpystrn(lcf->peers->peers[i].addr_port_text.data + len,
- lcf->upstream->port_text.data,
- lcf->upstream->port_text.len + 1);
+ ngx_memcpy(lcf->peers->peers[i].addr_port_text.data + len,
+ lcf->upstream->port_text.data,
+ lcf->upstream->port_text.len);
lcf->peers->peers[i].addr_port_text.len =
- len + lcf->upstream->port_text.len + 1;
+ len + lcf->upstream->port_text.len;
}
} else {
@@ -1204,10 +1249,11 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
lcf->peers->peers[0].addr = addr;
lcf->peers->peers[0].port = lcf->upstream->port;
- len = lcf->upstream->host.len + lcf->upstream->port_text.len + 1;
+ len = lcf->upstream->host.len + 1 + lcf->upstream->port_text.len;
+
+ lcf->peers->peers[0].addr_port_text.len = len;
- lcf->peers->peers[0].addr_port_text.data =
- ngx_palloc(cf->pool, len + 1);
+ lcf->peers->peers[0].addr_port_text.data = ngx_palloc(cf->pool, len);
if (lcf->peers->peers[0].addr_port_text.data == NULL) {
return NGX_CONF_ERROR;
}
@@ -1219,9 +1265,9 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
lcf->peers->peers[0].addr_port_text.data[len++] = ':';
- ngx_cpystrn(lcf->peers->peers[0].addr_port_text.data + len,
- lcf->upstream->port_text.data,
- lcf->upstream->port_text.len + 1);
+ ngx_memcpy(lcf->peers->peers[0].addr_port_text.data + len,
+ lcf->upstream->port_text.data,
+ lcf->upstream->port_text.len);
}
clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h
index 76db65282..094ee3bd1 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.h
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.h
@@ -245,7 +245,7 @@ void ngx_http_proxy_check_broken_connection(ngx_event_t *ev);
void ngx_http_proxy_busy_lock_handler(ngx_event_t *rev);
void ngx_http_proxy_upstream_busy_lock(ngx_http_proxy_ctx_t *p);
-size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len);
+u_char *ngx_http_proxy_log_error(void *data, u_char *buf, size_t len);
void ngx_http_proxy_finalize_request(ngx_http_proxy_ctx_t *p, int rc);
void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p);
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index 9b3d8847e..0852a426f 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -25,7 +25,8 @@ static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev);
static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *);
static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p);
static void ngx_http_proxy_process_body(ngx_event_t *ev);
-static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, int ft_type);
+static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p,
+ ngx_uint_t ft_type);
static ngx_str_t http_methods[] = {
@@ -137,7 +138,8 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
if (r->quoted_uri) {
escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len,
- r->uri.len - uc->location->len);
+ r->uri.len - uc->location->len,
+ NGX_ESCAPE_URI);
} else {
escape = 0;
}
@@ -246,7 +248,7 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
if (escape) {
ngx_escape_uri(b->last, r->uri.data + uc->location->len,
- r->uri.len - uc->location->len);
+ r->uri.len - uc->location->len, NGX_ESCAPE_URI);
b->last += r->uri.len - uc->location->len + escape;
} else {
@@ -409,8 +411,8 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
*(b->last++) = CR; *(b->last++) = LF;
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http proxy header: \"%s: %s\"",
- header[i].key.data, header[i].value.data);
+ "http proxy header: \"%V: %V\"",
+ &header[i].key, &header[i].value);
}
/* add "\r\n" at the header end */
@@ -670,7 +672,7 @@ void ngx_http_proxy_upstream_busy_lock(ngx_http_proxy_ctx_t *p)
static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
{
- int rc;
+ ngx_int_t rc;
ngx_connection_t *c;
ngx_http_request_t *r;
ngx_output_chain_ctx_t *output;
@@ -683,7 +685,7 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
rc = ngx_event_connect_peer(&p->upstream->peer);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0,
- "http proxy connect: %d", rc);
+ "http proxy connect: %i", rc);
if (rc == NGX_ERROR) {
ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
@@ -705,6 +707,8 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
c->write->event_handler = ngx_http_proxy_send_request_handler;
c->read->event_handler = ngx_http_proxy_process_upstream_status_line;
+ c->sendfile = r->connection->sendfile;
+
c->pool = r->pool;
c->read->log = c->write->log = c->log = r->connection->log;
@@ -1028,8 +1032,8 @@ static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev)
p->upstream->status_line.len + 1);
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, rev->log, 0,
- "http proxy status %d \"%s\"",
- p->upstream->status, p->upstream->status_line.data);
+ "http proxy status %ui \"%V\"",
+ p->upstream->status, &p->upstream->status_line);
/* init or reinit the p->upstream->headers_in.headers table */
@@ -1143,8 +1147,7 @@ static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev)
}
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http proxy header: \"%s: %s\"",
- h->key.data, h->value.data);
+ "http proxy header: \"%V: %V\"", &h->key, &h->value);
continue;
@@ -1467,7 +1470,7 @@ static void ngx_http_proxy_process_body(ngx_event_t *ev)
if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0,
- "http proxy upstream exit: " PTR_FMT, ep->out);
+ "http proxy upstream exit: %p", ep->out);
ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
ngx_http_proxy_finalize_request(p, 0);
return;
@@ -1484,12 +1487,13 @@ static void ngx_http_proxy_process_body(ngx_event_t *ev)
}
-static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, int ft_type)
+static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p,
+ ngx_uint_t ft_type)
{
- int status;
+ ngx_uint_t status;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0,
- "http proxy next upstream: %d", ft_type);
+ "http proxy next upstream: %ui", ft_type);
ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c
index 90bbbe2f5..a550acb1d 100644
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -83,7 +83,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_http_core_srv_conf_t **cscfp, *cscf;
ngx_http_core_loc_conf_t *clcf;
ngx_http_core_main_conf_t *cmcf;
-#if (WIN32)
+#if (NGX_WIN32)
ngx_iocp_conf_t *iocpcf;
#endif
@@ -343,9 +343,8 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (in_addr[a].default_server) {
ngx_log_error(NGX_LOG_ERR, cf->log, 0,
- "the duplicate default server in %s:%d",
- lscf[l].file_name.data,
- lscf[l].line);
+ "the duplicate default server in %V:%d",
+ &lscf[l].file_name, lscf[l].line);
return NGX_CONF_ERROR;
}
@@ -516,7 +515,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index];
ls->log = clcf->err_log;
-#if (WIN32)
+#if (NGX_WIN32)
iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module);
if (iocpcf->acceptex_read) {
ls->post_accept_buffer_size = cscf->client_header_buffer_size;
@@ -582,18 +581,18 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
in_port = in_ports.elts;
for (p = 0; p < in_ports.nelts; p++) {
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0,
- "port: %d %08x", in_port[p].port, &in_port[p]);
+ "port: %d %p", in_port[p].port, &in_port[p]);
in_addr = in_port[p].addrs.elts;
for (a = 0; a < in_port[p].addrs.nelts; a++) {
ngx_inet_ntop(AF_INET, &in_addr[a].addr, address, 20);
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, cf->log, 0,
- "%s:%d %08x",
+ "%s:%d %p",
address, in_port[p].port, in_addr[a].core_srv_conf);
s_name = in_addr[a].names.elts;
for (n = 0; n < in_addr[a].names.nelts; n++) {
ngx_log_debug4(NGX_LOG_DEBUG_HTTP, cf->log, 0,
- "%s:%d %s %08x",
- address, in_port[p].port, s_name[n].name.data,
+ "%s:%d %V %p",
+ address, in_port[p].port, &s_name[n].name,
s_name[n].core_srv_conf);
}
}
@@ -671,7 +670,7 @@ static ngx_int_t ngx_http_add_names(ngx_conf_t *cf,
for (i = 0; i < cscf->server_names.nelts; i++) {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0,
- "name: %s", server_names[i].name.data);
+ "name: %V", &server_names[i].name);
/* TODO: duplicate names can be checked here */
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h
index 303a4daef..46194f34d 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -33,7 +33,7 @@ typedef struct ngx_http_cleanup_s ngx_http_cleanup_t;
typedef struct {
- u_int connection;
+ u_int connection;
/*
* we declare "action" as "char *" because the actions are usually
@@ -41,9 +41,9 @@ typedef struct {
* all the time their types
*/
- char *action;
- u_char *client;
- u_char *url;
+ char *action;
+ ngx_str_t *client;
+ ngx_http_request_t *request;
} ngx_http_log_ctx_t;
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 8f101bad8..7e8cf6903 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -10,7 +10,7 @@
#include <ngx_http.h>
#include <nginx.h>
-/* STUB */
+
#define NGX_HTTP_LOCATION_EXACT 1
#define NGX_HTTP_LOCATION_AUTO_REDIRECT 2
#define NGX_HTTP_LOCATION_REGEX 3
@@ -329,12 +329,12 @@ ngx_module_t ngx_http_core_module = {
void ngx_http_handler(ngx_http_request_t *r)
{
- ngx_http_log_ctx_t *lcx;
+ ngx_http_log_ctx_t *ctx;
r->connection->unexpected_eof = 0;
- lcx = r->connection->log->data;
- lcx->action = NULL;
+ ctx = r->connection->log->data;
+ ctx->action = NULL;
switch (r->headers_in.connection_type) {
case 0:
@@ -526,17 +526,15 @@ ngx_int_t ngx_http_find_location_config(ngx_http_request_t *r)
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http cl: " SIZE_T_FMT " max: " SIZE_T_FMT,
- r->headers_in.content_length_n,
- clcf->client_max_body_size);
+ "http cl:%z max:%uz",
+ r->headers_in.content_length_n, clcf->client_max_body_size);
if (r->headers_in.content_length_n != -1
&& clcf->client_max_body_size
&& clcf->client_max_body_size < (size_t) r->headers_in.content_length_n)
{
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "client intented to send too large body: "
- SIZE_T_FMT " bytes",
+ "client intented to send too large body: %z bytes",
r->headers_in.content_length_n);
return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE;
@@ -583,9 +581,8 @@ static ngx_int_t ngx_http_find_location(ngx_http_request_t *r,
#endif
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "find location: %s\"%s\"",
- clcfp[i]->exact_match ? "= " : "",
- clcfp[i]->name.data);
+ "find location: %s\"%V\"",
+ clcfp[i]->exact_match ? "= " : "", &clcfp[i]->name);
if (clcfp[i]->auto_redirect
&& r->uri.len == clcfp[i]->name.len - 1
@@ -649,8 +646,7 @@ static ngx_int_t ngx_http_find_location(ngx_http_request_t *r,
}
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "find location: ~ \"%s\"",
- clcfp[i]->name.data);
+ "find location: ~ \"%V\"", &clcfp[i]->name);
n = ngx_regex_exec(clcfp[i]->regex, &r->uri, NULL, 0);
@@ -661,8 +657,8 @@ static ngx_int_t ngx_http_find_location(ngx_http_request_t *r,
if (n < 0) {
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
ngx_regex_exec_n
- " failed: %d on \"%s\" using \"%s\"",
- n, r->uri.data, clcfp[i]->name.data);
+ " failed: %d on \"%V\" using \"%V\"",
+ n, &r->uri, &clcfp[i]->name);
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -809,14 +805,12 @@ ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r,
ngx_str_t *uri, ngx_str_t *args)
{
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "internal redirect: \"%s\"", uri->data);
+ "internal redirect: \"%V\"", uri);
- r->uri.len = uri->len;
- r->uri.data = uri->data;
+ r->uri = *uri;
if (args) {
- r->args.len = args->len;
- r->args.data = args->data;
+ r->args = *args;
}
if (ngx_http_set_exten(r) != NGX_OK) {
@@ -1092,16 +1086,14 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
clcf->name = value[2];
#else
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "the using of the regex \"%s\" "
- "requires PCRE library",
- value[2].data);
+ "the using of the regex \"%V\" "
+ "requires PCRE library", &value[2]);
return NGX_CONF_ERROR;
#endif
} else {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid location modifier \"%s\"",
- value[1].data);
+ "invalid location modifier \"%V\"", &value[1]);
return NGX_CONF_ERROR;
}
@@ -1123,9 +1115,9 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
if (pclcf->exact_match) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "location \"%s\" could not be inside "
- "the exact location \"%s\"",
- clcf->name.data, pclcf->name.data);
+ "location \"%V\" could not be inside "
+ "the exact location \"%V\"",
+ &clcf->name, &pclcf->name);
return NGX_CONF_ERROR;
}
@@ -1139,8 +1131,8 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
#endif
{
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "location \"%s\" is outside location \"%s\"",
- clcf->name.data, pclcf->name.data);
+ "location \"%V\" is outside location \"%V\"",
+ &clcf->name, &pclcf->name);
return NGX_CONF_ERROR;
}
@@ -1301,7 +1293,7 @@ static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
if (conf->listen.nelts == 0) {
ngx_test_null(l, ngx_push_array(&conf->listen), NGX_CONF_ERROR);
l->addr = INADDR_ANY;
-#if (WIN32)
+#if (NGX_WIN32)
l->port = 80;
#else
/* STUB: getuid() should be cached */
@@ -1561,9 +1553,9 @@ static char *ngx_http_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|| (port < 1 || port > 65536)) { /* "listen 99999" */
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid port \"%s\" in \"%s\" directive, "
+ "invalid port \"%s\" in \"%V\" directive, "
"it must be a number between 1 and 65535",
- &addr[p], cmd->name.data);
+ &addr[p], &cmd->name);
return NGX_CONF_ERROR;
@@ -1583,7 +1575,7 @@ static char *ngx_http_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (h == NULL || h->h_addr_list[0] == NULL) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"can not resolve host \"%s\" "
- "in \"%s\" directive", addr, cmd->name.data);
+ "in \"%V\" directive", addr, &cmd->name);
return NGX_CONF_ERROR;
}
@@ -1612,9 +1604,9 @@ static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
for (i = 1; i < cf->args->nelts; i++) {
if (value[i].len == 0) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "server name \"%s\" is invalid "
- "in \"%s\" directive",
- value[i].data, cmd->name.data);
+ "server name \"%V\" is invalid "
+ "in \"%V\" directive",
+ &value[i], &cmd->name);
return NGX_CONF_ERROR;
}
@@ -1659,13 +1651,13 @@ static char *ngx_set_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if ((ngx_uint_t) lcf->alias == alias) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "\"%s\" directive is duplicate",
- cmd->name.data);
+ "\"%V\" directive is duplicate",
+ &cmd->name);
} else {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "\"%s\" directive is duplicate, "
+ "\"%V\" directive is duplicate, "
"\"%s\" directive is specified before",
- cmd->name.data, lcf->alias ? "alias" : "root");
+ &cmd->name, lcf->alias ? "alias" : "root");
}
return NGX_CONF_ERROR;
@@ -1708,7 +1700,7 @@ static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (value[i].data[0] == '=') {
if (i == 1) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid value \"%s\"", value[i].data);
+ "invalid value \"%V\"", &value[i]);
return NGX_CONF_ERROR;
}
@@ -1716,7 +1708,7 @@ static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (overwrite == NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid value \"%s\"", value[i].data);
+ "invalid value \"%V\"", value[i]);
return NGX_CONF_ERROR;
}
@@ -1735,14 +1727,14 @@ static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
err->status = ngx_atoi(value[i].data, value[i].len);
if (err->status == NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid value \"%s\"", value[i].data);
+ "invalid value \"%V\"", &value[i]);
return NGX_CONF_ERROR;
}
if (err->status < 400 || err->status > 599) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "value \"%s\" must be between 400 and 599",
- value[i].data);
+ "value \"%V\" must be between 400 and 599",
+ &value[i]);
return NGX_CONF_ERROR;
}
diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c
index acd8dbd3b..8f920d240 100644
--- a/src/http/ngx_http_file_cache.c
+++ b/src/http/ngx_http_file_cache.c
@@ -168,7 +168,7 @@ int ngx_http_cache_update_file(ngx_http_request_t *r, ngx_http_cache_ctx_t *ctx,
err = ngx_errno;
-#if (WIN32)
+#if (NGX_WIN32)
if (err == NGX_EEXIST) {
if (ngx_win32_rename_file(temp_file, &ctx->file.name, r->pool)
== NGX_ERROR)
diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c
index 595dd59e3..3fa11086d 100644
--- a/src/http/ngx_http_header_filter.c
+++ b/src/http/ngx_http_header_filter.c
@@ -319,13 +319,6 @@ static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r)
if (r->headers_out.content_length_n >= 0) {
b->last = ngx_sprintf(b->last, "Content-Length: %O" CRLF,
r->headers_out.content_length_n);
-
-#if 0
- b->last += ngx_snprintf((char *) b->last,
- sizeof("Content-Length: ") + NGX_OFF_T_LEN + 2,
- "Content-Length: " OFF_T_FMT CRLF,
- r->headers_out.content_length_n);
-#endif
}
}
@@ -396,12 +389,6 @@ static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r)
{
b->last = ngx_sprintf(b->last, "Keep-Alive: timeout=%T" CRLF,
clcf->keepalive_header);
-#if 0
- b->last += ngx_snprintf((char *) b->last,
- sizeof("Keep-Alive: timeout=") + TIME_T_LEN + 2,
- "Keep-Alive: timeout=" TIME_T_FMT CRLF,
- clcf->keepalive_header);
-#endif
}
} else {
diff --git a/src/http/ngx_http_log_handler.c b/src/http/ngx_http_log_handler.c
index 9a1389d13..581a1ce65 100644
--- a/src/http/ngx_http_log_handler.c
+++ b/src/http/ngx_http_log_handler.c
@@ -133,7 +133,7 @@ ngx_int_t ngx_http_log_handler(ngx_http_request_t *r)
ngx_http_log_t *log;
ngx_http_log_op_t *op;
ngx_http_log_loc_conf_t *lcf;
-#if (WIN32)
+#if (NGX_WIN32)
u_long written;
#endif
@@ -160,7 +160,7 @@ ngx_int_t ngx_http_log_handler(ngx_http_request_t *r)
}
}
-#if (WIN32)
+#if (NGX_WIN32)
len += 2;
#else
len++;
@@ -186,7 +186,7 @@ ngx_int_t ngx_http_log_handler(ngx_http_request_t *r)
}
}
-#if (WIN32)
+#if (NGX_WIN32)
*p++ = CR; *p++ = LF;
WriteFile(log[l].file->fd, line, p - line, &written, NULL);
#else
@@ -211,12 +211,6 @@ static u_char *ngx_http_log_connection(ngx_http_request_t *r, u_char *buf,
uintptr_t data)
{
return ngx_sprintf(buf, "%ui", r->connection->number);
-
-#if 0
- return buf + ngx_snprintf((char *) buf, NGX_INT_T_LEN + 1,
- "%" NGX_UINT_T_FMT,
- r->connection->number);
-#endif
}
@@ -249,11 +243,6 @@ static u_char *ngx_http_log_msec(ngx_http_request_t *r, u_char *buf,
ngx_gettimeofday(&tv);
return ngx_sprintf(buf, "%l.%03l", tv.tv_sec, tv.tv_usec / 1000);
-
-#if 0
- return buf + ngx_snprintf((char *) buf, TIME_T_LEN + 5, "%ld.%03ld",
- tv.tv_sec, tv.tv_usec / 1000);
-#endif
}
@@ -274,11 +263,6 @@ static u_char *ngx_http_log_status(ngx_http_request_t *r, u_char *buf,
{
return ngx_sprintf(buf, "%ui",
r->err_status ? r->err_status : r->headers_out.status);
-
-#if 0
- return buf + ngx_snprintf((char *) buf, 4, "%" NGX_UINT_T_FMT,
- r->err_status ? r->err_status : r->headers_out.status);
-#endif
}
@@ -286,11 +270,6 @@ static u_char *ngx_http_log_length(ngx_http_request_t *r, u_char *buf,
uintptr_t data)
{
return ngx_sprintf(buf, "%O", r->connection->sent);
-
-#if 0
- return buf + ngx_snprintf((char *) buf, NGX_OFF_T_LEN + 1, OFF_T_FMT,
- r->connection->sent);
-#endif
}
@@ -298,10 +277,6 @@ static u_char *ngx_http_log_apache_length(ngx_http_request_t *r, u_char *buf,
uintptr_t data)
{
return ngx_sprintf(buf, "%O", r->connection->sent - r->header_size);
-#if 0
- return buf + ngx_snprintf((char *) buf, NGX_OFF_T_LEN + 1, OFF_T_FMT,
- r->connection->sent - r->header_size);
-#endif
}
@@ -470,9 +445,7 @@ static u_char *ngx_http_log_header_out(ngx_http_request_t *r, u_char *buf,
if (buf == NULL) {
return (u_char *) NGX_OFF_T_LEN;
}
- return buf + ngx_snprintf((char *) buf,
- NGX_OFF_T_LEN + 2, OFF_T_FMT,
- r->headers_out.content_length_n);
+ return ngx_sprintf(buf, "%O", r->headers_out.content_length_n);
}
if (data == offsetof(ngx_http_headers_out_t, last_modified)) {
diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c
index e70a6ea93..bfe5efb17 100644
--- a/src/http/ngx_http_parse.c
+++ b/src/http/ngx_http_parse.c
@@ -199,7 +199,7 @@ ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
}
break;
- /* check "/.", "//", and "%" in URI */
+ /* check "/.", "//", "%", and "\" (Win32) in URI */
case sw_after_slash_in_uri:
switch (ch) {
case CR:
@@ -224,6 +224,11 @@ ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
r->quoted_uri = 1;
state = sw_uri;
break;
+#if (NGX_WIN32)
+ case '\\':
+ r->complex_uri = 1;
+ break;
+#endif
case '/':
r->complex_uri = 1;
break;
@@ -237,7 +242,7 @@ ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
}
break;
- /* check "/" and "%" in URI */
+ /* check "/", "%" and "\" (Win32) in URI */
case sw_check_uri:
switch (ch) {
case CR:
@@ -257,6 +262,12 @@ ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
case '.':
r->uri_ext = p;
break;
+#if (NGX_WIN32)
+ case '\\':
+ r->complex_uri = 1;
+ state = sw_after_slash_in_uri;
+ break;
+#endif
case '/':
r->uri_ext = NULL;
state = sw_after_slash_in_uri;
@@ -657,7 +668,7 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
sw_slash,
sw_dot,
sw_dot_dot,
-#if (WIN32)
+#if (NGX_WIN32)
sw_dot_dot_dot,
#endif
sw_quoted,
@@ -671,17 +682,42 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
p = r->uri_start;
u = r->uri.data;
r->uri_ext = NULL;
+ r->args_start = NULL;
ch = *p++;
- while (p < r->uri_start + r->uri.len + 1) {
+ while (p < r->uri_start + r->uri.len + 1 && r->args_start == NULL) {
+
+ /*
+ * we use "ch = *p++" inside the cycle but this operation is safe
+ * because after the URI there is always at least one charcter:
+ * the line feed
+ */
ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "s:%d in:'%x:%c', out:'%c'", state, ch, ch, *u);
+ "s:%d in:'%Xd:%c', out:'%c'", state, ch, ch, *u);
switch (state) {
case sw_usual:
switch(ch) {
+#if (NGX_WIN32)
+ case '\\':
+ r->uri_ext = NULL;
+
+ if (p == r->uri_start + r->uri.len) {
+
+ /*
+ * we omit the last "\" to cause redirect because
+ * the browsers do not treat "\" as "/" in relative URL path
+ */
+
+ break;
+ }
+
+ state = sw_slash;
+ *u++ = '/';
+ break;
+#endif
case '/':
r->uri_ext = NULL;
state = sw_slash;
@@ -691,6 +727,9 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
quoted_state = state;
state = sw_quoted;
break;
+ case '?':
+ r->args_start = p;
+ break;
case '.':
r->uri_ext = u + 1;
default:
@@ -702,6 +741,10 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
case sw_slash:
switch(ch) {
+#if (NGX_WIN32)
+ case '\\':
+ break;
+#endif
case '/':
break;
case '.':
@@ -722,6 +765,10 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
case sw_dot:
switch(ch) {
+#if (NGX_WIN32)
+ case '\\':
+ /* fall through */
+#endif
case '/':
state = sw_slash;
u--;
@@ -744,6 +791,10 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
case sw_dot_dot:
switch(ch) {
+#if (NGX_WIN32)
+ case '\\':
+ /* fall through */
+#endif
case '/':
state = sw_slash;
u -= 4;
@@ -758,7 +809,7 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
quoted_state = state;
state = sw_quoted;
break;
-#if (WIN32)
+#if (NGX_WIN32)
case '.':
state = sw_dot_dot_dot;
*u++ = ch;
@@ -772,9 +823,10 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
ch = *p++;
break;
-#if (WIN32)
+#if (NGX_WIN32)
case sw_dot_dot_dot:
switch(ch) {
+ case '\\':
case '/':
state = sw_slash;
u -= 5;
@@ -857,12 +909,7 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
if (r->uri_ext) {
r->exten.len = u - r->uri_ext;
-
- if (!(r->exten.data = ngx_palloc(r->pool, r->exten.len + 1))) {
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- ngx_cpystrn(r->exten.data, r->uri_ext, r->exten.len + 1);
+ r->exten.data = r->uri_ext;
}
r->uri_ext = NULL;
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index d78a779ca..a2cf1a025 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -34,24 +34,22 @@ static void ngx_http_lingering_close_handler(ngx_event_t *ev);
static void ngx_http_client_error(ngx_http_request_t *r,
int client_error, int error);
-static size_t ngx_http_log_error(void *data, char *buf, size_t len);
+static u_char *ngx_http_log_error(void *data, u_char *buf, size_t len);
/* NGX_HTTP_PARSE_... errors */
static char *client_header_errors[] = {
- "client %s sent invalid method",
- "client %s sent invalid request",
- "client %s sent too long URI",
- "client %s sent invalid method in HTTP/0.9 request",
-
- "client %s sent invalid header, URL: %s",
- "client %s sent too long header line, URL: %s",
- "client %s sent HTTP/1.1 request without \"Host\" header, URL: %s",
- "client %s sent invalid \"Content-Length\" header, URL: %s",
- "client %s sent POST method without \"Content-Length\" header, URL: %s",
- "client %s sent plain HTTP request to HTTPS port, URL: %s",
- "client %s sent invalid \"Host\" header \"%s\", URL: %s"
+ "client %V sent invalid method \"%V\"",
+ "client %V sent invalid request \"%V\"",
+ "client %V sent too long URI in request \"%V\"",
+ "client %V sent invalid method in HTTP/0.9 request \"%V\"",
+
+ "client %V sent invalid header, URL: \"%V\"",
+ "client %V sent too long header line, URL: \"%V\"",
+ "client %V sent HTTP/1.1 request without \"Host\" header, URL: \"%V\"",
+ "client %V sent invalid \"Content-Length\" header, URL: \"%V\"",
+ "client %V sent POST method without \"Content-Length\" header, URL: \"%V\"",
};
@@ -105,14 +103,15 @@ void ngx_http_init_connection(ngx_connection_t *c)
ngx_event_t *rev;
ngx_http_log_ctx_t *ctx;
- if (!(ctx = ngx_pcalloc(c->pool, sizeof(ngx_http_log_ctx_t)))) {
+ if (!(ctx = ngx_palloc(c->pool, sizeof(ngx_http_log_ctx_t)))) {
ngx_http_close_connection(c);
return;
}
ctx->connection = c->number;
- ctx->client = c->addr_text.data;
+ ctx->client = &c->addr_text;
ctx->action = "reading client request line";
+ ctx->request = NULL;
c->log->data = ctx;
c->log->handler = ngx_http_log_error;
c->log_error = NGX_ERROR_INFO;
@@ -278,7 +277,7 @@ static void ngx_http_init_request(ngx_event_t *rev)
* AcceptEx() already gave this address.
*/
-#if (WIN32)
+#if (NGX_WIN32)
if (c->local_sockaddr) {
r->in_addr =
((struct sockaddr_in *) c->local_sockaddr)->sin_addr.s_addr;
@@ -295,7 +294,7 @@ static void ngx_http_init_request(ngx_event_t *rev)
r->in_addr = addr_in.sin_addr.s_addr;
-#if (WIN32)
+#if (NGX_WIN32)
}
#endif
@@ -428,9 +427,9 @@ static void ngx_http_init_request(ngx_event_t *rev)
static void ngx_http_ssl_handshake(ngx_event_t *rev)
{
- int n;
- ngx_int_t rc;
u_char buf[1];
+ ssize_t n;
+ ngx_int_t rc;
ngx_connection_t *c;
ngx_http_request_t *r;
@@ -454,7 +453,7 @@ static void ngx_http_ssl_handshake(ngx_event_t *rev)
if (n == 1) {
if (buf[0] == 0x80 /* SSLv2 */ || buf[0] == 0x16 /* SSLv3/TLSv1 */) {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, rev->log, 0,
- "https ssl handshake: 0x%X", buf[0]);
+ "https ssl handshake: 0x%02Xd", buf[0]);
c->recv = ngx_ssl_recv;
c->send_chain = ngx_ssl_send_chain;
@@ -488,7 +487,6 @@ static void ngx_http_ssl_handshake(ngx_event_t *rev)
static void ngx_http_process_request_line(ngx_event_t *rev)
{
- u_char *p;
ssize_t n;
ngx_int_t rc, rv;
ngx_connection_t *c;
@@ -524,21 +522,9 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
/* the request line has been parsed successfully */
- /* copy unparsed URI */
-
- r->unparsed_uri.len = r->uri_end - r->uri_start;
- r->unparsed_uri.data = ngx_palloc(r->pool, r->unparsed_uri.len + 1);
- if (r->unparsed_uri.data == NULL) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- ngx_http_close_connection(c);
- return;
- }
-
- ngx_cpystrn(r->unparsed_uri.data, r->uri_start,
- r->unparsed_uri.len + 1);
-
+ r->request_line.len = r->request_end - r->request_start;
+ r->request_line.data = r->request_start;
- /* copy URI */
if (r->args_start) {
r->uri.len = r->args_start - 1 - r->uri_start;
@@ -546,13 +532,14 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
r->uri.len = r->uri_end - r->uri_start;
}
- if (!(r->uri.data = ngx_palloc(r->pool, r->uri.len + 1))) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- ngx_http_close_connection(c);
- return;
- }
-
if (r->complex_uri || r->quoted_uri) {
+
+ if (!(r->uri.data = ngx_palloc(r->pool, r->uri.len + 1))) {
+ ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
+ ngx_http_close_connection(c);
+ return;
+ }
+
rc = ngx_http_parse_complex_uri(r);
if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) {
@@ -562,74 +549,55 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
}
if (rc != NGX_OK) {
- r->request_line.len = r->request_end - r->request_start;
- r->request_line.data = r->request_start;
-
ngx_http_client_error(r, rc, NGX_HTTP_BAD_REQUEST);
return;
}
} else {
- ngx_cpystrn(r->uri.data, r->uri_start, r->uri.len + 1);
+ r->uri.data = r->uri_start;
}
+ r->unparsed_uri.len = r->uri_end - r->uri_start;
+ r->unparsed_uri.data = r->uri_start;
- 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';
if (r->method == 0) {
r->method_name.len = r->method_end - r->request_start + 1;
r->method_name.data = r->request_line.data;
}
- if (r->uri_ext) {
-
- /* copy URI extention */
+ if (r->uri_ext) {
if (r->args_start) {
r->exten.len = r->args_start - 1 - r->uri_ext;
} else {
r->exten.len = r->uri_end - r->uri_ext;
}
- if (!(r->exten.data = ngx_palloc(r->pool, r->exten.len + 1))) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- ngx_http_close_connection(c);
- return;
- }
-
- ngx_cpystrn(r->exten.data, r->uri_ext, r->exten.len + 1);
+ r->exten.data = r->uri_ext;
}
- if (r->args_start && r->uri_end > r->args_start) {
-
- /* copy URI arguments */
+ if (r->args_start && r->uri_end > r->args_start) {
r->args.len = r->uri_end - r->args_start;
-
- if (!(r->args.data = ngx_palloc(r->pool, r->args.len + 1))) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- ngx_http_close_connection(c);
- return;
- }
-
- ngx_cpystrn(r->args.data, r->args_start, r->args.len + 1);
+ r->args.data = r->args_start;
}
+
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http request line: \"%s\"", r->request_line.data);
+ "http request line: \"%V\"", &r->request_line);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http uri: \"%s\"", r->uri.data);
+ "http uri: \"%V\"", &r->uri);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http args: \"%s\"",
- r->args.data ? r->args.data : (u_char *) "");
+ "http args: \"%V\"", &r->args);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http exten: \"%s\"",
- r->exten.data ? r->exten.data : (u_char *) "");
+ "http exten: \"%V\"", &r->exten);
+
+ ctx = c->log->data;
+ ctx->request = r;
if (r->http_version < NGX_HTTP_VERSION_10) {
rev->event_handler = ngx_http_block_read;
@@ -655,10 +623,7 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
return;
}
-
- ctx = c->log->data;
ctx->action = "reading client request headers";
- ctx->url = r->unparsed_uri.data;
rev->event_handler = ngx_http_process_request_headers;
ngx_http_process_request_headers(rev);
@@ -669,6 +634,9 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
/* there was error while a request line parsing */
+ ngx_http_client_error(r, rc, NGX_HTTP_BAD_REQUEST);
+
+#if 0
for (p = r->request_start; p < r->header_in->last; p++) {
if (*p == CR || *p == LF) {
break;
@@ -686,6 +654,8 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
(rc == NGX_HTTP_PARSE_INVALID_METHOD) ?
NGX_HTTP_NOT_IMPLEMENTED:
NGX_HTTP_BAD_REQUEST);
+#endif
+
return;
}
@@ -811,8 +781,8 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
}
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http header: \"%s: %s\"",
- h->key.data, h->value.data);
+ "http header: \"%V: %V\"",
+ &h->key, &h->value);
continue;
@@ -973,7 +943,7 @@ static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r,
b = hc->free[--hc->nfree];
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http large header free: " PTR_FMT " " SIZE_T_FMT,
+ "http large header free: %p %uz",
b->pos, b->end - b->last);
} else if (hc->nbusy < cscf->large_client_header_buffers.num) {
@@ -993,7 +963,7 @@ static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r,
}
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http large header alloc: " PTR_FMT " " SIZE_T_FMT,
+ "http large header alloc: %p %uz",
b->pos, b->end - b->last);
} else {
@@ -1095,7 +1065,7 @@ static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r)
for (i = 0; i < r->virtual_names->nelts; i++) {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "server name: %s", name[i].name.data);
+ "server name: %V", &name[i].name);
if (name[i].wildcard) {
if (r->headers_in.host_name_len <= name[i].name.len) {
@@ -1579,7 +1549,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "set http keepalive handler");
- ctx = (ngx_http_log_ctx_t *) c->log->data;
+ ctx = c->log->data;
ctx->action = "closing request";
hc = r->http_connection;
@@ -1677,7 +1647,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
b->last = b->start;
}
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc free: " PTR_FMT " %d",
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc free: %p %d",
hc->free, hc->nfree);
if (hc->free) {
@@ -1689,7 +1659,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
hc->nfree = 0;
}
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc busy: " PTR_FMT " %d",
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc busy: %p %d",
hc->busy, hc->nbusy);
if (hc->busy) {
@@ -1785,8 +1755,9 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev)
if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
if (rev->pending_eof) {
+ rev->log->handler = NULL;
ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno,
- "kevent() reported that client %s closed "
+ "kevent() reported that client %V closed "
"keepalive connection", ctx->client);
ngx_http_close_connection(c);
return;
@@ -1841,7 +1812,7 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev)
if (n == 0) {
ngx_log_error(NGX_LOG_INFO, c->log, ngx_socket_errno,
- "client %s closed keepalive connection", ctx->client);
+ "client %V closed keepalive connection", ctx->client);
ngx_http_close_connection(c);
return;
}
@@ -2055,7 +2026,7 @@ void ngx_http_close_request(ngx_http_request_t *r, int error)
if (r->file.fd != NGX_INVALID_FILE) {
if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
- ngx_close_file_n " \"%s\" failed", r->file.name.data);
+ ngx_close_file_n " \"%V\" failed", &r->file.name);
}
}
@@ -2067,8 +2038,8 @@ void ngx_http_close_request(ngx_http_request_t *r, int error)
== NGX_FILE_ERROR)
{
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
- ngx_close_file_n " deleted file \"%s\" failed",
- r->request_body->temp_file->file.name.data);
+ ngx_close_file_n " deleted file \"%V\" failed",
+ &r->request_body->temp_file->file.name);
}
}
@@ -2088,9 +2059,9 @@ void ngx_http_close_request(ngx_http_request_t *r, int error)
}
}
- /* ctx->url was allocated from r->pool */
+ /* the variuos request strings were allocated from r->pool */
ctx = log->data;
- ctx->url = NULL;
+ ctx->request = NULL;
r->request_line.len = 0;
@@ -2148,6 +2119,7 @@ void ngx_http_close_connection(ngx_connection_t *c)
static void ngx_http_client_error(ngx_http_request_t *r,
int client_error, int error)
{
+ u_char *p;
ngx_http_log_ctx_t *ctx;
ngx_http_core_srv_conf_t *cscf;
@@ -2164,13 +2136,15 @@ static void ngx_http_client_error(ngx_http_request_t *r,
r->connection->log->handler = NULL;
- if (ctx->url) {
+ if (ctx->request) {
+
switch (client_error) {
case NGX_HTTP_PARSE_INVALID_HOST:
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR],
- ctx->client, r->headers_in.host->value.data, ctx->url);
+ "client %V sent invalid \"Host\" header \"%V\", URL: \"%V\"",
+ ctx->client, &r->headers_in.host->value,
+ &ctx->request->unparsed_uri);
error = NGX_HTTP_INVALID_HOST;
@@ -2186,24 +2160,49 @@ static void ngx_http_client_error(ngx_http_request_t *r,
case NGX_HTTP_PARSE_HTTP_TO_HTTPS:
error = NGX_HTTP_TO_HTTPS;
+ if (ctx->request->headers_in.referer) {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "client %V sent plain HTTP request to HTTPS port, "
+ "URL: \"%V\", referrer \"%V\"",
+ ctx->client, &ctx->request->unparsed_uri,
+ &ctx->request->headers_in.referer->value);
- /* fall through */
+ } else {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "client %V sent plain HTTP request to HTTPS port, "
+ "URL: \"%V\"", ctx->client, &ctx->request->unparsed_uri);
+ }
+
+ break;
default:
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR],
- ctx->client, ctx->url);
+ ctx->client, &ctx->request->unparsed_uri);
}
} else {
+
if (error == NGX_HTTP_REQUEST_URI_TOO_LARGE) {
r->request_line.len = r->header_in->end - r->request_start;
r->request_line.data = r->request_start;
+
+ } else {
+ if (r->request_line.data == NULL) {
+ for (p = r->request_start; p < r->header_in->last; p++) {
+ if (*p == CR || *p == LF) {
+ break;
+ }
+ }
+
+ r->request_line.len = p - r->request_start;
+ r->request_line.data = r->request_start;
+ }
}
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR],
- ctx->client);
+ ctx->client, &r->request_line);
}
r->connection->log->handler = ngx_http_log_error;
@@ -2212,20 +2211,35 @@ static void ngx_http_client_error(ngx_http_request_t *r,
}
-static size_t ngx_http_log_error(void *data, char *buf, size_t len)
+static u_char *ngx_http_log_error(void *data, u_char *buf, size_t len)
{
ngx_http_log_ctx_t *ctx = data;
- if (ctx->action && ctx->url) {
- return ngx_snprintf(buf, len, " while %s, client: %s, URL: %s",
- ctx->action, ctx->client, ctx->url);
+ u_char *p;
- } else if (ctx->action == NULL && ctx->url) {
- return ngx_snprintf(buf, len, ", client: %s, URL: %s",
- ctx->client, ctx->url);
+ p = buf;
- } else {
- return ngx_snprintf(buf, len, " while %s, client: %s",
- ctx->action, ctx->client);
+ if (ctx->action) {
+ p = ngx_snprintf(p, len, " while %s", ctx->action);
+ len -= p - buf;
}
+
+ p = ngx_snprintf(p, len, ", client: %V", ctx->client);
+
+ if (ctx->request == NULL) {
+ return p;
+ }
+
+ len -= p - buf;
+
+ p = ngx_snprintf(p, len, ", URL: \"%V\"", &ctx->request->unparsed_uri);
+
+ if (ctx->request->headers_in.referer == NULL) {
+ return p;
+ }
+
+ len -= p - buf;
+
+ return ngx_snprintf(p, len, ", referrer: \"%V\"",
+ &ctx->request->headers_in.referer->value);
}
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index f1b957b6f..31b1187b0 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -41,8 +41,9 @@
#define NGX_HTTP_PARSE_NO_HOST_HEADER 16
#define NGX_HTTP_PARSE_INVALID_CL_HEADER 17
#define NGX_HTTP_PARSE_POST_WO_CL_HEADER 18
-#define NGX_HTTP_PARSE_HTTP_TO_HTTPS 19
-#define NGX_HTTP_PARSE_INVALID_HOST 20
+
+#define NGX_HTTP_PARSE_INVALID_HOST 19
+#define NGX_HTTP_PARSE_HTTP_TO_HTTPS 20
#define NGX_HTTP_OK 200
diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c
index ee8e3685b..c9ec6fa07 100644
--- a/src/http/ngx_http_request_body.c
+++ b/src/http/ngx_http_request_body.c
@@ -148,7 +148,7 @@ static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r)
n = c->recv(c, r->request_body->buf->last, size);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http client request body recv " SIZE_T_FMT, n);
+ "http client request body recv %z", n);
if (n == NGX_AGAIN) {
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
@@ -184,7 +184,7 @@ static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r)
}
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http client request body rest " SIZE_T_FMT,
+ "http client request body rest %uz",
r->request_body->rest);
if (r->request_body->rest) {
diff --git a/src/http/ngx_http_script.c b/src/http/ngx_http_script.c
index 3a26d65de..51a1b47e2 100644
--- a/src/http/ngx_http_script.c
+++ b/src/http/ngx_http_script.c
@@ -40,15 +40,11 @@ char *ngx_http_script_request_line(ngx_http_request_t *r, char *p, size_t len)
char *ngx_http_script_status(ngx_http_request_t *r, char *p, size_t len)
{
- p += ngx_snprintf(p, len, "%d", r->headers_out.status);
-
- return p;
+ return ngx_snprintf(p, len, "%d", r->headers_out.status);
}
char *ngx_http_script_sent(ngx_http_request_t *r, char *p, size_t len)
{
- p += ngx_snprintf(p, len, OFF_FMT, r->connection->sent);
-
- return p;
+ return ngx_sprintf(p, "%O", r->connection->sent);
}
diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c
index 37e0f3fab..67f686267 100644
--- a/src/http/ngx_http_write_filter.c
+++ b/src/http/ngx_http_write_filter.c
@@ -69,6 +69,12 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
for (cl = ctx->out; cl; cl = cl->next) {
ll = &cl->next;
+#if 1
+ if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) {
+ ngx_debug_point();
+ }
+#endif
+
size += ngx_buf_size(cl->buf);
if (cl->buf->flush || cl->buf->recycled) {
@@ -83,10 +89,20 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
/* add the new chain to the existent one */
for (ln = in; ln; ln = ln->next) {
- ngx_alloc_link_and_set_buf(cl, ln->buf, r->pool, NGX_ERROR);
+ if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ return NGX_ERROR;
+ }
+
+ cl->buf = ln->buf;
*ll = cl;
ll = &cl->next;
+#if 1
+ if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) {
+ ngx_debug_point();
+ }
+#endif
+
size += ngx_buf_size(cl->buf);
if (cl->buf->flush || cl->buf->recycled) {
@@ -98,11 +114,12 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
}
+ *ll = NULL;
+
c = r->connection;
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http write filter: l:%d f:" OFF_T_FMT " s:" OFF_T_FMT,
- last, flush, size);
+ "http write filter: l:%d f:%O s:%O", last, flush, size);
clcf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
ngx_http_core_module);
@@ -125,6 +142,9 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
if (!last) {
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
"the http output chain is empty");
+
+ ngx_debug_point();
+
return NGX_ERROR;
}
return NGX_OK;
@@ -136,7 +156,7 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
clcf->limit_rate ? clcf->limit_rate: OFF_T_MAX_VALUE);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http write filter %X", chain);
+ "http write filter %p", chain);
if (clcf->limit_rate) {
sent = c->sent - sent;
diff --git a/src/os/unix/ngx_aio_write_chain.c b/src/os/unix/ngx_aio_write_chain.c
index b8c13356c..4d45f079a 100644
--- a/src/os/unix/ngx_aio_write_chain.c
+++ b/src/os/unix/ngx_aio_write_chain.c
@@ -13,11 +13,10 @@
ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in,
off_t limit)
{
- int n;
u_char *buf, *prev;
off_t send, sent;
size_t len;
- ssize_t size;
+ ssize_t n, size;
ngx_err_t err;
ngx_chain_t *cl;
@@ -63,7 +62,7 @@ ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in,
n = ngx_aio_write(c, buf, len);
- ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "aio_write: %d", n);
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "aio_write: %z", n);
if (n == NGX_ERROR) {
return NGX_CHAIN_ERROR;
@@ -75,7 +74,7 @@ ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in,
}
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "aio_write sent: " OFF_T_FMT, c->sent);
+ "aio_write sent: %O", c->sent);
for (cl = in; cl; cl = cl->next) {
diff --git a/src/os/unix/ngx_alloc.c b/src/os/unix/ngx_alloc.c
index dc3609206..7ec4f87c3 100644
--- a/src/os/unix/ngx_alloc.c
+++ b/src/os/unix/ngx_alloc.c
@@ -17,11 +17,10 @@ void *ngx_alloc(size_t size, ngx_log_t *log)
if (!(p = malloc(size))) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
- "malloc() " SIZE_T_FMT " bytes failed", size);
+ "malloc() %uz bytes failed", size);
}
- ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0,
- "malloc: " PTR_FMT ":" SIZE_T_FMT, p, size);
+ ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, "malloc: %p:%uz", p, size);
return p;
}
@@ -49,12 +48,12 @@ void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
if (posix_memalign(&p, alignment, size) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
- "posix_memalign() " SIZE_T_FMT " bytes aligned to "
- SIZE_T_FMT " failed", size, alignment);
+ "posix_memalign() %uz bytes aligned to %uz failed",
+ size, alignment);
}
ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0,
- "posix_memalign: " PTR_FMT ":" SIZE_T_FMT, p, size);
+ "posix_memalign: %p:%uz", p, size);
return p;
}
@@ -67,12 +66,12 @@ void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
if (!(p = memalign(alignment, size))) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
- "memalign() " SIZE_T_FMT " bytes aligned to "
- SIZE_T_FMT " failed", size, alignment);
+ "memalign() %uz bytes aligned to %uz failed",
+ size, alignment);
}
ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0,
- "memalign: " PTR_FMT ":" SIZE_T_FMT, p, size);
+ "memalign: %p:%uz", p, size);
return p;
}
diff --git a/src/os/unix/ngx_channel.c b/src/os/unix/ngx_channel.c
index 3d09d68bb..5c5a5e10b 100644
--- a/src/os/unix/ngx_channel.c
+++ b/src/os/unix/ngx_channel.c
@@ -120,9 +120,14 @@ ngx_int_t ngx_read_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size,
return NGX_ERROR;
}
+ if (n == 0) {
+ ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, 0, "recvmsg() returned zero");
+ return NGX_ERROR;
+ }
+
if ((size_t) n < sizeof(ngx_channel_t)) {
ngx_log_error(NGX_LOG_ALERT, log, 0,
- "recvmsg() returned not enough data");
+ "recvmsg() returned not enough data: %uz", n);
return NGX_ERROR;
}
diff --git a/src/os/unix/ngx_errno.c b/src/os/unix/ngx_errno.c
index 0c93d23a1..ced0eafcb 100644
--- a/src/os/unix/ngx_errno.c
+++ b/src/os/unix/ngx_errno.c
@@ -10,32 +10,29 @@
#if (NGX_STRERROR_R)
-ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size)
+u_char *ngx_strerror_r(int err, u_char *errstr, size_t size)
{
- size_t len;
-
if (size == 0) {
return 0;
}
errstr[0] = '\0';
- strerror_r(err, errstr, size);
+ strerror_r(err, (char *) errstr, size);
- for (len = 0; len < size; len++) {
- if (errstr[len] == '\0') {
- break;
- }
+ while (*errstr && size) {
+ errstr++;
+ size--;
}
- return len;
+ return errstr;
}
#elif (NGX_GNU_STRERROR_R)
/* Linux strerror_r() */
-ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size)
+u_char *ngx_strerror_r(int err, u_char *errstr, size_t size)
{
char *str;
size_t len;
@@ -46,20 +43,18 @@ ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size)
errstr[0] = '\0';
- str = strerror_r(err, errstr, size);
+ str = strerror_r(err, (char *) errstr, size);
- if (str != errstr) {
- return ngx_cpystrn((u_char *) errstr, (u_char *) str, size)
- - (u_char *) errstr;
+ if (str != (char *) errstr) {
+ return ngx_cpystrn(errstr, (u_char *) str, size);
}
- for (len = 0; len < size; len++) {
- if (errstr[len] == '\0') {
- break;
- }
+ while (*errstr && size) {
+ errstr++;
+ size--;
}
- return len;
+ return errstr;
}
#endif
diff --git a/src/os/unix/ngx_errno.h b/src/os/unix/ngx_errno.h
index cc9b1d19f..9a392f822 100644
--- a/src/os/unix/ngx_errno.h
+++ b/src/os/unix/ngx_errno.h
@@ -47,14 +47,14 @@ typedef int ngx_err_t;
#if (HAVE_STRERROR_R || HAVE_GNU_STRERROR_R)
-ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size);
+u_char *ngx_strerror_r(int err, u_char *errstr, size_t size);
#else
/* Solaris has threads-safe strerror() */
#define ngx_strerror_r(err, errstr, size) \
- (char *) ngx_cpystrn(errstr, strerror(err), size) - (errstr)
+ ngx_cpystrn(errstr, (u_char *) strerror(err), size)
#endif
diff --git a/src/os/unix/ngx_files.c b/src/os/unix/ngx_files.c
index da75ba022..7bf5ad124 100644
--- a/src/os/unix/ngx_files.c
+++ b/src/os/unix/ngx_files.c
@@ -13,7 +13,7 @@ ssize_t ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
ssize_t n;
ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
- "read: %d, %X, %d, " OFF_T_FMT, file->fd, buf, size, offset);
+ "read: %d, %p, %uz, %O", file->fd, buf, size, offset);
#if (NGX_PREAD)
@@ -57,6 +57,9 @@ ssize_t ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
{
ssize_t n;
+ ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
+ "write: %d, %p, %uz, %O", file->fd, buf, size, offset);
+
#if (NGX_PWRITE)
n = pwrite(file->fd, buf, size, offset);
@@ -68,7 +71,7 @@ ssize_t ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
if ((size_t) n != size) {
ngx_log_error(NGX_LOG_CRIT, file->log, 0,
- "pwrite() has written only %d of %d", n, size);
+ "pwrite() has written only %z of %uz", n, size);
return NGX_ERROR;
}
@@ -92,7 +95,7 @@ ssize_t ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
if ((size_t) n != size) {
ngx_log_error(NGX_LOG_CRIT, file->log, 0,
- "write() has written only %d of %d", n, size);
+ "write() has written only %z of %uz", n, size);
return NGX_ERROR;
}
@@ -120,17 +123,19 @@ int ngx_open_tempfile(u_char *name, ngx_uint_t persistent)
}
+#define NGX_IOVS 8
+
ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl,
off_t offset, ngx_pool_t *pool)
{
u_char *prev;
size_t size;
ssize_t n;
- struct iovec *iov;
ngx_err_t err;
- ngx_array_t io;
+ ngx_array_t vec;
+ struct iovec *iov, iovs[NGX_IOVS];
- /* use pwrite() if there's the only buf in a chain */
+ /* use pwrite() if there is the only buf in a chain */
if (cl->next == NULL) {
return ngx_write_file(file, cl->buf->pos,
@@ -138,61 +143,74 @@ ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl,
offset);
}
- prev = NULL;
- iov = NULL;
- size = 0;
+ vec.elts = iovs;
+ vec.size = sizeof(struct iovec);
+ vec.nalloc = NGX_IOVS;
+ vec.pool = pool;
+
+ do {
+ prev = NULL;
+ iov = NULL;
+ size = 0;
- ngx_init_array(io, pool, 10, sizeof(struct iovec), NGX_ERROR);
+ vec.nelts = 0;
- /* create the iovec and coalesce the neighbouring bufs */
+ /* create the iovec and coalesce the neighbouring bufs */
- while (cl) {
- if (prev == cl->buf->pos) {
- iov->iov_len += cl->buf->last - cl->buf->pos;
+ while (cl && vec.nelts < IOV_MAX) {
+ if (prev == cl->buf->pos) {
+ iov->iov_len += cl->buf->last - cl->buf->pos;
- } else {
- ngx_test_null(iov, ngx_push_array(&io), NGX_ERROR);
- iov->iov_base = (void *) cl->buf->pos;
- iov->iov_len = cl->buf->last - cl->buf->pos;
+ } else {
+ if (!(iov = ngx_array_push(&vec))) {
+ return NGX_ERROR;
+ }
+
+ iov->iov_base = (void *) cl->buf->pos;
+ iov->iov_len = cl->buf->last - cl->buf->pos;
+ }
+
+ size += cl->buf->last - cl->buf->pos;
+ prev = cl->buf->last;
+ cl = cl->next;
}
- size += cl->buf->last - cl->buf->pos;
- prev = cl->buf->last;
- cl = cl->next;
- }
+ /* use pwrite() if there is the only iovec buffer */
- /* use pwrite() if there's the only iovec buffer */
+ if (vec.nelts == 1) {
+ iov = vec.elts;
+ return ngx_write_file(file, (u_char *) iov[0].iov_base,
+ iov[0].iov_len, offset);
+ }
- if (io.nelts == 1) {
- iov = io.elts;
- return ngx_write_file(file, (u_char *) iov[0].iov_base, iov[0].iov_len,
- offset);
- }
+ if (file->sys_offset != offset) {
+ if (lseek(file->fd, offset, SEEK_SET) == -1) {
+ ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
+ "lseek() failed");
+ return NGX_ERROR;
+ }
- if (file->sys_offset != offset) {
- if (lseek(file->fd, offset, SEEK_SET) == -1) {
- ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, "lseek() failed");
- return NGX_ERROR;
+ file->sys_offset = offset;
}
- file->sys_offset = offset;
- }
+ n = writev(file->fd, vec.elts, vec.nelts);
- n = writev(file->fd, io.elts, io.nelts);
+ if (n == -1) {
+ ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
+ "writev() failed");
+ return NGX_ERROR;
+ }
- if (n == -1) {
- ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, "writev() failed");
- return NGX_ERROR;
- }
+ if ((size_t) n != size) {
+ ngx_log_error(NGX_LOG_CRIT, file->log, 0,
+ "writev() has written only %z of %uz", n, size);
+ return NGX_ERROR;
+ }
- if ((size_t) n != size) {
- ngx_log_error(NGX_LOG_CRIT, file->log, 0,
- "writev() has written only %d of %d", n, size);
- return NGX_ERROR;
- }
+ file->sys_offset += n;
+ file->offset += n;
- file->sys_offset += n;
- file->offset += n;
+ } while (cl);
return n;
}
diff --git a/src/os/unix/ngx_freebsd_init.c b/src/os/unix/ngx_freebsd_init.c
index 39a057be9..faf8e9f1e 100644
--- a/src/os/unix/ngx_freebsd_init.c
+++ b/src/os/unix/ngx_freebsd_init.c
@@ -9,8 +9,8 @@
/* FreeBSD 3.0 at least */
-char ngx_freebsd_kern_ostype[20];
-char ngx_freebsd_kern_osrelease[20];
+char ngx_freebsd_kern_ostype[16];
+char ngx_freebsd_kern_osrelease[128];
int ngx_freebsd_kern_osreldate;
int ngx_freebsd_hw_ncpu;
int ngx_freebsd_net_inet_tcp_sendspace;
@@ -95,7 +95,12 @@ ngx_int_t ngx_os_init(ngx_log_t *log)
ngx_freebsd_kern_ostype, &size, NULL, 0) == -1) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
"sysctlbyname(kern.ostype) failed");
- return NGX_ERROR;
+
+ if (ngx_errno != NGX_ENOMEM) {
+ return NGX_ERROR;
+ }
+
+ ngx_freebsd_kern_ostype[size - 1] = '\0';
}
size = sizeof(ngx_freebsd_kern_osrelease);
@@ -103,7 +108,12 @@ ngx_int_t ngx_os_init(ngx_log_t *log)
ngx_freebsd_kern_osrelease, &size, NULL, 0) == -1) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
"sysctlbyname(kern.osrelease) failed");
- return NGX_ERROR;
+
+ if (ngx_errno != NGX_ENOMEM) {
+ return NGX_ERROR;
+ }
+
+ ngx_freebsd_kern_osrelease[size - 1] = '\0';
}
diff --git a/src/os/unix/ngx_freebsd_rfork_thread.c b/src/os/unix/ngx_freebsd_rfork_thread.c
index 774adb938..b64325bcd 100644
--- a/src/os/unix/ngx_freebsd_rfork_thread.c
+++ b/src/os/unix/ngx_freebsd_rfork_thread.c
@@ -21,9 +21,10 @@
* The SysV semop() is a cheap syscall, particularly if it has little sembuf's
* and does not use SEM_UNDO.
*
- * The condition variable implementation uses signal #64. The signal handler
- * is SIG_IGN so the kill() is a cheap syscall. The thread waits a signal
- * in kevent(). The use of the EVFILT_SIGNAL is safe since FreeBSD 4.7.
+ * The condition variable implementation uses the signal #64.
+ * The signal handler is SIG_IGN so the kill() is a cheap syscall.
+ * The thread waits a signal in kevent(). The use of the EVFILT_SIGNAL
+ * is safe since FreeBSD 4.10-STABLE.
*
* This threads implementation currently works on i386 (486+) and amd64
* platforms only.
@@ -114,15 +115,16 @@ void _spinunlock(ngx_atomic_t *lock)
#endif
-int ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg,
- ngx_log_t *log)
+ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg,
+ ngx_log_t *log)
{
- int id, err;
- char *stack, *stack_top;
+ ngx_pid_t id;
+ ngx_err_t err;
+ char *stack, *stack_top;
if (nthreads >= max_threads) {
ngx_log_error(NGX_LOG_CRIT, log, 0,
- "no more than %d threads can be created", max_threads);
+ "no more than %ui threads can be created", max_threads);
return NGX_ERROR;
}
@@ -133,20 +135,21 @@ int ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg,
if (stack == MAP_FAILED) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
- "mmap(" PTR_FMT ":" SIZE_T_FMT
- ", MAP_STACK) thread stack failed",
+ "mmap(%p:%uz, MAP_STACK) thread stack failed",
last_stack, usable_stack_size);
return NGX_ERROR;
}
if (stack != last_stack) {
- ngx_log_error(NGX_LOG_ALERT, log, 0, "stack address was changed");
+ ngx_log_error(NGX_LOG_ALERT, log, 0,
+ "stack %p address was changed to %p", last_stack, stack);
+ return NGX_ERROR;
}
stack_top = stack + usable_stack_size;
ngx_log_debug2(NGX_LOG_DEBUG_CORE, log, 0,
- "thread stack: " PTR_FMT "-" PTR_FMT, stack, stack_top);
+ "thread stack: %p-%p", stack, stack_top);
ngx_set_errno(0);
@@ -164,7 +167,7 @@ int ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg,
/ ngx_thread_stack_size;
tids[nthreads] = id;
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "rfork()ed thread: %d", id);
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "rfork()ed thread: %P", id);
}
return err;
@@ -205,30 +208,30 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle)
red_zone = ngx_freebsd_kern_usrstack - (size + rz_size);
ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
- "usrstack: " PTR_FMT " red zone: " PTR_FMT,
+ "usrstack: %p red zone: %p",
ngx_freebsd_kern_usrstack, red_zone);
zone = mmap(red_zone, rz_size, PROT_NONE, MAP_ANON, -1, 0);
if (zone == MAP_FAILED) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
- "mmap(" PTR_FMT ":" SIZE_T_FMT
- ", PROT_NONE, MAP_ANON) red zone failed",
+ "mmap(%p:%uz, PROT_NONE, MAP_ANON) red zone failed",
red_zone, rz_size);
return NGX_ERROR;
}
if (zone != red_zone) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
- "red zone address was changed");
+ "red zone %p address was changed to %p", red_zone, zone);
+ return NGX_ERROR;
}
- /* create the threads errno's array */
+ /* create the thread errno' array */
if (!(errnos = ngx_calloc(n * sizeof(int), cycle->log))) {
return NGX_ERROR;
}
- /* create the threads tids array */
+ /* create the thread tids array */
if (!(tids = ngx_calloc((n + 1) * sizeof(ngx_tid_t), cycle->log))) {
return NGX_ERROR;
@@ -236,7 +239,7 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle)
tids[0] = ngx_pid;
- /* create the threads tls's array */
+ /* create the thread tls' array */
ngx_tls = ngx_calloc(NGX_THREAD_KEYS_MAX * (n + 1) * sizeof(void *),
cycle->log);
@@ -274,7 +277,7 @@ ngx_tid_t ngx_thread_self()
}
-ngx_int_t ngx_thread_key_create(ngx_tls_key_t *key)
+ngx_err_t ngx_thread_key_create(ngx_tls_key_t *key)
{
if (nkeys >= NGX_THREAD_KEYS_MAX) {
return NGX_ENOMEM;
@@ -286,7 +289,7 @@ ngx_int_t ngx_thread_key_create(ngx_tls_key_t *key)
}
-ngx_int_t ngx_thread_set_tls(ngx_tls_key_t key, void *value)
+ngx_err_t ngx_thread_set_tls(ngx_tls_key_t key, void *value)
{
if (key >= NGX_THREAD_KEYS_MAX) {
return NGX_EINVAL;
@@ -297,7 +300,7 @@ ngx_int_t ngx_thread_set_tls(ngx_tls_key_t key, void *value)
}
-ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, uint flags)
+ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags)
{
ngx_mutex_t *m;
union semun op;
@@ -361,10 +364,10 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
#if (NGX_DEBUG)
if (try) {
ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0,
- "try lock mutex " PTR_FMT " lock:%X", m, m->lock);
+ "try lock mutex %p lock:%XD", m, m->lock);
} else {
ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0,
- "lock mutex " PTR_FMT " lock:%X", m, m->lock);
+ "lock mutex %p lock:%XD", m, m->lock);
}
#endif
@@ -395,7 +398,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
}
ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0,
- "mutex " PTR_FMT " lock:%X", m, m->lock);
+ "mutex %p lock:%XD", m, m->lock);
/*
* The mutex is locked so we increase a number
@@ -406,8 +409,8 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
if ((lock & ~NGX_MUTEX_LOCK_BUSY) > nthreads) {
ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno,
- "%d threads wait for mutex " PTR_FMT
- ", while only %d threads are available",
+ "%D threads wait for mutex %p, "
+ "while only %ui threads are available",
lock & ~NGX_MUTEX_LOCK_BUSY, m, nthreads);
return NGX_ERROR;
}
@@ -415,7 +418,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
if (ngx_atomic_cmp_set(&m->lock, old, lock)) {
ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0,
- "wait mutex " PTR_FMT " lock:%X", m, m->lock);
+ "wait mutex %p lock:%XD", m, m->lock);
/*
* The number of the waiting threads has been increased
@@ -430,14 +433,12 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
if (semop(m->semid, &op, 1) == -1) {
ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno,
- "semop() failed while waiting "
- "on mutex " PTR_FMT, m);
+ "semop() failed while waiting on mutex %p", m);
return NGX_ERROR;
}
ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0,
- "mutex waked up " PTR_FMT " lock:%X",
- m, m->lock);
+ "mutex waked up %p lock:%XD", m, m->lock);
tries = 0;
old = m->lock;
@@ -462,7 +463,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
if (tries++ > 1000) {
ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
- "mutex " PTR_FMT " is contested", m);
+ "mutex %p is contested", m);
/* the mutex is probably contested so we are giving up now */
@@ -474,7 +475,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
}
ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0,
- "mutex " PTR_FMT " is locked, lock:%X", m, m->lock);
+ "mutex %p is locked, lock:%XD", m, m->lock);
return NGX_OK;
}
@@ -493,7 +494,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
if (!(old & NGX_MUTEX_LOCK_BUSY)) {
ngx_log_error(NGX_LOG_ALERT, m->log, 0,
- "trying to unlock the free mutex " PTR_FMT, m);
+ "trying to unlock the free mutex %p", m);
return NGX_ERROR;
}
@@ -501,7 +502,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
#if 0
ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0,
- "unlock mutex " PTR_FMT " lock:%X", m, old);
+ "unlock mutex %p lock:%XD", m, old);
#endif
for ( ;; ) {
@@ -516,7 +517,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
if (m->semid == -1) {
ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
- "mutex " PTR_FMT " is unlocked", m);
+ "mutex %p is unlocked", m);
return NGX_OK;
}
@@ -546,7 +547,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
/* wake up the thread that waits on semaphore */
ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
- "wake up mutex " PTR_FMT "", m);
+ "wake up mutex %p", m);
op.sem_num = 0;
op.sem_op = 1;
@@ -554,8 +555,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
if (semop(m->semid, &op, 1) == -1) {
ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno,
- "semop() failed while waking up on mutex "
- PTR_FMT, m);
+ "semop() failed while waking up on mutex %p", m);
return NGX_ERROR;
}
@@ -566,7 +566,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
}
ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
- "mutex " PTR_FMT " is unlocked", m);
+ "mutex %p is unlocked", m);
return NGX_OK;
}
@@ -647,21 +647,20 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m)
}
ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0,
- "cv " PTR_FMT " wait, kq:%d, signo:%d",
- cv, cv->kq, cv->signo);
+ "cv %p wait, kq:%d, signo:%d", cv, cv->kq, cv->signo);
for ( ;; ) {
n = kevent(cv->kq, NULL, 0, &kev, 1, NULL);
ngx_log_debug2(NGX_LOG_DEBUG_CORE, cv->log, 0,
- "cv " PTR_FMT " kevent: %d", cv, n);
+ "cv %p kevent: %d", cv, n);
if (n == -1) {
err = ngx_errno;
ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT,
cv->log, ngx_errno,
- "kevent() failed while waiting condition variable "
- PTR_FMT, cv);
+ "kevent() failed while waiting condition variable %p",
+ cv);
if (err == NGX_EINTR) {
break;
@@ -673,7 +672,7 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m)
if (n == 0) {
ngx_log_error(NGX_LOG_ALERT, cv->log, 0,
"kevent() returned no events "
- "while waiting condition variable " PTR_FMT,
+ "while waiting condition variable %p",
cv);
continue;
}
@@ -681,7 +680,7 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m)
if (kev.filter != EVFILT_SIGNAL) {
ngx_log_error(NGX_LOG_ALERT, cv->log, 0,
"kevent() returned unexpected events: %d "
- "while waiting condition variable " PTR_FMT,
+ "while waiting condition variable %p",
kev.filter, cv);
continue;
}
@@ -689,7 +688,7 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m)
if (kev.ident != (uintptr_t) cv->signo) {
ngx_log_error(NGX_LOG_ALERT, cv->log, 0,
"kevent() returned unexpected signal: %d ",
- "while waiting condition variable " PTR_FMT,
+ "while waiting condition variable %p",
kev.ident, cv);
continue;
}
@@ -697,8 +696,7 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m)
break;
}
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0,
- "cv " PTR_FMT " is waked up", cv);
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is waked up", cv);
if (ngx_mutex_lock(m) == NGX_ERROR) {
return NGX_ERROR;
@@ -713,7 +711,7 @@ ngx_int_t ngx_cond_signal(ngx_cond_t *cv)
ngx_err_t err;
ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0,
- "cv " PTR_FMT " to signal " PID_T_FMT " %d",
+ "cv %p to signal %P %d",
cv, cv->tid, cv->signo);
if (kill(cv->tid, cv->signo) == -1) {
@@ -721,8 +719,7 @@ ngx_int_t ngx_cond_signal(ngx_cond_t *cv)
err = ngx_errno;
ngx_log_error(NGX_LOG_ALERT, cv->log, err,
- "kill() failed while signaling condition variable "
- PTR_FMT, cv);
+ "kill() failed while signaling condition variable %p", cv);
if (err == NGX_ESRCH) {
cv->tid = -1;
@@ -731,8 +728,7 @@ ngx_int_t ngx_cond_signal(ngx_cond_t *cv)
return NGX_ERROR;
}
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0,
- "cv " PTR_FMT " is signaled", cv);
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is signaled", cv);
return NGX_OK;
}
diff --git a/src/os/unix/ngx_freebsd_rfork_thread.h b/src/os/unix/ngx_freebsd_rfork_thread.h
index bef230a64..2af0adb80 100644
--- a/src/os/unix/ngx_freebsd_rfork_thread.h
+++ b/src/os/unix/ngx_freebsd_rfork_thread.h
@@ -18,7 +18,7 @@ typedef pid_t ngx_tid_t;
#define ngx_log_pid ngx_thread_self()
#define ngx_log_tid 0
-#define TID_T_FMT PID_T_FMT
+#define NGX_TID_T_FMT "%P"
#define NGX_MUTEX_LIGHT 1
@@ -91,10 +91,10 @@ typedef ngx_uint_t ngx_tls_key_t;
extern void **ngx_tls;
-ngx_int_t ngx_thread_key_create(ngx_tls_key_t *key);
+ngx_err_t ngx_thread_key_create(ngx_tls_key_t *key);
#define ngx_thread_key_create_n "the tls key creation"
-ngx_int_t ngx_thread_set_tls(ngx_tls_key_t key, void *value);
+ngx_err_t ngx_thread_set_tls(ngx_tls_key_t key, void *value);
#define ngx_thread_set_tls_n "the tls key setting"
diff --git a/src/os/unix/ngx_freebsd_sendfile_chain.c b/src/os/unix/ngx_freebsd_sendfile_chain.c
index 8303c0631..192a1a1ee 100644
--- a/src/os/unix/ngx_freebsd_sendfile_chain.c
+++ b/src/os/unix/ngx_freebsd_sendfile_chain.c
@@ -265,7 +265,7 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
}
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, err,
- "sendfile() sent only " OFF_T_FMT " bytes",
+ "sendfile() sent only %O bytes",
sent);
} else {
@@ -290,14 +290,14 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
}
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "sendfile: %d, @" OFF_T_FMT " " OFF_T_FMT ":%d",
+ "sendfile: %d, @%O %O:%uz",
rc, file->file_pos, sent, fsize + hsize);
} else {
rc = writev(c->fd, header.elts, header.nelts);
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "writev: %d of " SIZE_T_FMT, rc, hsize);
+ "writev: %d of %uz", rc, hsize);
if (rc == -1) {
err = ngx_errno;
diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h
index 9a0fee9ba..fb2cbc892 100644
--- a/src/os/unix/ngx_linux_config.h
+++ b/src/os/unix/ngx_linux_config.h
@@ -44,6 +44,7 @@
#include <netdb.h>
#include <time.h> /* tzset() */
+#include <malloc.h> /* memalign() */
#include <sys/ioctl.h>
#include <sys/sysctl.h>
diff --git a/src/os/unix/ngx_linux_sendfile_chain.c b/src/os/unix/ngx_linux_sendfile_chain.c
index 4de7ac2cd..ad40f55d9 100644
--- a/src/os/unix/ngx_linux_sendfile_chain.c
+++ b/src/os/unix/ngx_linux_sendfile_chain.c
@@ -195,7 +195,7 @@ ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
sent = rc > 0 ? rc : 0;
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "sendfile: %d, @" OFF_T_FMT " %d:%d",
+ "sendfile: %d, @%O %z:%uz",
rc, file->file_pos, sent, fsize);
} else {
@@ -221,7 +221,7 @@ ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
sent = rc > 0 ? rc : 0;
- ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "writev: %d", sent);
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "writev: %z", sent);
}
if (send - sprev == sent) {
diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c
index 1c7b1b6c0..19d65a489 100644
--- a/src/os/unix/ngx_posix_init.c
+++ b/src/os/unix/ngx_posix_init.c
@@ -134,7 +134,7 @@ ngx_int_t ngx_posix_init(ngx_log_t *log)
void ngx_posix_status(ngx_log_t *log)
{
ngx_log_error(NGX_LOG_INFO, log, 0,
- "getrlimit(RLIMIT_NOFILE): " RLIM_T_FMT ":" RLIM_T_FMT,
+ "getrlimit(RLIMIT_NOFILE): %r:%r",
rlmt.rlim_cur, rlmt.rlim_max);
}
diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c
index 4f7ed6409..3141e1403 100644
--- a/src/os/unix/ngx_process.c
+++ b/src/os/unix/ngx_process.c
@@ -143,7 +143,7 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle,
}
ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
- "spawn %s: " PID_T_FMT, name, pid);
+ "spawn %s: %P", name, pid);
ngx_processes[s].pid = pid;
ngx_processes[s].exited = 0;
@@ -282,22 +282,40 @@ void ngx_process_get_status()
if (WTERMSIG(status)) {
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
- "%s " PID_T_FMT " exited on signal %d%s",
+ "%s %P exited on signal %d%s",
process, pid, WTERMSIG(status),
WCOREDUMP(status) ? " (core dumped)" : "");
} else {
ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, 0,
- "%s " PID_T_FMT " exited with code %d",
+ "%s %P exited with code %d",
process, pid, WEXITSTATUS(status));
}
if (WEXITSTATUS(status) == 2 && ngx_processes[i].respawn) {
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
- "%s " PID_T_FMT
- " exited with fatal code %d and could not respawn",
- process, pid, WEXITSTATUS(status));
+ "%s %P exited with fatal code %d and could not respawn",
+ process, pid, WEXITSTATUS(status));
ngx_processes[i].respawn = 0;
}
}
}
+
+
+void ngx_debug_point()
+{
+ ngx_core_conf_t *ccf;
+
+ ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx,
+ ngx_core_module);
+
+ switch (ccf->debug_points) {
+
+ case NGX_DEBUG_POINTS_STOP:
+ raise(SIGSTOP);
+ break;
+
+ case NGX_DEBUG_POINTS_ABORT:
+ abort();
+ }
+}
diff --git a/src/os/unix/ngx_process.h b/src/os/unix/ngx_process.h
index 9cb0700d6..12703b3e3 100644
--- a/src/os/unix/ngx_process.h
+++ b/src/os/unix/ngx_process.h
@@ -53,6 +53,7 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle,
char *name, ngx_int_t respawn);
ngx_pid_t ngx_execute(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx);
void ngx_process_get_status(void);
+void ngx_debug_point(void);
#if (NGX_HAVE_SCHED_YIELD)
diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c
index 1da491526..0447bc4ec 100644
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -322,11 +322,10 @@ static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n,
}
ngx_log_debug6(NGX_LOG_DEBUG_CORE, cycle->log, 0,
- "pass channel s:%d pid:" PID_T_FMT
- " fd:%d to s:%d pid:" PID_T_FMT " fd:%d",
- ch.slot, ch.pid, ch.fd,
- i, ngx_processes[i].pid,
- ngx_processes[i].channel[0]);
+ "pass channel s:%d pid:%P fd:%d to s:%i pid:%P fd:%d",
+ ch.slot, ch.pid, ch.fd,
+ i, ngx_processes[i].pid,
+ ngx_processes[i].channel[0]);
/* TODO: NGX_AGAIN */
@@ -384,7 +383,7 @@ static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo)
for (i = 0; i < ngx_last_process; i++) {
ngx_log_debug7(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "child: %d " PID_T_FMT " e:%d t:%d d:%d r:%d j:%d",
+ "child: %d %P e:%d t:%d d:%d r:%d j:%d",
i,
ngx_processes[i].pid,
ngx_processes[i].exiting,
@@ -421,13 +420,12 @@ static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo)
}
ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
- "kill (" PID_T_FMT ", %d)" ,
- ngx_processes[i].pid, signo);
+ "kill (%P, %d)" , ngx_processes[i].pid, signo);
if (kill(ngx_processes[i].pid, signo) == -1) {
err = ngx_errno;
ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
- "kill(%d, %d) failed",
+ "kill(%P, %d) failed",
ngx_processes[i].pid, signo);
if (err == NGX_ESRCH) {
@@ -459,7 +457,7 @@ static ngx_uint_t ngx_reap_childs(ngx_cycle_t *cycle)
for (i = 0; i < ngx_last_process; i++) {
ngx_log_debug7(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
- "child: %d " PID_T_FMT " e:%d t:%d d:%d r:%d j:%d",
+ "child: %d %P e:%d t:%d d:%d r:%d j:%d",
i,
ngx_processes[i].pid,
ngx_processes[i].exiting,
@@ -492,8 +490,8 @@ static ngx_uint_t ngx_reap_childs(ngx_cycle_t *cycle)
}
ngx_log_debug3(NGX_LOG_DEBUG_CORE, cycle->log, 0,
- "pass close channel s:%d pid:" PID_T_FMT
- " to:" PID_T_FMT, ch.slot, ch.pid, ngx_processes[n].pid);
+ "pass close channel s:%i pid:%P to:%P",
+ ch.slot, ch.pid, ngx_processes[n].pid);
/* TODO: NGX_AGAIN */
@@ -786,9 +784,19 @@ static void ngx_channel_handler(ngx_event_t *ev)
n = ngx_read_channel(c->fd, &ch, sizeof(ngx_channel_t), ev->log);
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, "channel: %d", n);
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, "channel: %i", n);
- if (n <= 0) {
+ if (n == NGX_ERROR) {
+ if (close(c->fd) == -1) {
+ ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
+ "close() channel failed");
+ }
+
+ c->fd = -1;
+ return;
+ }
+
+ if (n == NGX_AGAIN) {
return;
}
@@ -812,8 +820,7 @@ static void ngx_channel_handler(ngx_event_t *ev)
case NGX_CMD_OPEN_CHANNEL:
ngx_log_debug3(NGX_LOG_DEBUG_CORE, ev->log, 0,
- "get channel s:%d pid:" PID_T_FMT " fd:%d",
- ch.slot, ch.pid, ch.fd);
+ "get channel s:%i pid:%P fd:%d", ch.slot, ch.pid, ch.fd);
ngx_processes[ch.slot].pid = ch.pid;
ngx_processes[ch.slot].channel[0] = ch.fd;
@@ -822,8 +829,7 @@ static void ngx_channel_handler(ngx_event_t *ev)
case NGX_CMD_CLOSE_CHANNEL:
ngx_log_debug4(NGX_LOG_DEBUG_CORE, ev->log, 0,
- "close channel s:%d pid:" PID_T_FMT " our:" PID_T_FMT
- " fd:%d",
+ "close channel s:%i pid:%P our:%P fd:%d",
ch.slot, ch.pid, ngx_processes[ch.slot].pid,
ngx_processes[ch.slot].channel[0]);
@@ -882,7 +888,7 @@ static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle)
}
-static void* ngx_worker_thread_cycle(void *data)
+static void *ngx_worker_thread_cycle(void *data)
{
ngx_thread_t *thr = data;
@@ -909,7 +915,7 @@ static void* ngx_worker_thread_cycle(void *data)
}
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
- "thread " TID_T_FMT " started", ngx_thread_self());
+ "thread " NGX_TID_T_FMT " started", ngx_thread_self());
ngx_setthrtitle("worker thread");
@@ -941,7 +947,8 @@ static void* ngx_worker_thread_cycle(void *data)
ngx_mutex_unlock(ngx_posted_events_mutex);
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
- "thread %d is done", ngx_thread_self());
+ "thread " NGX_TID_T_FMT " is done",
+ ngx_thread_self());
return (void *) 0;
}
diff --git a/src/os/unix/ngx_pthread_thread.c b/src/os/unix/ngx_pthread_thread.c
index ad7987b81..4903d5e50 100644
--- a/src/os/unix/ngx_pthread_thread.c
+++ b/src/os/unix/ngx_pthread_thread.c
@@ -15,14 +15,14 @@ static ngx_uint_t max_threads;
static pthread_attr_t thr_attr;
-int ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg,
- ngx_log_t *log)
+ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg,
+ ngx_log_t *log)
{
int err;
if (nthreads >= max_threads) {
ngx_log_error(NGX_LOG_CRIT, log, 0,
- "no more than %d threads can be created", max_threads);
+ "no more than %ui threads can be created", max_threads);
return NGX_ERROR;
}
@@ -34,7 +34,7 @@ int ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg,
}
ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0,
- "thread is created: " TID_T_FMT, *tid);
+ "thread is created: " NGX_TID_T_FMT, *tid);
nthreads++;
@@ -70,7 +70,7 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle)
}
-ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, uint flags)
+ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags)
{
int err;
ngx_mutex_t *m;
@@ -101,7 +101,7 @@ void ngx_mutex_destroy(ngx_mutex_t *m)
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, m->log, err,
- "pthread_mutex_destroy(" PTR_FMT ") failed", m);
+ "pthread_mutex_destroy(%p) failed", m);
}
ngx_free(m);
@@ -116,18 +116,17 @@ ngx_int_t ngx_mutex_lock(ngx_mutex_t *m)
return NGX_OK;
}
- ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "lock mutex " PTR_FMT, m);
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "lock mutex %p", m);
err = pthread_mutex_lock(&m->mutex);
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, m->log, err,
- "pthread_mutex_lock(" PTR_FMT ") failed", m);
+ "pthread_mutex_lock(%p) failed", m);
return NGX_ERROR;
}
- ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
- "mutex " PTR_FMT " is locked", m);
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is locked", m);
return NGX_OK;
}
@@ -141,8 +140,7 @@ ngx_int_t ngx_mutex_trylock(ngx_mutex_t *m)
return NGX_OK;
}
- ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
- "try lock mutex " PTR_FMT, m);
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "try lock mutex %p", m);
err = pthread_mutex_trylock(&m->mutex);
@@ -152,12 +150,11 @@ ngx_int_t ngx_mutex_trylock(ngx_mutex_t *m)
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, m->log, err,
- "pthread_mutex_trylock(" PTR_FMT ") failed", m);
+ "pthread_mutex_trylock(%p) failed", m);
return NGX_ERROR;
}
- ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
- "mutex " PTR_FMT " is locked", m);
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is locked", m);
return NGX_OK;
}
@@ -171,18 +168,17 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
return NGX_OK;
}
- ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "unlock mutex " PTR_FMT, m);
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "unlock mutex %p", m);
err = pthread_mutex_unlock(&m->mutex);
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, m->log, err,
- "pthread_mutex_unlock(" PTR_FMT ") failed", m);
+ "pthread_mutex_unlock(%p) failed", m);
return NGX_ERROR;
}
- ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
- "mutex " PTR_FMT " is unlocked", m);
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is unlocked", m);
return NGX_OK;
}
@@ -219,7 +215,7 @@ void ngx_cond_destroy(ngx_cond_t *cv)
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, cv->log, err,
- "pthread_cond_destroy(" PTR_FMT ") failed", cv);
+ "pthread_cond_destroy(%p) failed", cv);
}
ngx_free(cv);
@@ -230,22 +226,19 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m)
{
int err;
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0,
- "cv " PTR_FMT " wait", cv);
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p wait", cv);
err = pthread_cond_wait(&cv->cond, &m->mutex);
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, cv->log, err,
- "pthread_cond_wait(" PTR_FMT ") failed", cv);
+ "pthread_cond_wait(%p) failed", cv);
return NGX_ERROR;
}
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0,
- "cv " PTR_FMT " is waked up", cv);
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is waked up", cv);
- ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
- "mutex " PTR_FMT " is locked", m);
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is locked", m);
return NGX_OK;
}
@@ -255,19 +248,17 @@ ngx_int_t ngx_cond_signal(ngx_cond_t *cv)
{
int err;
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0,
- "cv " PTR_FMT " to signal", cv);
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p to signal", cv);
err = pthread_cond_signal(&cv->cond);
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, cv->log, err,
- "pthread_cond_signal(" PTR_FMT ") failed", cv);
+ "pthread_cond_signal(%p) failed", cv);
return NGX_ERROR;
}
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0,
- "cv " PTR_FMT " is signaled", cv);
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is signaled", cv);
return NGX_OK;
}
diff --git a/src/os/unix/ngx_shared.c b/src/os/unix/ngx_shared.c
index 60f2de029..7f3c5e9be 100644
--- a/src/os/unix/ngx_shared.c
+++ b/src/os/unix/ngx_shared.c
@@ -18,8 +18,7 @@ void *ngx_create_shared_memory(size_t size, ngx_log_t *log)
if (p == MAP_FAILED) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
- "mmap(MAP_ANON|MAP_SHARED, " SIZE_T_FMT ") failed",
- size);
+ "mmap(MAP_ANON|MAP_SHARED, %uz) failed", size);
return NULL;
}
@@ -45,8 +44,7 @@ void *ngx_create_shared_memory(size_t size, ngx_log_t *log)
if (p == MAP_FAILED) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
- "mmap(/dev/zero, MAP_SHARED, " SIZE_T_FMT ") failed",
- size);
+ "mmap(/dev/zero, MAP_SHARED, %uz) failed", size);
p = NULL;
}
@@ -72,7 +70,7 @@ void *ngx_create_shared_memory(size_t size, ngx_log_t *log)
if (id == -1) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
- "shmget(" SIZE_T_FMT ") failed", size);
+ "shmget(%uz) failed", size);
return NULL;
}
diff --git a/src/os/unix/ngx_socket.h b/src/os/unix/ngx_socket.h
index 34449d090..c6eb9413f 100644
--- a/src/os/unix/ngx_socket.h
+++ b/src/os/unix/ngx_socket.h
@@ -15,7 +15,7 @@
typedef int ngx_socket_t;
-#define ngx_socket(af, type, proto, flags) socket(af, type, proto)
+#define ngx_socket socket
#define ngx_socket_n "socket()"
diff --git a/src/os/unix/ngx_solaris_sendfilev_chain.c b/src/os/unix/ngx_solaris_sendfilev_chain.c
index 9430dc05b..21f8b8f7c 100644
--- a/src/os/unix/ngx_solaris_sendfilev_chain.c
+++ b/src/os/unix/ngx_solaris_sendfilev_chain.c
@@ -136,8 +136,7 @@ ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in,
}
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, err,
- "sendfilev() sent only " SIZE_T_FMT " bytes",
- sent);
+ "sendfilev() sent only %z bytes", sent);
} else {
wev->error = 1;
@@ -147,7 +146,7 @@ ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in,
}
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "sendfilev: %d " SIZE_T_FMT, n, sent);
+ "sendfilev: %z %z", n, sent);
if (send - sprev == sent) {
complete = 1;
diff --git a/src/os/unix/ngx_thread.h b/src/os/unix/ngx_thread.h
index 16e216ef0..ac7cfad43 100644
--- a/src/os/unix/ngx_thread.h
+++ b/src/os/unix/ngx_thread.h
@@ -29,9 +29,9 @@ typedef pthread_t ngx_tid_t;
#define ngx_log_tid (int) ngx_thread_self()
#if (NGX_FREEBSD) && !(NGX_LINUXTHREADS)
-#define TID_T_FMT PTR_FMT
+#define NGX_TID_T_FMT "%p"
#else
-#define TID_T_FMT "%d"
+#define NGX_TID_T_FMT "%d"
#endif
@@ -92,11 +92,11 @@ extern volatile ngx_thread_t ngx_threads[NGX_MAX_THREADS];
ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle);
-int ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg,
- ngx_log_t *log);
+ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg,
+ ngx_log_t *log);
-ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, uint flags);
+ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags);
void ngx_mutex_destroy(ngx_mutex_t *m);
@@ -110,8 +110,8 @@ ngx_int_t ngx_cond_signal(ngx_cond_t *cv);
#define ngx_thread_volatile
-#define ngx_log_tid 0
-#define TID_T_FMT "%d"
+#define ngx_log_tid 0
+#define NGX_TID_T_FMT "%d"
#define ngx_mutex_trylock(m) NGX_OK
#define ngx_mutex_lock(m) NGX_OK
diff --git a/src/os/unix/ngx_writev_chain.c b/src/os/unix/ngx_writev_chain.c
index e57b59305..e3893226d 100644
--- a/src/os/unix/ngx_writev_chain.c
+++ b/src/os/unix/ngx_writev_chain.c
@@ -9,14 +9,14 @@
#include <ngx_event.h>
-#define NGX_IOVS 8
+#define NGX_IOVS 16
ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
{
u_char *prev;
- ssize_t n, size;
- off_t send, sprev, sent;
+ ssize_t n, size, sent;
+ off_t send, sprev;
ngx_uint_t eintr, complete;
ngx_err_t err;
ngx_array_t vec;
@@ -66,6 +66,12 @@ ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
continue;
}
+#if 1
+ if (!ngx_buf_in_memory(cl->buf)) {
+ ngx_debug_point();
+ }
+#endif
+
size = cl->buf->last - cl->buf->pos;
if (send + size > limit) {
@@ -110,8 +116,7 @@ ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
sent = n > 0 ? n : 0;
- ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "writev: " OFF_T_FMT, sent);
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "writev: %z", sent);
if (send - sprev == sent) {
complete = 1;
@@ -119,7 +124,8 @@ ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
c->sent += sent;
- for (cl = in; cl && sent > 0; cl = cl->next) {
+ for (cl = in; cl; cl = cl->next) {
+
if (ngx_buf_special(cl->buf)) {
continue;
}
diff --git a/src/os/win32/nginx.ico b/src/os/win32/nginx.ico
new file mode 100644
index 000000000..6fb330b51
--- /dev/null
+++ b/src/os/win32/nginx.ico
Binary files differ
diff --git a/src/os/win32/nginx.rc b/src/os/win32/nginx.rc
new file mode 100644
index 000000000..7a2e24133
--- /dev/null
+++ b/src/os/win32/nginx.rc
@@ -0,0 +1,16 @@
+
+// Copyright (C) Igor Sysoev
+
+#include <ngx_gui.h>
+
+nginx icon discardable "src\\os\\win32\\nginx.ico"
+tray icon discardable "src\\os\\win32\\tray.ico"
+
+nginx menu discardable
+begin
+ popup "&nginx"
+ begin
+ menuitem "&Exit", NGX_WM_EXIT
+ menuitem "&About", NGX_WM_ABOUT
+ end
+end
diff --git a/src/os/win32/ngx_alloc.c b/src/os/win32/ngx_alloc.c
index ea36cad57..e73aa32af 100644
--- a/src/os/win32/ngx_alloc.c
+++ b/src/os/win32/ngx_alloc.c
@@ -17,11 +17,10 @@ void *ngx_alloc(size_t size, ngx_log_t *log)
if (!(p = malloc(size))) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
- "malloc() " SIZE_T_FMT " bytes failed", size);
+ "malloc() %uz bytes failed", size);
}
- ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0,
- "malloc: " PTR_FMT ":" SIZE_T_FMT, p, size);
+ ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, "malloc: %p:%uz", p, size);
return p;
}
diff --git a/src/os/win32/ngx_atomic.h b/src/os/win32/ngx_atomic.h
index 3ef150996..b4915d0a2 100644
--- a/src/os/win32/ngx_atomic.h
+++ b/src/os/win32/ngx_atomic.h
@@ -18,7 +18,7 @@
#define ngx_atomic_inc(p) InterlockedIncrement((long *) p)
-#if defined( __WATCOMC__ ) || defined( __BORLANDC__ )
+#if defined( __WATCOMC__ ) || defined( __BORLANDC__ ) || ( _MSC_VER >= 1300 )
/* the new SDK headers */
diff --git a/src/os/win32/ngx_errno.c b/src/os/win32/ngx_errno.c
index 6f8d2da5b..8e9280d92 100644
--- a/src/os/win32/ngx_errno.c
+++ b/src/os/win32/ngx_errno.c
@@ -15,64 +15,101 @@
static ngx_str_t wsa_errors[] = {
- ngx_string("Invalid argument"), /* 10022 */
- ngx_null_string, /* 10023 */
- ngx_null_string, /* 10024 */
- ngx_null_string, /* 10025 */
- ngx_null_string, /* 10026 */
- ngx_null_string, /* 10027 */
- ngx_null_string, /* 10028 */
- ngx_null_string, /* 10029 */
- ngx_null_string, /* 10030 */
- ngx_null_string, /* 10031 */
- ngx_null_string, /* 10032 */
- ngx_null_string, /* 10033 */
- ngx_null_string, /* 10034 */
- ngx_string("Resource temporarily unavailable"), /* 10035 */
- ngx_null_string, /* 10036 */
- ngx_null_string, /* 10037 */
- ngx_null_string, /* 10038 */
- ngx_null_string, /* 10039 */
- ngx_null_string, /* 10040 */
- ngx_null_string, /* 10041 */
- ngx_null_string, /* 10042 */
- ngx_null_string, /* 10043 */
- ngx_null_string, /* 10044 */
- ngx_null_string, /* 10045 */
- ngx_null_string, /* 10046 */
- ngx_null_string, /* 10047 */
- ngx_null_string, /* 10048 */
- ngx_null_string, /* 10049 */
- ngx_null_string, /* 10050 */
- ngx_null_string, /* 10051 */
- ngx_null_string, /* 10052 */
- ngx_null_string, /* 10053 */
- ngx_null_string, /* 10054 */
- ngx_null_string, /* 10055 */
- ngx_null_string, /* 10056 */
- ngx_string("Socket is not connected") /* 10057 */
+ ngx_string("An invalid argument was supplied"), /* WSAEINVAL 10022 */
+ ngx_string("Too many open sockets"), /* WSAEMFILE 10023 */
+
+ ngx_null_string, /* 10024 */
+ ngx_null_string, /* 10025 */
+ ngx_null_string, /* 10026 */
+ ngx_null_string, /* 10027 */
+ ngx_null_string, /* 10028 */
+ ngx_null_string, /* 10029 */
+ ngx_null_string, /* 10030 */
+ ngx_null_string, /* 10031 */
+ ngx_null_string, /* 10032 */
+ ngx_null_string, /* 10033 */
+ ngx_null_string, /* 10034 */
+
+ /* WSAEWOULDBLOCK 10035 */
+ ngx_string("A non-blocking socket operation could not be completed "
+ "immediately"),
+
+ ngx_null_string, /* 10036 */
+ ngx_null_string, /* 10037 */
+
+ /* WSAENOTSOCK 10038 */
+ ngx_string("An operation was attempted on something that is not a socket"),
+
+ ngx_null_string, /* 10039 */
+ ngx_null_string, /* 10040 */
+ ngx_null_string, /* 10041 */
+ ngx_null_string, /* 10042 */
+ ngx_null_string, /* 10043 */
+ ngx_null_string, /* 10044 */
+ ngx_null_string, /* 10045 */
+ ngx_null_string, /* 10046 */
+ ngx_null_string, /* 10047 */
+ ngx_null_string, /* 10048 */
+ ngx_null_string, /* 10049 */
+ ngx_null_string, /* 10050 */
+ ngx_null_string, /* 10051 */
+ ngx_null_string, /* 10052 */
+ ngx_null_string, /* 10053 */
+
+ /* WSAECONNRESET 10054 */
+ ngx_string("An existing connection was forcibly closed by the remote host"),
+
+ /* WSAENOBUFS 10055 */
+ ngx_string("An operation on a socket could not be performed because "
+ "the system lacked sufficient buffer space or "
+ "because a queue was full"),
+
+ /* WSAEISCONN 10056 */
+ ngx_string("A connect request was made on an already connected socket"),
+
+ /* WSAENOTCONN 10057 */
+ ngx_string("A request to send or receive data was disallowed because"
+ "the socket is not connected and (when sending on a datagram "
+ "socket using a sendto call) no address was supplied"),
+
+ ngx_null_string, /* 10058 */
+ ngx_null_string, /* 10059 */
+
+ /* WSAETIMEDOUT 10060 */
+ ngx_string("A connection attempt failed because the connected party "
+ "did not properly respond after a period of time, "
+ "or established connection failed because connected host "
+ "has failed to respond"),
+
+ /* WSAECONNREFUSED 10061 */
+ ngx_string("No connection could be made because the target machine "
+ "actively refused it")
};
-int ngx_strerror_r(ngx_err_t err, char *errstr, size_t size)
+u_char *ngx_strerror_r(ngx_err_t err, u_char *errstr, size_t size)
{
int n;
u_int len;
ngx_err_t format_error;
+ if (size == 0) {
+ return errstr;
+ }
+
len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- errstr, size, NULL);
+ (char *) errstr, size, NULL);
if (len == 0) {
format_error = GetLastError();
if (format_error == ERROR_MR_MID_NOT_FOUND) {
- n = err - WSABASEERR - 22;
+ n = err - WSAEINVAL;
- if (n >= 0 && n <= 35) {
+ if (n >= 0 && n <= WSAECONNREFUSED - WSAEINVAL) {
len = wsa_errors[n].len;
if (len) {
@@ -81,21 +118,22 @@ int ngx_strerror_r(ngx_err_t err, char *errstr, size_t size)
}
ngx_memcpy(errstr, wsa_errors[n].data, len);
- return len;
+
+ return errstr + len;
}
}
}
- len = ngx_snprintf(errstr, size,
- "FormatMessage() error:(%d)", format_error);
- return len;
-
+ return ngx_snprintf(errstr, size,
+ "FormatMessage() error:(%d)", format_error);
}
/* remove ".\r\n\0" */
while (errstr[len] == '\0' || errstr[len] == CR
|| errstr[len] == LF || errstr[len] == '.')
+ {
--len;
+ }
- return ++len;
+ return &errstr[++len];
}
diff --git a/src/os/win32/ngx_errno.h b/src/os/win32/ngx_errno.h
index f60ea74e1..863dce879 100644
--- a/src/os/win32/ngx_errno.h
+++ b/src/os/win32/ngx_errno.h
@@ -38,7 +38,7 @@ typedef DWORD ngx_err_t;
#define NGX_EALREADY WSAEALREADY
#define NGX_EINVAL WSAEINVAL
-int ngx_strerror_r(ngx_err_t err, char *errstr, size_t size);
+u_char *ngx_strerror_r(ngx_err_t err, u_char *errstr, size_t size);
#endif /* _NGX_ERRNO_H_INCLUDED_ */
diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c
index dea310698..ffd52c9bd 100644
--- a/src/os/win32/ngx_files.c
+++ b/src/os/win32/ngx_files.c
@@ -18,19 +18,20 @@ ssize_t ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
if (ngx_win32_version < NGX_WIN_NT) {
/*
- * in Win9X the overlapped pointer must be NULL
- * so we need to use SetFilePointer() to set the offset
+ * under Win9X the overlapped pointer must be NULL
+ * so we have to use SetFilePointer() to set the offset
*/
if (file->offset != offset) {
/*
- * the maximum file size on FAT16 is 2G, but on FAT32
- * the size is 4G so we need to use high_offset
+ * the maximum file size on the FAT16 is 2G, but on the FAT32
+ * the size is 4G so we have to use the high_offset
* because a single offset is signed value
*/
high_offset = (long) (offset >> 32);
+
if (SetFilePointer(file->fd, (long) offset, &high_offset,
FILE_BEGIN) == INVALID_SET_FILE_POINTER)
{
@@ -81,15 +82,15 @@ ssize_t ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
if (ngx_win32_version < NGX_WIN_NT) {
/*
- * in Win9X the overlapped pointer must be NULL
- * so we need to use SetFilePointer() to set the offset
+ * under Win9X the overlapped pointer must be NULL
+ * so we have to use SetFilePointer() to set the offset
*/
if (file->offset != offset) {
/*
- * the maximum file size on FAT16 is 2G, but on FAT32
- * the size is 4G so we need to use high_offset
+ * the maximum file size on the FAT16 is 2G, but on the FAT32
+ * the size is 4G so we have to use high_offset
* because a single offset is signed value
*/
@@ -189,8 +190,7 @@ int ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_pool_t *pool)
do {
num = ngx_next_temp_number(collision);
- ngx_snprintf((char *) name + to->len, 1 + 10 + 1 + sizeof("DELETE"),
- ".%010u.DELETE", num);
+ ngx_sprintf(name + to->len, ".%010u.DELETE", num);
if (MoveFile((const char *) to->data, (const char *) name) == 0) {
collision = 1;
diff --git a/src/os/win32/ngx_gui.c b/src/os/win32/ngx_gui.c
new file mode 100644
index 000000000..5673820d2
--- /dev/null
+++ b/src/os/win32/ngx_gui.c
@@ -0,0 +1,85 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ */
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+#define NGX_MAX_TEXT 2048
+
+
+void ngx_message_box(char *title, ngx_uint_t type, ngx_err_t err,
+ const char *fmt, ...)
+{
+ va_list args;
+ u_char text[NGX_MAX_TEXT], *p, *last;
+
+ last = text + NGX_MAX_TEXT;
+
+ va_start(args, fmt);
+ p = ngx_vsnprintf(text, NGX_MAX_TEXT, fmt, args);
+ va_end(args);
+
+ if (err) {
+
+ if (p > last - 50) {
+
+ /* leave a space for an error code */
+
+ p = last - 50;
+ *p++ = '.';
+ *p++ = '.';
+ *p++ = '.';
+ }
+
+ if ((unsigned) err >= 0x80000000) {
+ p = ngx_snprintf(p, last - p, " (%Xd: ", err);
+
+ } else {
+ p = ngx_snprintf(p, last - p, " (%d: ", err);
+ }
+
+ p = ngx_strerror_r(err, p, last - p);
+
+ if (p < last) {
+ *p++ = ')';
+ }
+ }
+
+ if (p == last) {
+ p--;
+ }
+
+ *p = '\0';
+
+ MessageBox(NULL, (char *) text, title, type);
+}
+
+
+ngx_int_t ngx_system_tray_icon(HWND window, u_long action,
+ HICON icon, u_char *tip)
+{
+ NOTIFYICONDATA ni;
+
+ ni.cbSize = sizeof(NOTIFYICONDATA);
+ ni.hWnd = window;
+ ni.uID = 0;
+ ni.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
+ ni.uCallbackMessage = NGX_WM_TRAY;
+ ni.hIcon = icon;
+
+ if (tip) {
+ ngx_cpystrn((u_char *) ni.szTip, tip, 64);
+ } else {
+ ni.szTip[0] = '\0';
+ }
+
+ if (Shell_NotifyIcon(action, &ni) == 0) {
+ return NGX_ERROR;
+ }
+
+ return NGX_OK;
+}
diff --git a/src/os/win32/ngx_gui.h b/src/os/win32/ngx_gui.h
new file mode 100644
index 000000000..1c2fd9b43
--- /dev/null
+++ b/src/os/win32/ngx_gui.h
@@ -0,0 +1,27 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ */
+
+
+#ifndef _NGX_GUI_H_INCLUDED_
+#define _NGX_GUI_H_INCLUDED_
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+#define NGX_WM_TRAY WM_USER
+#define NGX_WM_EXIT WM_USER + 1
+#define NGX_WM_ABOUT WM_USER + 2
+
+
+void ngx_message_box(char *title, ngx_uint_t type, ngx_err_t err,
+ const char *fmt, ...);
+
+ngx_int_t ngx_system_tray_icon(HWND window, u_long action,
+ HICON icon, u_char *tip);
+
+
+#endif /* _NGX_GUI_H_INCLUDED_ */
diff --git a/src/os/win32/ngx_os.h b/src/os/win32/ngx_os.h
index 98c8e15c2..c27f8a80a 100644
--- a/src/os/win32/ngx_os.h
+++ b/src/os/win32/ngx_os.h
@@ -10,6 +10,7 @@
#include <ngx_config.h>
#include <ngx_core.h>
+#include <ngx_gui.h>
#define NGX_IO_SENDFILE 1
#define NGX_IO_ZEROCOPY 2
@@ -56,6 +57,7 @@ ngx_chain_t *ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in,
extern ngx_os_io_t ngx_os_io;
extern ngx_uint_t ngx_ncpu;
+extern ngx_uint_t ngx_max_wsabufs;
extern ngx_int_t ngx_max_sockets;
extern ngx_uint_t ngx_inherited_nonblocking;
extern ngx_uint_t ngx_win32_version;
diff --git a/src/os/win32/ngx_process.h b/src/os/win32/ngx_process.h
index b9b4aeb80..a282d17ad 100644
--- a/src/os/win32/ngx_process.h
+++ b/src/os/win32/ngx_process.h
@@ -29,6 +29,7 @@ typedef struct {
ngx_pid_t ngx_execute(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx);
+#define ngx_debug_point()
#define ngx_sched_yield() Sleep(0)
diff --git a/src/os/win32/ngx_process_cycle.c b/src/os/win32/ngx_process_cycle.c
index 843c3111e..e0635a5eb 100644
--- a/src/os/win32/ngx_process_cycle.c
+++ b/src/os/win32/ngx_process_cycle.c
@@ -7,8 +7,13 @@
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_event.h>
+#include <nginx.h>
+static void *ngx_worker_thread_cycle(void *data);
+static long __stdcall ngx_window_procedure(HWND window, u_int message,
+ u_int wparam, long lparam);
+
#if 0
ngx_pid_t ngx_new_binary;
@@ -37,6 +42,8 @@ sig_atomic_t ngx_change_binary;
#endif
+static HMENU ngx_menu;
+
void ngx_master_process_cycle(ngx_cycle_t *cycle)
{
@@ -48,7 +55,17 @@ void ngx_master_process_cycle(ngx_cycle_t *cycle)
void ngx_single_process_cycle(ngx_cycle_t *cycle)
{
- ngx_int_t i;
+ int rc;
+ ngx_int_t i;
+ ngx_err_t err;
+ ngx_tid_t tid;
+ MSG message;
+ HWND window;
+ HMENU menu;
+ HICON icon,tray;
+ WNDCLASS wc;
+ HINSTANCE instance;
+ ngx_core_conf_t *ccf;
ngx_init_temp_number();
@@ -61,9 +78,197 @@ void ngx_single_process_cycle(ngx_cycle_t *cycle)
}
}
+
+ ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
+
+ if (ngx_init_threads(ngx_threads_n,
+ ccf->thread_stack_size, cycle) == NGX_ERROR)
+ {
+ /* fatal */
+ exit(2);
+ }
+
+ err = ngx_thread_key_create(&ngx_core_tls_key);
+ if (err != 0) {
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
+ ngx_thread_key_create_n " failed");
+ /* fatal */
+ exit(2);
+ }
+
+
+ instance = GetModuleHandle(NULL);
+
+ icon = LoadIcon(instance, "nginx");
+ if (icon == NULL) {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ "LoadIcon(\"nginx\") failed");
+ /* fatal */
+ exit(2);
+ }
+
+ tray = LoadIcon(instance, "tray");
+ if (icon == NULL) {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ "LoadIcon(\"tray\") failed");
+ /* fatal */
+ exit(2);
+ }
+
+ menu = LoadMenu(instance, "nginx");
+ if (menu == NULL) {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ "LoadMenu() failed");
+ /* fatal */
+ exit(2);
+ }
+
+ ngx_menu = GetSubMenu(menu, 0);
+ if (ngx_menu == NULL) {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ "GetSubMenu() failed");
+ /* fatal */
+ exit(2);
+ }
+
+
+ wc.style = CS_HREDRAW|CS_VREDRAW;
+ wc.lpfnWndProc = ngx_window_procedure;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = instance;
+ wc.hIcon = icon;
+ wc.hCursor = NULL;
+ wc.hbrBackground = NULL;
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = "nginx";
+
+ if (RegisterClass(&wc) == 0) {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ "RegisterClass() failed");
+ /* fatal */
+ exit(2);
+ }
+
+
+ window = CreateWindow("nginx", "nginx", WS_OVERLAPPEDWINDOW,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ NULL, NULL, instance, NULL);
+
+ if (window == NULL) {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ "CreateWindow() failed");
+ /* fatal */
+ exit(2);
+ }
+
+
+ if (ngx_system_tray_icon(window, NIM_ADD, tray, (u_char *) " nginx")
+ == NGX_ERROR)
+ {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ "Shell_NotifyIcon(NIM_ADD) failed");
+ /* fatal */
+ exit(2);
+ }
+
+
+ if (ngx_create_thread(&tid, ngx_worker_thread_cycle, NULL, cycle->log) != 0)
+ {
+ /* fatal */
+ exit(2);
+ }
+
+
+ for ( ;; ) {
+ rc = GetMessage(&message, NULL, 0, 0);
+
+ if (rc == -1) {
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+ "GetMessage() failed");
+ continue;
+ }
+
+ if (rc == 0) {
+ exit(0);
+ }
+
+ TranslateMessage(&message);
+ DispatchMessage(&message);
+ }
+}
+
+
+static void *ngx_worker_thread_cycle(void *data)
+{
+ ngx_cycle_t *cycle;
+
+ cycle = (ngx_cycle_t *) ngx_cycle;
+
for ( ;; ) {
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle");
ngx_process_events(cycle);
}
+
+ return NULL;
+}
+
+
+static long __stdcall ngx_window_procedure(HWND window, u_int message,
+ u_int wparam, long lparam)
+{
+ POINT mouse;
+
+ switch (message) {
+
+ case NGX_WM_TRAY:
+ if (lparam == WM_RBUTTONDOWN) {
+ if (GetCursorPos(&mouse) == 0) {
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno,
+ "GetCursorPos() failed");
+ return 0;
+ }
+
+ if (SetForegroundWindow(window) == 0) {
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno,
+ "SetForegroundWindow() failed");
+ return 0;
+ }
+
+ if (TrackPopupMenu(ngx_menu, TPM_RIGHTBUTTON,
+ mouse.x, mouse.y, 0, window, NULL) == 0)
+ {
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno,
+ "TrackPopupMenu() failed");
+ return 0;
+ }
+ }
+
+ return 0;
+
+ case WM_COMMAND:
+ if (wparam == NGX_WM_ABOUT) {
+ ngx_message_box("nginx", MB_OK, 0,
+ NGINX_VER CRLF "(C) 2002-2004 Igor Sysoev");
+ return 0;
+ }
+
+ if (wparam == NGX_WM_EXIT) {
+ if (ngx_system_tray_icon(window, NIM_DELETE, NULL, NULL)
+ == NGX_ERROR)
+ {
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno,
+ "Shell_NotifyIcon(NIM_DELETE) failed");
+ }
+ }
+
+ PostQuitMessage(0);
+
+ return 0;
+
+ default:
+ return DefWindowProc(window, message, wparam, lparam);
+ }
}
diff --git a/src/os/win32/ngx_socket.h b/src/os/win32/ngx_socket.h
index 4ce60a7f3..d49ad2c15 100644
--- a/src/os/win32/ngx_socket.h
+++ b/src/os/win32/ngx_socket.h
@@ -19,12 +19,8 @@ typedef SOCKET ngx_socket_t;
typedef int socklen_t;
-#define ngx_socket(af, type, proto, flags) socket(af, type, proto)
-
-#if 0
-#define ngx_socket(af, type, proto, flags) \
- WSASocket(af, type, proto, NULL, 0, flags)
-#endif
+#define ngx_socket(af, type, proto) \
+ WSASocket(af, type, proto, NULL, 0, WSA_FLAG_OVERLAPPED)
#define ngx_socket_n "WSASocket()"
diff --git a/src/os/win32/ngx_thread.c b/src/os/win32/ngx_thread.c
new file mode 100644
index 000000000..8fae0e379
--- /dev/null
+++ b/src/os/win32/ngx_thread.c
@@ -0,0 +1,68 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ */
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+ngx_int_t ngx_threads_n;
+
+
+static size_t stack_size;
+
+
+ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg,
+ ngx_log_t *log)
+{
+ ngx_err_t err;
+
+ *tid = CreateThread(NULL, stack_size,
+ (LPTHREAD_START_ROUTINE) func, arg, 0, NULL);
+
+ if (*tid != NULL) {
+ return 0;
+ }
+
+ err = ngx_errno;
+ ngx_log_error(NGX_LOG_ALERT, log, err, "CreateThread() failed");
+ return err;
+}
+
+
+ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle)
+{
+ stack_size = size;
+
+ return NGX_OK;
+}
+
+
+ngx_err_t ngx_thread_key_create(ngx_tls_key_t *key)
+{
+ *key = TlsAlloc();
+
+ if (*key == TLS_OUT_OF_INDEXES) {
+ return ngx_errno;
+ }
+
+ return 0;
+}
+
+
+ngx_err_t ngx_thread_set_tls(ngx_tls_key_t *key, void *data)
+{
+ if (TlsSetValue(*key, data) == 0) {
+ return ngx_errno;
+ }
+
+ return 0;
+}
+
+
+ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags)
+{
+ return (ngx_mutex_t *) 1;
+}
diff --git a/src/os/win32/ngx_thread.h b/src/os/win32/ngx_thread.h
index b3b6e67cd..5b3c4da98 100644
--- a/src/os/win32/ngx_thread.h
+++ b/src/os/win32/ngx_thread.h
@@ -12,21 +12,46 @@
#include <ngx_core.h>
-#if (NGX_THREADS)
+typedef HANDLE ngx_tid_t;
+typedef DWORD ngx_tls_key_t;
+
+
+typedef struct {
+ HANDLE mutex;
+ ngx_log_t *log;
+} ngx_mutex_t;
+
+
+ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg,
+ ngx_log_t *log);
+ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle);
+
+ngx_err_t ngx_thread_key_create(ngx_tls_key_t *key);
+#define ngx_thread_key_create_n "TlsAlloc()"
+ngx_err_t ngx_thread_set_tls(ngx_tls_key_t *key, void *data);
+#define ngx_thread_set_tls_n "TlsSetValue()"
+#define ngx_thread_get_tls TlsGetValue
+
#define ngx_thread_volatile volatile
-#else /* !NGX_THREADS */
+#define ngx_log_tid GetCurrentThreadId()
+#define NGX_TID_T_FMT "%ud"
+
-#define ngx_thread_volatile
+ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags);
-#define ngx_log_tid 0
-#define TID_T_FMT "%d"
-#define ngx_mutex_lock(m) NGX_OK
+/* STUB */
+#define NGX_MUTEX_LIGHT 0
+
+#define ngx_mutex_lock(m) NGX_OK
+#define ngx_mutex_trylock(m) NGX_OK
#define ngx_mutex_unlock(m)
+/* */
+
-#endif
+extern ngx_int_t ngx_threads_n;
#endif /* _NGX_THREAD_H_INCLUDED_ */
diff --git a/src/os/win32/ngx_win32_config.h b/src/os/win32/ngx_win32_config.h
index a6c336d7a..e7d3086e8 100644
--- a/src/os/win32/ngx_win32_config.h
+++ b/src/os/win32/ngx_win32_config.h
@@ -8,8 +8,6 @@
#define _NGX_WIN32_CONFIG_H_INCLUDED_
-#define WIN32 1
-
#define STRICT
#define WIN32_LEAN_AND_MEAN
@@ -25,6 +23,7 @@
#include <winsock2.h>
#include <mswsock.h>
+#include <shellapi.h>
#include <stddef.h> /* offsetof() */
#include <stdio.h>
#include <stdlib.h>
@@ -96,8 +95,10 @@
#ifdef _MSC_VER
typedef unsigned __int32 uint32_t;
+typedef __int32 int32_t;
#else /* __WATCOMC__ */
typedef unsigned int uint32_t;
+typedef int int32_t;
#endif
typedef __int64 int64_t;
@@ -115,17 +116,13 @@ typedef uint32_t ngx_atomic_t;
#define TIME_T_LEN sizeof("-2147483648") - 1
-#define OFF_T_FMT "%I64d"
-#define SIZE_T_FMT "%d"
-#define SIZE_T_X_FMT "%x"
-#define PID_T_FMT "%d"
-#define TIME_T_FMT "%lu"
-#define PTR_FMT "%08X"
-
#define NGX_WIN_NT 200000
+#define NGX_THREADS 1
+
+
#ifndef HAVE_INHERITED_NONBLOCK
#define HAVE_INHERITED_NONBLOCK 1
#endif
diff --git a/src/os/win32/ngx_win32_init.c b/src/os/win32/ngx_win32_init.c
index ea1cfd1b5..cb8c93128 100644
--- a/src/os/win32/ngx_win32_init.c
+++ b/src/os/win32/ngx_win32_init.c
@@ -10,6 +10,7 @@
ngx_uint_t ngx_win32_version;
ngx_uint_t ngx_ncpu;
+ngx_uint_t ngx_max_wsabufs;
ngx_int_t ngx_max_sockets;
ngx_uint_t ngx_inherited_nonblocking = 1;
ngx_fd_t ngx_stderr_fileno;
@@ -31,6 +32,9 @@ typedef struct {
} ngx_osviex_stub_t;
+static u_int osviex;
+static OSVERSIONINFOEX osvi;
+
/* Should these pointers be per protocol ? */
LPFN_ACCEPTEX acceptex;
LPFN_GETACCEPTEXSOCKADDRS getacceptexsockaddrs;
@@ -43,13 +47,10 @@ static GUID tf_guid = WSAID_TRANSMITFILE;
ngx_int_t ngx_os_init(ngx_log_t *log)
{
- u_int osviex;
- DWORD bytes;
- SOCKET s;
- WSADATA wsd;
- SYSTEM_INFO si;
- OSVERSIONINFOEX osvi;
- ngx_osviex_stub_t *osviex_stub;
+ DWORD bytes;
+ SOCKET s;
+ WSADATA wsd;
+ SYSTEM_INFO si;
/* get Windows version */
@@ -90,43 +91,6 @@ ngx_int_t ngx_os_init(ngx_log_t *log)
if (osviex) {
ngx_win32_version += osvi.wServicePackMajor * 10
+ osvi.wServicePackMinor;
-
- /*
- * the MSVC 6.0 SP2 defines wSuiteMask and wProductType
- * as WORD wReserved[2]
- */
- osviex_stub = (ngx_osviex_stub_t *) &osvi.wServicePackMinor;
-
- ngx_log_error(NGX_LOG_INFO, log, 0,
- "OS: %u build:%u, \"%s\", suite:%x, type:%u",
- ngx_win32_version, osvi.dwBuildNumber, osvi.szCSDVersion,
- osviex_stub->wSuiteMask, osviex_stub->wProductType);
-
- } else {
- if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
-
- /* Win9x build */
-
- ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %u build:%u.%u.%u, \"%s\"",
- ngx_win32_version,
- osvi.dwBuildNumber >> 24,
- (osvi.dwBuildNumber >> 16) & 0xff,
- osvi.dwBuildNumber & 0xffff,
- osvi.szCSDVersion);
-
- } else {
-
- /*
- * VER_PLATFORM_WIN32_NT
- *
- * we do not currently support VER_PLATFORM_WIN32_CE
- * and we do not support VER_PLATFORM_WIN32s at all
- */
-
- ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %u build:%u, \"%s\"",
- ngx_win32_version, osvi.dwBuildNumber,
- osvi.szCSDVersion);
- }
}
GetSystemInfo(&si);
@@ -143,15 +107,19 @@ ngx_int_t ngx_os_init(ngx_log_t *log)
}
if (ngx_win32_version < NGX_WIN_NT) {
+ ngx_max_wsabufs = 16;
return NGX_OK;
}
+ /* STUB: ngx_uint_t max */
+ ngx_max_wsabufs = 1024 * 1024;
+
/* get AcceptEx(), GetAcceptExSockAddrs() and TransmitFile() addresses */
- s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0);
+ s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
if (s == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- ngx_socket_n " %s falied");
+ ngx_socket_n " falied");
return NGX_ERROR;
}
@@ -194,4 +162,46 @@ ngx_int_t ngx_os_init(ngx_log_t *log)
void ngx_os_status(ngx_log_t *log)
{
+ ngx_osviex_stub_t *osviex_stub;
+
+ if (osviex) {
+
+ /*
+ * the MSVC 6.0 SP2 defines wSuiteMask and wProductType
+ * as WORD wReserved[2]
+ */
+ osviex_stub = (ngx_osviex_stub_t *) &osvi.wServicePackMinor;
+
+ ngx_log_error(NGX_LOG_INFO, log, 0,
+ "OS: %ud build:%ud, \"%s\", suite:%Xd, type:%ud",
+ ngx_win32_version, osvi.dwBuildNumber, osvi.szCSDVersion,
+ osviex_stub->wSuiteMask, osviex_stub->wProductType);
+
+ } else {
+ if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
+
+ /* Win9x build */
+
+ ngx_log_error(NGX_LOG_INFO, log, 0,
+ "OS: %u build:%ud.%ud.%ud, \"%s\"",
+ ngx_win32_version,
+ osvi.dwBuildNumber >> 24,
+ (osvi.dwBuildNumber >> 16) & 0xff,
+ osvi.dwBuildNumber & 0xffff,
+ osvi.szCSDVersion);
+
+ } else {
+
+ /*
+ * VER_PLATFORM_WIN32_NT
+ *
+ * we do not currently support VER_PLATFORM_WIN32_CE
+ * and we do not support VER_PLATFORM_WIN32s at all
+ */
+
+ ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %ud build:%ud, \"%s\"",
+ ngx_win32_version, osvi.dwBuildNumber,
+ osvi.szCSDVersion);
+ }
+ }
}
diff --git a/src/os/win32/ngx_wsarecv.c b/src/os/win32/ngx_wsarecv.c
index bb0e5566c..ac7a5c4c9 100644
--- a/src/os/win32/ngx_wsarecv.c
+++ b/src/os/win32/ngx_wsarecv.c
@@ -25,7 +25,7 @@ ssize_t ngx_wsarecv(ngx_connection_t *c, u_char *buf, size_t size)
rc = WSARecv(c->fd, wsabuf, 1, &bytes, &flags, NULL, NULL);
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "WSARecv: fd:%d rc:%d %d of %d", c->fd, rc, bytes, size);
+ "WSARecv: fd:%d rc:%d %ul of %z", c->fd, rc, bytes, size);
rev = c->read;
@@ -85,6 +85,10 @@ ssize_t ngx_overlapped_wsarecv(ngx_connection_t *c, u_char *buf, size_t size)
return NGX_ERROR;
}
+ ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
+ "WSARecv ovlp: fd:%d %ul of %z",
+ c->fd, rev->available, size);
+
return rev->available;
}
@@ -95,6 +99,9 @@ ssize_t ngx_overlapped_wsarecv(ngx_connection_t *c, u_char *buf, size_t size)
return NGX_ERROR;
}
+ ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
+ "WSARecv: fd:%d %ul of %z", c->fd, bytes, size);
+
return bytes;
}
@@ -110,12 +117,15 @@ ssize_t ngx_overlapped_wsarecv(ngx_connection_t *c, u_char *buf, size_t size)
rev->complete = 0;
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "WSARecv: fd:%d rc:%d %d of %d", c->fd, rc, bytes, size);
+ "WSARecv ovlp: fd:%d rc:%d %ul of %z",
+ c->fd, rc, bytes, size);
if (rc == -1) {
err = ngx_socket_errno;
if (err == WSA_IO_PENDING) {
rev->active = 1;
+ ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
+ "WSARecv() posted");
return NGX_AGAIN;
}
@@ -148,94 +158,3 @@ ssize_t ngx_overlapped_wsarecv(ngx_connection_t *c, u_char *buf, size_t size)
return bytes;
}
-
-#if 0
-
-/* DELELTE IT WHEN ABOVE FUNC WOULD BE TESTED */
-
-ssize_t ngx_wsarecv(ngx_connection_t *c, char *buf, size_t size)
-{
- int rc;
- u_int flags;
- size_t bytes;
- WSABUF wsabuf[1];
- ngx_err_t err;
- ngx_event_t *rev;
- LPWSAOVERLAPPED ovlp;
-
- rev = c->read;
- bytes = 0;
-
- if ((ngx_event_flags & NGX_USE_AIO_EVENT) && rev->ready) {
- rev->ready = 0;
-
- /* the overlapped WSARecv() completed */
-
- if (ngx_event_flags & NGX_USE_IOCP_EVENT) {
- if (rev->ovlp.error) {
- ngx_log_error(NGX_LOG_ERR, c->log, rev->ovlp.error,
- "WSARecv() failed");
- return NGX_ERROR;
- }
-
- return rev->available;
- }
-
- if (WSAGetOverlappedResult(c->fd, (LPWSAOVERLAPPED) &rev->ovlp,
- &bytes, 0, NULL) == 0) {
- err = ngx_socket_errno;
- ngx_log_error(NGX_LOG_CRIT, c->log, err,
- "WSARecv() or WSAGetOverlappedResult() failed");
-
- return NGX_ERROR;
- }
-
- return bytes;
- }
-
- if (ngx_event_flags & NGX_USE_AIO_EVENT) {
- ovlp = (LPWSAOVERLAPPED) &c->read->ovlp;
- ngx_memzero(ovlp, sizeof(WSAOVERLAPPED));
-
- } else {
- ovlp = NULL;
- }
-
- wsabuf[0].buf = buf;
- wsabuf[0].len = size;
- flags = 0;
-
- rc = WSARecv(c->fd, wsabuf, 1, &bytes, &flags, ovlp, NULL);
-
- ngx_log_debug(c->log, "WSARecv: %d:%d" _ rc _ bytes);
-
- if (rc == -1) {
- err = ngx_socket_errno;
- if (err == WSA_IO_PENDING) {
- return NGX_AGAIN;
-
- } else if (err == WSAEWOULDBLOCK) {
- ngx_log_error(NGX_LOG_INFO, c->log, err, "WSARecv() EAGAIN");
- return NGX_AGAIN;
-
- } else {
- ngx_log_error(NGX_LOG_CRIT, c->log, err, "WSARecv() failed");
- return NGX_ERROR;
- }
- }
-
- if (ngx_event_flags & NGX_USE_IOCP_EVENT) {
-
- /*
- * If a socket was bound with I/O completion port
- * then GetQueuedCompletionStatus() would anyway return its status
- * despite that WSARecv() was already completed.
- */
-
- return NGX_AGAIN;
- }
-
- return bytes;
-}
-
-#endif
diff --git a/src/os/win32/ngx_wsasend_chain.c b/src/os/win32/ngx_wsasend_chain.c
index 08f93c80b..1d75e0969 100644
--- a/src/os/win32/ngx_wsasend_chain.c
+++ b/src/os/win32/ngx_wsasend_chain.c
@@ -9,17 +9,21 @@
#include <ngx_event.h>
+#define NGX_WSABUFS 8
+
+
ngx_chain_t *ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in,
off_t limit)
{
int rc;
u_char *prev;
- size_t size;
- u_long sent;
- LPWSABUF wsabuf;
+ u_long size, sent, send, sprev;
+ ngx_uint_t complete;
ngx_err_t err;
ngx_event_t *wev;
- ngx_array_t wsabufs;
+ ngx_array_t vec;
+ LPWSABUF wsabuf;
+ WSABUF wsabufs[NGX_WSABUFS];
ngx_chain_t *cl;
wev = c->write;
@@ -28,80 +32,119 @@ ngx_chain_t *ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in,
return in;
}
+ send = 0;
+ complete = 0;
+
/*
* WSABUFs must be 4-byte aligned otherwise
* WSASend() will return undocumented WSAEINVAL error.
*/
- ngx_init_array(wsabufs, c->pool, 10, sizeof(WSABUF), NGX_CHAIN_ERROR);
+ vec.elts = wsabufs;
+ vec.size = sizeof(WSABUF);
+ vec.nalloc = NGX_WSABUFS;
+ vec.pool = c->pool;
- prev = NULL;
- wsabuf = NULL;
+ for ( ;; ) {
+ prev = NULL;
+ wsabuf = NULL;
+ sprev = send;
- /* create the WSABUF and coalesce the neighbouring bufs */
+ vec.nelts = 0;
- for (cl = in; cl; cl = cl->next) {
+ /* create the WSABUF and coalesce the neighbouring bufs */
- if (prev == cl->buf->pos) {
- wsabuf->len += cl->buf->last - cl->buf->pos;
- prev = cl->buf->last;
+ for (cl = in;
+ cl && vec.nelts < ngx_max_wsabufs && send < limit;
+ cl = cl->next)
+ {
+ if (ngx_buf_special(cl->buf)) {
+ continue;
+ }
+
+ size = cl->buf->last - cl->buf->pos;
+
+ if (send + size > limit) {
+ size = (u_long) (limit - send);
+ }
+
+ if (prev == cl->buf->pos) {
+ wsabuf->len += cl->buf->last - cl->buf->pos;
+
+ } else {
+ if (!(wsabuf = ngx_array_push(&vec))) {
+ return NGX_CHAIN_ERROR;
+ }
+
+ wsabuf->buf = (char *) cl->buf->pos;
+ wsabuf->len = cl->buf->last - cl->buf->pos;
+ }
- } else {
- ngx_test_null(wsabuf, ngx_push_array(&wsabufs), NGX_CHAIN_ERROR);
- wsabuf->buf = (char *) cl->buf->pos;
- wsabuf->len = cl->buf->last - cl->buf->pos;
prev = cl->buf->last;
+ send += size;
}
- }
- rc = WSASend(c->fd, wsabufs.elts, wsabufs.nelts, &sent, 0, NULL, NULL);
+ sent = 0;
- if (rc == -1) {
- err = ngx_errno;
+ rc = WSASend(c->fd, vec.elts, vec.nelts, &sent, 0, NULL, NULL);
- if (err == WSAEWOULDBLOCK) {
- ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
- "WSASend() not ready");
- wev->ready = 0;
- return in;
+ if (rc == -1) {
+ err = ngx_errno;
- } else {
- wev->error = 1;
- ngx_connection_error(c, err, "WSASend() failed");
- return NGX_CHAIN_ERROR;
+ if (err == WSAEWOULDBLOCK) {
+ ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
+ "WSASend() not ready");
+
+ } else {
+ wev->error = 1;
+ ngx_connection_error(c, err, "WSASend() failed");
+ return NGX_CHAIN_ERROR;
+ }
}
- }
- ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "WSASend: %d", sent);
+ ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
+ "WSASend: fd:%d, s:%ul", c->fd, sent);
- c->sent += sent;
+ if (send - sprev == sent) {
+ complete = 1;
+ }
- for (cl = in; cl && sent > 0; cl = cl->next) {
+ c->sent += sent;
- size = cl->buf->last - cl->buf->pos;
+ for (cl = in; cl && sent > 0; cl = cl->next) {
+ if (ngx_buf_special(cl->buf)) {
+ continue;
+ }
- if (sent >= size) {
- sent -= size;
+ if (sent == 0) {
+ break;
+ }
- if (ngx_buf_in_memory(cl->buf)) {
+ size = cl->buf->last - cl->buf->pos;
+
+ if (sent >= size) {
+ sent -= size;
cl->buf->pos = cl->buf->last;
+
+ continue;
}
- continue;
+ cl->buf->pos += sent;
+
+ break;
}
- if (ngx_buf_in_memory(cl->buf)) {
- cl->buf->pos += sent;
+ if (!complete) {
+ wev->ready = 0;
+ return cl;
}
- break;
- }
+ if (send >= limit || cl == NULL) {
+ return cl;
+ }
- if (cl) {
- wev->ready = 0;
+ in = cl;
}
-
- return cl;
}
@@ -111,13 +154,14 @@ ngx_chain_t *ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in,
int rc;
u_char *prev;
size_t size;
- u_long sent;
+ u_long send, sent;
LPWSABUF wsabuf;
ngx_err_t err;
ngx_event_t *wev;
- ngx_array_t wsabufs;
+ ngx_array_t vec;
ngx_chain_t *cl;
LPWSAOVERLAPPED ovlp;
+ WSABUF wsabufs[NGX_WSABUFS];
wev = c->write;
@@ -125,6 +169,9 @@ ngx_chain_t *ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in,
return in;
}
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
+ "wev->complete: %d", wev->complete);
+
if (!wev->complete) {
/* post the overlapped WSASend() */
@@ -134,32 +181,52 @@ ngx_chain_t *ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in,
* WSASend() will return undocumented WSAEINVAL error.
*/
- ngx_init_array(wsabufs, c->pool, 10, sizeof(WSABUF), NGX_CHAIN_ERROR);
+ vec.elts = wsabufs;
+ vec.nelts = 0;
+ vec.size = sizeof(WSABUF);
+ vec.nalloc = NGX_WSABUFS;
+ vec.pool = c->pool;
+ send = 0;
prev = NULL;
wsabuf = NULL;
/* create the WSABUF and coalesce the neighbouring bufs */
- for (cl = in; cl; cl = cl->next) {
+ for (cl = in;
+ cl && vec.nelts < ngx_max_wsabufs && send < limit;
+ cl = cl->next)
+ {
+ if (ngx_buf_special(cl->buf)) {
+ continue;
+ }
+
+ size = cl->buf->last - cl->buf->pos;
+
+ if (send + size > limit) {
+ size = (u_long) (limit - send);
+ }
if (prev == cl->buf->pos) {
wsabuf->len += cl->buf->last - cl->buf->pos;
- prev = cl->buf->last;
-
+
} else {
- ngx_test_null(wsabuf, ngx_push_array(&wsabufs),
- NGX_CHAIN_ERROR);
+ if (!(wsabuf = ngx_array_push(&vec))) {
+ return NGX_CHAIN_ERROR;
+ }
+
wsabuf->buf = (char *) cl->buf->pos;
wsabuf->len = cl->buf->last - cl->buf->pos;
- prev = cl->buf->last;
}
+
+ prev = cl->buf->last;
+ send += size;
}
ovlp = (LPWSAOVERLAPPED) &c->write->ovlp;
ngx_memzero(ovlp, sizeof(WSAOVERLAPPED));
- rc = WSASend(c->fd, wsabufs.elts, wsabufs.nelts, &sent, 0, ovlp, NULL);
+ rc = WSASend(c->fd, vec.elts, vec.nelts, &sent, 0, ovlp, NULL);
wev->complete = 0;
@@ -167,6 +234,8 @@ ngx_chain_t *ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in,
err = ngx_errno;
if (err == WSA_IO_PENDING) {
+ ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
+ "WSASend() posted");
wev->active = 1;
return in;
@@ -188,6 +257,9 @@ ngx_chain_t *ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in,
return in;
}
+ ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
+ "WSASend: fd:%d, s:%ul", c->fd, sent);
+
} else {
/* the overlapped WSASend() complete */
@@ -214,27 +286,30 @@ ngx_chain_t *ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in,
}
}
- ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "WSASend: %d", sent);
+ ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
+ "WSASend ovlp: fd:%d, s:%ul", c->fd, sent);
c->sent += sent;
for (cl = in; cl && sent > 0; cl = cl->next) {
+ if (ngx_buf_special(cl->buf)) {
+ continue;
+ }
+
+ if (sent == 0) {
+ break;
+ }
size = cl->buf->last - cl->buf->pos;
if (sent >= size) {
sent -= size;
-
- if (ngx_buf_in_memory(cl->buf)) {
- cl->buf->pos = cl->buf->last;
- }
+ cl->buf->pos = cl->buf->last;
continue;
}
- if (ngx_buf_in_memory(cl->buf)) {
- cl->buf->pos += sent;
- }
+ cl->buf->pos += sent;
break;
}
diff --git a/src/os/win32/tray.ico b/src/os/win32/tray.ico
new file mode 100644
index 000000000..077cbac27
--- /dev/null
+++ b/src/os/win32/tray.ico
Binary files differ