# HG changeset patch # User Igor Sysoev # Date 1069959697 0 # Node ID 34995c5ec6c44ca80294d5d79fd1a0c8b87edce5 # Parent 0b81c7a0b133f71f47e8676b2f5a5982bf294944 nginx-0.0.1-2003-11-27-22:01:37 import diff --git a/auto/func b/auto/func --- a/auto/func +++ b/auto/func @@ -9,7 +9,7 @@ echo "$NGX_UNISTD_H" > autotest.c echo "$NGX_FUNC_INC" >> autotest.c echo "int main() { $NGX_FUNC_TEST; return 0; }" >> autotest.c -eval "$CC $CC_TEST_FLAGS -o autotest autotest.c > $NGX_ERR 2>&1" +eval "$CC $CC_TEST_FLAGS -o autotest autotest.c $NGX_FUNC_LIBS > $NGX_ERR 2>&1" if [ -x autotest ]; then echo " + $NGX_FUNC found" diff --git a/auto/os/linux b/auto/os/linux --- a/auto/os/linux +++ b/auto/os/linux @@ -9,8 +9,7 @@ ZLIB_LIB="-lz" # TODO check sendfile64() -#CC_TEST_FLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE" -CC_TEST_FLAGS="-D_GNU_SOURCE" +CC_TEST_FLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE" # STUB CORE_SRCS="$CORE_SRCS $LINUX_SENDFILE_SRCS" diff --git a/auto/os/solaris b/auto/os/solaris --- a/auto/os/solaris +++ b/auto/os/solaris @@ -22,6 +22,7 @@ fi NGX_FUNC_INC="#include " +NGX_FUNC_LIBS="-lsendfile" NGX_FUNC_TEST="int fd = 1; sendfilevec_t vec[1]; size_t sent = 1; ssize_t n; n = sendfilev(fd, vec, 1, &sent)" diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h --- a/src/os/unix/ngx_linux_config.h +++ b/src/os/unix/ngx_linux_config.h @@ -4,10 +4,8 @@ #define _GNU_SOURCE /* pread(), pwrite(), gethostname() */ -#if 0 #define _FILE_OFFSET_BITS 64 #define _LARGEFILE_SOURCE -#endif #include @@ -28,7 +26,13 @@ #include #include #include + +#if (HAVE_SENDFILE64) #include +#else +extern ssize_t sendfile(int s, int fd, int32_t *offset, size_t size); +#endif + #include #include /* TCP_CORK */ #include @@ -37,15 +41,6 @@ -#if 0 -#define SIZE_FMT "%d" -#define SIZEX_FMT "%x" -#define PID_FMT "%d" -#define RLIM_FMT "%lu" -#endif - - - #ifndef HAVE_SELECT #define HAVE_SELECT 1 #endif diff --git a/src/os/unix/ngx_linux_sendfile_chain.c b/src/os/unix/ngx_linux_sendfile_chain.c --- a/src/os/unix/ngx_linux_sendfile_chain.c +++ b/src/os/unix/ngx_linux_sendfile_chain.c @@ -8,7 +8,7 @@ ngx_chain_t *ngx_linux_sendfile_chain(ng { int rc; char *prev; - off_t offset; + off_t fprev; size_t size, fsize, sent; ngx_int_t use_cork, eintr; struct iovec *iov; @@ -17,6 +17,11 @@ ngx_chain_t *ngx_linux_sendfile_chain(ng ngx_array_t header; ngx_event_t *wev; ngx_chain_t *cl, *tail; +#if (HAVE_SENDFILE64) + off_t offset; +#else + int32_t offset; +#endif wev = c->write; @@ -82,20 +87,20 @@ ngx_log_debug(c->log, "CORK"); file = cl->hunk; fsize = (size_t) (file->file_last - file->file_pos); - offset = file->file_last; + fprev = file->file_last; cl = cl->next; /* coalesce the neighbouring file hunks */ while (cl && (cl->hunk->type & NGX_HUNK_FILE)) { if (file->file->fd != cl->hunk->file->fd - || offset != cl->hunk->file_pos) + || fprev != cl->hunk->file_pos) { break; } fsize += (size_t) (cl->hunk->file_last - cl->hunk->file_pos); - offset = cl->hunk->file_last; + fprev = cl->hunk->file_last; cl = cl->next; } } @@ -108,7 +113,11 @@ ngx_log_debug(c->log, "CORK"); tail = cl; if (fsize) { +#if (HAVE_SENDFILE64) offset = file->file_pos; +#else + offset = (int32_t) file->file_pos; +#endif rc = sendfile(c->fd, file->file->fd, &offset, fsize); if (rc == -1) { diff --git a/src/os/unix/ngx_os.h b/src/os/unix/ngx_os.h --- a/src/os/unix/ngx_os.h +++ b/src/os/unix/ngx_os.h @@ -62,4 +62,9 @@ extern int rotate; #endif +#ifdef SOLARIS +#include +#endif + + #endif /* _NGX_OS_H_INCLUDED_ */ diff --git a/src/os/unix/ngx_solaris_init.c b/src/os/unix/ngx_solaris_init.c --- a/src/os/unix/ngx_solaris_init.c +++ b/src/os/unix/ngx_solaris_init.c @@ -12,8 +12,13 @@ ngx_os_io_t ngx_os_io = { ngx_unix_recv, NULL, NULL, +#if (HAVE_SENDFILE) + ngx_solaris_sendfilev_chain, + NGX_IO_SENDFILE +#else ngx_writev_chain, 0 +#endif }; diff --git a/src/os/unix/ngx_solaris_sendfilev_chain.c b/src/os/unix/ngx_solaris_sendfilev_chain.c --- a/src/os/unix/ngx_solaris_sendfilev_chain.c +++ b/src/os/unix/ngx_solaris_sendfilev_chain.c @@ -9,9 +9,10 @@ ngx_chain_t *ngx_solaris_sendfilev_chain int fd; char *prev; off_t fprev; - size_t sent; + size_t sent, size; ssize_t n; ngx_int_t eintr; + ngx_err_t err; sendfilevec_t *sfv; ngx_array_t vec; ngx_event_t *wev; @@ -26,10 +27,14 @@ ngx_chain_t *ngx_solaris_sendfilev_chain do { fd = SFV_FD_SELF; prev = NULL; + fprev = 0; sfv = NULL; eintr = 0; sent = 0; + ngx_init_array(vec, c->pool, 10, sizeof(sendfilevec_t), + NGX_CHAIN_ERROR); + /* create the sendfilevec and coalesce the neighbouring hunks */ for (cl = in; cl; cl = cl->next) { @@ -47,7 +52,7 @@ ngx_chain_t *ngx_solaris_sendfilev_chain ngx_test_null(sfv, ngx_push_array(&vec), NGX_CHAIN_ERROR); sfv->sfv_fd = SFV_FD_SELF; sfv->sfv_flag = 0; - sfv->sfv_off = cl->hunk->pos; + sfv->sfv_off = (off_t) (uintptr_t) cl->hunk->pos; sfv->sfv_len = cl->hunk->last - cl->hunk->pos; } @@ -72,7 +77,7 @@ ngx_chain_t *ngx_solaris_sendfilev_chain } } - n = sendfile(c->fd, vec->elts, vec->nelts, &sent); + n = sendfilev(c->fd, vec.elts, vec.nelts, &sent); if (n == -1) { err = ngx_errno; @@ -93,7 +98,7 @@ ngx_chain_t *ngx_solaris_sendfilev_chain } #if (NGX_DEBUG_WRITE_CHAIN) - ngx_log_debug(c->log, "sendfilev: %d " SIZE_T_FMT ", n _ sent); + ngx_log_debug(c->log, "sendfilev: %d " SIZE_T_FMT _ n _ sent); #endif c->sent += sent; diff --git a/src/os/unix/ngx_writev_chain.c b/src/os/unix/ngx_writev_chain.c --- a/src/os/unix/ngx_writev_chain.c +++ b/src/os/unix/ngx_writev_chain.c @@ -10,80 +10,94 @@ ngx_chain_t *ngx_writev_chain(ngx_connec ssize_t n, size; off_t sent; struct iovec *iov; + ngx_int_t eintr; ngx_err_t err; ngx_array_t io; ngx_chain_t *cl; + ngx_event_t *wev; - if (!c->write->ready) { + wev = c->write; + + if (!wev->ready) { return in; } ngx_init_array(io, c->pool, 10, sizeof(struct iovec), NGX_CHAIN_ERROR); - prev = NULL; - iov = NULL; + do { + prev = NULL; + iov = NULL; + eintr = 0; - /* create the iovec and coalesce the neighbouring hunks */ + /* create the iovec and coalesce the neighbouring hunks */ - for (cl = in; cl; cl = cl->next) { + for (cl = in; cl; cl = cl->next) { - if (prev == cl->hunk->pos) { - iov->iov_len += cl->hunk->last - cl->hunk->pos; - prev = cl->hunk->last; + if (prev == cl->hunk->pos) { + iov->iov_len += cl->hunk->last - cl->hunk->pos; + prev = cl->hunk->last; - } else { - ngx_test_null(iov, ngx_push_array(&io), NGX_CHAIN_ERROR); - iov->iov_base = cl->hunk->pos; - iov->iov_len = cl->hunk->last - cl->hunk->pos; - prev = cl->hunk->last; + } else { + ngx_test_null(iov, ngx_push_array(&io), NGX_CHAIN_ERROR); + iov->iov_base = cl->hunk->pos; + iov->iov_len = cl->hunk->last - cl->hunk->pos; + prev = cl->hunk->last; + } } - } - n = writev(c->fd, io.elts, io.nelts); + n = writev(c->fd, io.elts, io.nelts); - if (n == -1) { - err = ngx_errno; - if (err == NGX_EAGAIN) { - ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EAGAIN"); + if (n == -1) { + err = ngx_errno; + if (err == NGX_EAGAIN) { + ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EAGAIN"); - } else if (err == NGX_EINTR) { - ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EINTR"); + } 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; + } else { + wev->error = 1; + ngx_log_error(NGX_LOG_CRIT, c->log, err, "writev() failed"); + return NGX_CHAIN_ERROR; + } } - } - sent = n > 0 ? n : 0; + sent = n > 0 ? n : 0; #if (NGX_DEBUG_WRITE_CHAIN) - ngx_log_debug(c->log, "writev: " OFF_T_FMT _ sent); + ngx_log_debug(c->log, "writev: " OFF_T_FMT _ sent); #endif - c->sent += sent; + c->sent += sent; - for (cl = in; cl && sent > 0; cl = cl->next) { + for (cl = in; cl && sent > 0; cl = cl->next) { - size = cl->hunk->last - cl->hunk->pos; + size = cl->hunk->last - cl->hunk->pos; ngx_log_debug(c->log, "SIZE: %d" _ size); - if (sent >= size) { - sent -= size; + 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_IN_MEMORY) { + cl->hunk->pos = cl->hunk->last; + } + + continue; } - continue; + if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { + cl->hunk->pos += sent; + } + + break; } - if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { - cl->hunk->pos += sent; - } + } while (eintr); - break; + if (cl) { + wev->ready = 0; } return cl;