diff options
author | Igor Sysoev <igor@sysoev.ru> | 2003-11-27 19:01:37 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2003-11-27 19:01:37 +0000 |
commit | 764543e73426fd00741483ff830cf09bfb73752f (patch) | |
tree | 27b8bad85c18469e593d30ee137fdb5fe1a16af4 /src | |
parent | 0e499db3ed63432cfacd08282cce1d42b568b567 (diff) | |
download | nginx-764543e73426fd00741483ff830cf09bfb73752f.tar.gz nginx-764543e73426fd00741483ff830cf09bfb73752f.zip |
nginx-0.0.1-2003-11-27-22:01:37 import
Diffstat (limited to 'src')
-rw-r--r-- | src/os/unix/ngx_linux_config.h | 17 | ||||
-rw-r--r-- | src/os/unix/ngx_linux_sendfile_chain.c | 17 | ||||
-rw-r--r-- | src/os/unix/ngx_os.h | 5 | ||||
-rw-r--r-- | src/os/unix/ngx_solaris_init.c | 5 | ||||
-rw-r--r-- | src/os/unix/ngx_solaris_sendfilev_chain.c | 13 | ||||
-rw-r--r-- | src/os/unix/ngx_writev_chain.c | 90 |
6 files changed, 90 insertions, 57 deletions
diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h index 59e1b0976..0ec0532f3 100644 --- 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 <unistd.h> @@ -28,7 +26,13 @@ #include <sys/sysctl.h> #include <sys/wait.h> #include <sys/socket.h> + +#if (HAVE_SENDFILE64) #include <sys/sendfile.h> +#else +extern ssize_t sendfile(int s, int fd, int32_t *offset, size_t size); +#endif + #include <netinet/in.h> #include <netinet/tcp.h> /* TCP_CORK */ #include <arpa/inet.h> @@ -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 index 0b8e41792..9b311b21e 100644 --- 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(ngx_connection_t *c, ngx_chain_t *in) { 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(ngx_connection_t *c, ngx_chain_t *in) 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 index 1cc597b20..6f0a2e8b3 100644 --- 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 <ngx_solaris.h> +#endif + + #endif /* _NGX_OS_H_INCLUDED_ */ diff --git a/src/os/unix/ngx_solaris_init.c b/src/os/unix/ngx_solaris_init.c index 3b1383887..b2aba61b9 100644 --- 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 index 8fe5cef1e..c7d69feaf 100644 --- 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(ngx_connection_t *c, ngx_chain_t *in) 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(ngx_connection_t *c, ngx_chain_t *in) 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_connection_t *c, ngx_chain_t *in) 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(ngx_connection_t *c, ngx_chain_t *in) } } - 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(ngx_connection_t *c, ngx_chain_t *in) } #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 index 85d345c46..a9cac1dee 100644 --- 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_connection_t *c, ngx_chain_t *in) 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; + } + + continue; + } if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { - cl->hunk->pos = cl->hunk->last; + cl->hunk->pos += sent; } - continue; + break; } - if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { - cl->hunk->pos += sent; - } + } while (eintr); - break; + if (cl) { + wev->ready = 0; } return cl; |