nginx-0.0.1-2003-11-25-23:44:56 import
diff --git a/src/os/unix/ngx_files.h b/src/os/unix/ngx_files.h
index 51cba70..09fc856 100644
--- a/src/os/unix/ngx_files.h
+++ b/src/os/unix/ngx_files.h
@@ -82,7 +82,7 @@
#define ngx_read_dir_n "readdir()"
-#define ngx_create_dir(name) mkdir(name, (mode_t) 0700)
+#define ngx_create_dir(name) mkdir(name, 0700)
#define ngx_create_dir_n "mkdir()"
diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h
index a8014ec..24fb7b0 100644
--- a/src/os/unix/ngx_freebsd_config.h
+++ b/src/os/unix/ngx_freebsd_config.h
@@ -3,7 +3,7 @@
#include <unistd.h>
-#include <stddef.h> /* offsetof */
+#include <stddef.h> /* offsetof() */
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
@@ -27,35 +27,6 @@
#include <osreldate.h>
-
-/* TODO: autoconf */
-#if (i386)
-
-#if 0
-#define OFF_FMT "%lld"
-#endif
-
-#define SIZE_FMT "%d"
-#define SIZEX_FMT "%x"
-
-#else /* amd64, alpha, sparc64, ia64 */
-
-#if 0
-#define OFF_FMT "%ld"
-#endif
-
-#define SIZE_FMT "%ld"
-#define SIZEX_FMT "%lx"
-
-#endif
-
-#if 0
-#define TIME_FMT "%ld"
-#endif
-#define PID_FMT "%d"
-#define RLIM_FMT "%lld"
-
-
#ifndef HAVE_SELECT
#define HAVE_SELECT 1
#endif
@@ -89,58 +60,11 @@
#endif
-/* STUB */
-#define HAVE_PREAD 1
-#define HAVE_PWRITE 1
-#define HAVE_LOCALTIME_R 1
-
-
- /* FreeBSD sendfile */
-
-#if __FreeBSD_version >= 300007
-
-#ifndef HAVE_FREEBSD_SENDFILE
-#define HAVE_FREEBSD_SENDFILE 1
-#endif
-
-#endif
-
-
-#if (HAVE_FREEBSD_SENDFILE)
-#define HAVE_SENDFILE 1
-#endif
-
-
- /* FreeBSD kqueue */
-
-#if (__FreeBSD__ == 4 && __FreeBSD_version >= 410000) \
- || __FreeBSD_version >= 500011
-
-#ifndef HAVE_KQUEUE
-#define HAVE_KQUEUE 1
-#endif
-
-#endif
-
#if (HAVE_KQUEUE)
#include <sys/event.h>
#endif
- /* kqueue's NOTE_LOWAT */
-
-#if (__FreeBSD__ == 4 && __FreeBSD_version >= 430000) \
- || __FreeBSD_version >= 500018
-
-#ifndef HAVE_LOWAT_EVENT
-#define HAVE_LOWAT_EVENT 1
-#endif
-
-#endif
-
-
-
-
#ifndef HAVE_INHERITED_NONBLOCK
#define HAVE_INHERITED_NONBLOCK 1
#endif
diff --git a/src/os/unix/ngx_freebsd_init.c b/src/os/unix/ngx_freebsd_init.c
index 4f3146d..3446382 100644
--- a/src/os/unix/ngx_freebsd_init.c
+++ b/src/os/unix/ngx_freebsd_init.c
@@ -20,12 +20,12 @@
ngx_unix_recv,
ngx_readv_chain,
NULL,
-#if (HAVE_FREEBSD_SENDFILE)
+#if (HAVE_SENDFILE)
ngx_freebsd_sendfile_chain,
- NGX_HAVE_SENDFILE|NGX_HAVE_ZEROCOPY
+ NGX_HAVE_SENDFILE
#else
ngx_writev_chain,
- NULL
+ 0
#endif
};
@@ -97,7 +97,7 @@
version, __FreeBSD_version);
-#if (HAVE_FREEBSD_SENDFILE)
+#if (HAVE_SENDFILE)
/*
* The determination of the sendfile() nbytes bug is complex enough.
@@ -127,7 +127,7 @@
#endif
-#endif /* HAVE_FREEBSD_SENDFILE */
+#endif /* HAVE_SENDFILE */
if ((version < 500000 && version >= 440003) || version >= 500017) {
diff --git a/src/os/unix/ngx_freebsd_sendfile_chain.c b/src/os/unix/ngx_freebsd_sendfile_chain.c
index 610c7d7..6b0e62e 100644
--- a/src/os/unix/ngx_freebsd_sendfile_chain.c
+++ b/src/os/unix/ngx_freebsd_sendfile_chain.c
@@ -22,16 +22,17 @@
ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
{
- int rc, eintr, eagain;
+ int rc;
char *prev;
off_t sent, fprev;
size_t hsize, fsize, size;
+ ngx_int_t eintr, eagain;
struct iovec *iov;
struct sf_hdtr hdtr;
ngx_err_t err;
+ ngx_hunk_t *file;
ngx_array_t header, trailer;
ngx_event_t *wev;
- ngx_hunk_t *file;
ngx_chain_t *cl, *tail;
wev = c->write;
@@ -53,7 +54,6 @@
#endif
do {
- cl = in;
file = NULL;
fsize = 0;
hsize = 0;
@@ -156,7 +156,7 @@
ngx_log_debug(c->log, "NOPUSH");
if (ngx_tcp_nopush(c->fd) == NGX_ERROR) {
- ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno,
+ ngx_log_error(NGX_LOG_CRIT, c->log, ngx_errno,
ngx_tcp_nopush_n " failed");
return NGX_CHAIN_ERROR;
}
diff --git a/src/os/unix/ngx_linux.h b/src/os/unix/ngx_linux.h
new file mode 100644
index 0000000..12ccb97
--- /dev/null
+++ b/src/os/unix/ngx_linux.h
@@ -0,0 +1,8 @@
+#ifndef _NGX_LINUX_H_INCLUDED_
+#define _NGX_LINUX_H_INCLUDED_
+
+
+ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
+
+
+#endif /* _NGX_LINUX_H_INCLUDED_ */
diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h
index 22bb7c7..761263f 100644
--- a/src/os/unix/ngx_linux_config.h
+++ b/src/os/unix/ngx_linux_config.h
@@ -2,14 +2,14 @@
#define _NGX_LINUX_CONFIG_H_INCLUDED_
-#define _GNU_SOURCE /* pread, pwrite, gethostname, bzero */
+#define _GNU_SOURCE /* pread(), pwrite(), gethostname() */
#define _FILE_OFFSET_BITS 64
#define _LARGEFILE_SOURCE
#include <unistd.h>
-#include <stddef.h> /* offsetof */
+#include <stddef.h> /* offsetof() */
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
@@ -27,16 +27,17 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <dirent.h>
#include <netdb.h>
-#define OFF_FMT "%lld"
+#if 0
#define SIZE_FMT "%d"
#define SIZEX_FMT "%x"
-#define TIME_FMT "%ld"
#define PID_FMT "%d"
#define RLIM_FMT "%lu"
+#endif
diff --git a/src/os/unix/ngx_linux_sendfile_chain.c b/src/os/unix/ngx_linux_sendfile_chain.c
index 6ea67f4..31bcf3d 100644
--- a/src/os/unix/ngx_linux_sendfile_chain.c
+++ b/src/os/unix/ngx_linux_sendfile_chain.c
@@ -1,183 +1,214 @@
#include <ngx_config.h>
#include <ngx_core.h>
-#include <ngx_linux_init.h>
+#include <ngx_event.h>
ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
{
- int rc, on, off;
+ int rc;
char *prev;
- size_t hsize, size;
- ssize_t sent;
+ off_t fprev;
+ size_t size, fsize, sent;
+ ngx_int_t use_cork, eintr;
struct iovec *iov;
- struct sf_hdtr hdtr;
ngx_err_t err;
- ngx_array_t header, trailer;
ngx_hunk_t *file;
- ngx_chain_t *ce;
+ ngx_array_t header;
+ ngx_event_t *wev;
+ ngx_chain_t *cl;
- ce = in;
- file = NULL;
- hsize = 0;
+ wev = c->write;
- on = 1;
- off = 0;
+ if (!wev->ready) {
+ return in;
+ }
- ngx_init_array(header, c->pool, 10, sizeof(struct iovec), NGX_CHAIN_ERROR);
- ngx_init_array(trailer, c->pool, 10, sizeof(struct iovec), NGX_CHAIN_ERROR);
+ cork = 0;
- /* create the header iovec */
- if (ngx_hunk_in_memory_only(ce->hunk)) {
+ do {
+ file = NULL;
+ fsize = 0;
+ eintr = 0;
+
+ ngx_init_array(header, c->pool, 10, sizeof(struct iovec),
+ NGX_CHAIN_ERROR);
+
prev = NULL;
iov = NULL;
- /* create the iovec and coalesce the neighbouring chain entries */
- while (ce && ngx_hunk_in_memory_only(ce->hunk)) {
+ /* create the iovec and coalesce the neighbouring hunks */
- if (prev == ce->hunk->pos) {
- iov->iov_len += ce->hunk->last - ce->hunk->pos;
- prev = ce->hunk->last;
+ for (cl = in; cl; cl = cl->next) {
+ if (ngx_hunk_special(cl->hunk)) {
+ continue;
+ }
+
+ if (!ngx_hunk_in_memory_only(cl->hunk)) {
+ break;
+ }
+
+ if (prev == cl->hunk->pos) {
+ iov->iov_len += cl->hunk->last - cl->hunk->pos;
} else {
ngx_test_null(iov, ngx_push_array(&header), NGX_CHAIN_ERROR);
- iov->iov_base = ce->hunk->pos;
- iov->iov_len = ce->hunk->last - ce->hunk->pos;
- prev = ce->hunk->last;
+ iov->iov_base = cl->hunk->pos;
+ iov->iov_len = cl->hunk->last - cl->hunk->pos;
}
- if (ngx_freebsd_sendfile_nbytes_bug) {
- hsize += ce->hunk->last - ce->hunk->pos;
- }
-
- ce = ce->next;
- }
- }
-
- /* TODO: coalesce the neighbouring file hunks */
- if (ce && (ce->hunk->type & NGX_HUNK_FILE)) {
- file = ce->hunk;
- ce = ce->next;
- }
-
- /* create the trailer iovec */
- if (ce && ngx_hunk_in_memory_only(ce->hunk)) {
- prev = NULL;
- iov = NULL;
-
- /* create the iovec and coalesce the neighbouring chain entries */
- while (ce && ngx_hunk_in_memory_only(ce->hunk)) {
-
- if (prev == ce->hunk->pos) {
- iov->iov_len += ce->hunk->last - ce->hunk->pos;
- prev = ce->hunk->last;
-
- } else {
- ngx_test_null(iov, ngx_push_array(&trailer), NGX_CHAIN_ERROR);
- iov->iov_base = ce->hunk->pos;
- iov->iov_len = ce->hunk->last - ce->hunk->pos;
- prev = ce->hunk->last;
- }
-
- ce = ce->next;
- }
- }
-
- if (file) {
- if (setsockopt(c->fd, IPPROTO_TCP, TCP_CORK,
- (const void *) &on, sizeof(int)) == -1) {
- ngx_log_error(NGX_LOG_CRIT, c->log, err,
- "setsockopt(TCP_CORK, 1) failed");
- return NGX_CHAIN_ERROR;
+ prev = cl->hunk->last;
}
+ /* set TCP_CORK if there is a header before a file */
- rc = sendfile(c->fd, file->file->fd, file->file_pos,
- (size_t) (file->file_last - file->file_pos));
+ if (!c->tcp_nopush
+ && header.nelts != 0
+ && cl
+ && cl->hunk->type & NGX_HUNK_FILE)
+ {
+ c->tcp_nopush = 1;
- if (rc == -1) {
- err = ngx_errno;
- if (err == NGX_EAGAIN) {
- ngx_log_error(NGX_LOG_INFO, c->log, err, "senfile() EAGAIN");
+ngx_log_debug(c->log, "CORK");
- } else if (err == NGX_EINTR) {
- ngx_log_error(NGX_LOG_INFO, c->log, err, "senfile() EINTR");
-
- } else {
- ngx_log_error(NGX_LOG_CRIT, c->log, err, "sendfile() failed");
+ if (ngx_tcp_nopush(c->fd) == NGX_ERROR) {
+ ngx_log_error(NGX_LOG_CRIT, c->log, ngx_errno,
+ ngx_tcp_nopush_n " failed");
return NGX_CHAIN_ERROR;
}
}
- sent = rc > 0 ? rc : 0;
+ if (header.nelts == 0 && cl && cl->hunk->type & NGX_HUNK_FILE) {
-#if (NGX_DEBUG_WRITE_CHAIN)
- ngx_log_debug(c->log, "sendfile: %d, @%qd %d:%d" _
- rc _ file->file_pos _ sent _
- (size_t) (file->file_last - file->file_pos));
-#endif
+ /* get the file hunk */
- } else {
- rc = writev(c->fd, (struct iovec *) header.elts, header.nelts);
+ file = cl->hunk;
+ fsize = (size_t) (file->file_last - file->file_pos);
+ fprev = file->file_last;
+ cl = cl->next;
- if (rc == -1) {
- err = ngx_errno;
- if (err == NGX_EAGAIN) {
- ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EAGAIN");
+ /* coalesce the neighbouring file hunks */
- } else if (err == NGX_EINTR) {
- ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EINTR");
+ while (cl && (cl->hunk->type & NGX_HUNK_FILE)) {
+ if (file->file->fd != cl->hunk->file->fd
+ || fprev != cl->hunk->file_pos)
+ {
+ break;
+ }
- } else {
- ngx_log_error(NGX_LOG_CRIT, c->log, err, "writev() failed");
- return NGX_CHAIN_ERROR;
+ fsize += (size_t) (cl->hunk->file_last - cl->hunk->file_pos);
+ fprev = cl->hunk->file_last;
+ cl = cl->next;
}
}
- sent = rc > 0 ? rc : 0;
+ /*
+ * the tail is the rest of the chain that exceeded
+ * a single sendfile() capability
+ */
+
+ tail = cl;
+
+ if (fsize) {
+ rc = sendfile(c->fd, file->file->fd, file->file_pos, fsize);
+
+ if (rc == -1) {
+ err = ngx_errno;
+ if (err == NGX_EAGAIN) {
+ ngx_log_error(NGX_LOG_INFO, c->log, err,
+ "sendfile() EAGAIN");
+
+ } else if (err == NGX_EINTR) {
+ eintr = 1;
+ ngx_log_error(NGX_LOG_INFO, c->log, err,
+ "sendfile() EINTR");
+
+ } else {
+ ngx_log_error(NGX_LOG_CRIT, c->log, err,
+ "sendfile() failed");
+ return NGX_CHAIN_ERROR;
+ }
+ }
+
+ sent = rc > 0 ? rc : 0;
#if (NGX_DEBUG_WRITE_CHAIN)
- ngx_log_debug(c->log, "writev: %d" _ sent);
+ ngx_log_debug(c->log, "sendfile: %d, @" OFF_T_FMT " %d:%d" _
+ rc _ file->file_pos _ sent _ fsize);
#endif
- }
-
- c->sent += sent;
-
- for (ce = in; ce && sent > 0; ce = ce->next) {
-
- if (ce->hunk->type & NGX_HUNK_IN_MEMORY) {
- size = ce->hunk->last - ce->hunk->pos;
} else {
- size = ce->hunk->file_last - ce->hunk->file_pos;
- }
+ rc = writev(c->fd, header.elts, header.nelts);
- if (sent >= size) {
- sent -= size;
+ if (rc == -1) {
+ err = ngx_errno;
+ if (err == NGX_EAGAIN) {
+ ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EAGAIN");
- if (ce->hunk->type & NGX_HUNK_IN_MEMORY) {
- ce->hunk->pos = ce->hunk->last;
+ } else if (err == NGX_EINTR) {
+ eintr = 1;
+ ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EINTR");
+
+ } else {
+ ngx_log_error(NGX_LOG_CRIT, c->log, err, "writev() failed");
+ return NGX_CHAIN_ERROR;
+ }
}
- if (ce->hunk->type & NGX_HUNK_FILE) {
- ce->hunk->file_pos = ce->hunk->file_last;
+ sent = rc > 0 ? rc : 0;
+
+#if (NGX_DEBUG_WRITE_CHAIN)
+ ngx_log_debug(c->log, "writev: %d" _ sent);
+#endif
+ }
+
+ c->sent += sent;
+
+ for (cl = in; cl; cl = cl->next) {
+
+ if (ngx_hunk_special(cl->hunk)) {
+ continue;
}
- continue;
+ if (sent == 0) {
+ break;
+ }
+
+ size = ngx_hunk_size(cl->hunk);
+
+ if (sent >= size) {
+ sent -= size;
+
+ if (cl->hunk->type & NGX_HUNK_IN_MEMORY) {
+ cl->hunk->pos = cl->hunk->last;
+ }
+
+ if (cl->hunk->type & NGX_HUNK_FILE) {
+ cl->hunk->file_pos = cl->hunk->file_last;
+ }
+
+ continue;
+ }
+
+ if (cl->hunk->type & NGX_HUNK_IN_MEMORY) {
+ cl->hunk->pos += sent;
+ }
+
+ if (cl->hunk->type & NGX_HUNK_FILE) {
+ cl->hunk->file_pos += sent;
+ }
+
+ break;
}
- if (ce->hunk->type & NGX_HUNK_IN_MEMORY) {
- ce->hunk->pos += sent;
- }
+ in = cl;
- if (ce->hunk->type & NGX_HUNK_FILE) {
- ce->hunk->file_pos += sent;
- }
+ /* "tail == in" means that a single sendfile() is complete */
- break;
+ } while ((tail && tail == in) || eintr);
+
+ if (in) {
+ wev->ready = 0;
}
- ngx_destroy_array(&trailer);
- ngx_destroy_array(&header);
-
- return ce;
+ return in;
}
diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c
index 7462dcf..7550af0 100644
--- a/src/os/unix/ngx_posix_init.c
+++ b/src/os/unix/ngx_posix_init.c
@@ -56,7 +56,7 @@
}
ngx_log_error(NGX_LOG_INFO, log, 0,
- "getrlimit(RLIMIT_NOFILE): " RLIM_FMT ":" RLIM_FMT,
+ "getrlimit(RLIMIT_NOFILE): " RLIM_T_FMT ":" RLIM_T_FMT,
rlmt.rlim_cur, rlmt.rlim_max);
ngx_max_sockets = rlmt.rlim_cur;
diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c
index e487151..04e2475 100644
--- a/src/os/unix/ngx_process.c
+++ b/src/os/unix/ngx_process.c
@@ -41,9 +41,10 @@
break;
default:
+ break;
}
-ngx_log_debug(log, "parent process, child: " PID_FMT _ pid);
+ngx_log_debug(log, "parent process, child: " PID_T_FMT _ pid);
/* book keeping */
@@ -97,7 +98,7 @@
one = 1;
ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, 0,
- "process " PID_FMT " exited with code %d", pid, status);
+ "process " PID_T_FMT " exited with code %d", pid, status);
/* TODO: restart handler */
diff --git a/src/os/unix/ngx_socket.c b/src/os/unix/ngx_socket.c
index 48016cb..8b34c1c 100644
--- a/src/os/unix/ngx_socket.c
+++ b/src/os/unix/ngx_socket.c
@@ -55,6 +55,28 @@
(const void *) &tcp_nopush, sizeof(int));
}
+#elif __linux__
+
+int ngx_tcp_nopush(ngx_socket_t s)
+{
+ int cork;
+
+ cork = 1;
+
+ return setsockopt(s, IPPROTO_TCP, TCP_CORK,
+ (const void *) &cork, sizeof(int));
+}
+
+int ngx_tcp_push(ngx_socket_t s)
+{
+ int cork;
+
+ cork = 0;
+
+ return setsockopt(s, IPPROTO_TCP, TCP_CORK,
+ (const void *) &cork, sizeof(int));
+}
+
#else
int ngx_tcp_nopush(ngx_socket_t s)
diff --git a/src/os/unix/ngx_socket.h b/src/os/unix/ngx_socket.h
index 2a412d3..4e2eab4 100644
--- a/src/os/unix/ngx_socket.h
+++ b/src/os/unix/ngx_socket.h
@@ -29,11 +29,19 @@
#endif
int ngx_tcp_nopush(ngx_socket_t s);
-#define ngx_tcp_nopush_n "setsockopt(TCP_NOPUSH)"
-
int ngx_tcp_push(ngx_socket_t s);
+
+#ifdef __linux__
+
+#define ngx_tcp_nopush_n "setsockopt(TCP_CORK)"
+#define ngx_tcp_push_n "setsockopt(!TCP_CORK)"
+
+#else
+
+#define ngx_tcp_nopush_n "setsockopt(TCP_NOPUSH)"
#define ngx_tcp_push_n "setsockopt(!TCP_NOPUSH)"
+#endif
#define ngx_shutdown_socket shutdown
diff --git a/src/os/unix/ngx_solaris_config.h b/src/os/unix/ngx_solaris_config.h
index e592355..57ef672 100644
--- a/src/os/unix/ngx_solaris_config.h
+++ b/src/os/unix/ngx_solaris_config.h
@@ -10,7 +10,7 @@
#include <unistd.h>
#include <inttypes.h>
-#include <stddef.h> /* offsetof */
+#include <stddef.h> /* offsetof() */
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
@@ -28,14 +28,14 @@
#include <netdb.h>
-typedef uint32_t u_int32_t;
-
+#if 0
#define OFF_FMT "%lld"
#define SIZE_FMT "%d"
#define SIZEX_FMT "%x"
#define TIME_FMT "%ld"
#define PID_FMT "%ld"
#define RLIM_FMT "%lu"
+#endif
#ifndef HAVE_SELECT
diff --git a/src/os/unix/ngx_writev_chain.c b/src/os/unix/ngx_writev_chain.c
index 9b9e629..85d345c 100644
--- a/src/os/unix/ngx_writev_chain.c
+++ b/src/os/unix/ngx_writev_chain.c
@@ -58,7 +58,7 @@
sent = n > 0 ? n : 0;
#if (NGX_DEBUG_WRITE_CHAIN)
- ngx_log_debug(c->log, "writev: " OFF_FMT _ sent);
+ ngx_log_debug(c->log, "writev: " OFF_T_FMT _ sent);
#endif
c->sent += sent;