Mercurial > hg > nginx
changeset 428:5e73d0ea4dab
nginx-0.0.11-2004-09-16-20:10:13 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 16 Sep 2004 16:10:13 +0000 |
parents | 0d08eabe5c7b |
children | 694cd6cdb714 |
files | src/core/nginx.h src/os/unix/ngx_atomic.h src/os/unix/ngx_freebsd_sendfile_chain.c src/os/unix/ngx_linux_sendfile_chain.c src/os/unix/ngx_solaris_sendfilev_chain.c |
diffstat | 5 files changed, 62 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/src/core/nginx.h +++ b/src/core/nginx.h @@ -2,7 +2,7 @@ #define _NGINX_H_INCLUDED_ -#define NGINX_VER "nginx/0.0.10" +#define NGINX_VER "nginx/0.0.11" #define NGINX_VAR "NGINX" #define NGX_NEWPID_EXT ".newbin"
--- a/src/os/unix/ngx_atomic.h +++ b/src/os/unix/ngx_atomic.h @@ -108,7 +108,7 @@ static ngx_inline uint32_t ngx_atomic_cm ngx_atomic_t old, ngx_atomic_t set) { - uint32_t res = (u_int32_t) set; + uint32_t res = (uint32_t) set; __asm__ volatile (
--- a/src/os/unix/ngx_freebsd_sendfile_chain.c +++ b/src/os/unix/ngx_freebsd_sendfile_chain.c @@ -12,14 +12,14 @@ /* * Although FreeBSD sendfile() allows to pass a header and a trailer * it can not send a header with a part of the file in one packet until - * FreeBSD 5.2-STABLE. Besides over the fast ethernet connection sendfile() + * FreeBSD 5.3. Besides over the fast ethernet connection sendfile() * may send the partially filled packets, i.e. the 8 file pages may be sent * as the 11 full 1460-bytes packets, then one incomplete 324-bytes packet, * and then again the 11 full 1460-bytes packets. * * So we use the TCP_NOPUSH option (similar to Linux's TCP_CORK) * to postpone the sending - it not only sends a header and the first part - * of the file in one packet but also sends file pages in the full packets. + * of the file in one packet but also sends the file pages in the full packets. * * But until FreeBSD 4.5 the turning TCP_NOPUSH off does not flush a pending * data that less than MSS so that data may be sent with 5 second delay. @@ -28,6 +28,10 @@ */ +#define NGX_HEADERS 8 +#define NGX_TRAILERS 4 + + ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) { @@ -37,13 +41,13 @@ ngx_chain_t *ngx_freebsd_sendfile_chain( size_t hsize, fsize; ssize_t size; ngx_uint_t eintr, eagain, complete; - struct iovec *iov; - struct sf_hdtr hdtr; ngx_err_t err; ngx_buf_t *file; ngx_array_t header, trailer; ngx_event_t *wev; ngx_chain_t *cl; + struct sf_hdtr hdtr; + struct iovec *iov, headers[NGX_HEADERS], trailers[NGX_TRAILERS]; wev = c->write; @@ -66,6 +70,16 @@ ngx_chain_t *ngx_freebsd_sendfile_chain( send = 0; eagain = 0; + header.elts = headers; + header.size = sizeof(struct iovec); + header.nalloc = NGX_HEADERS; + header.pool = c->pool; + + trailer.elts = trailers; + trailer.size = sizeof(struct iovec); + trailer.nalloc = NGX_TRAILERS; + trailer.pool = c->pool; + for ( ;; ) { file = NULL; fsize = 0; @@ -74,10 +88,8 @@ ngx_chain_t *ngx_freebsd_sendfile_chain( complete = 0; sprev = send; - 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); + header.nelts = 0; + trailer.nelts = 0; /* create the header iovec and coalesce the neighbouring bufs */ @@ -106,7 +118,10 @@ ngx_chain_t *ngx_freebsd_sendfile_chain( iov->iov_len += size; } else { - ngx_test_null(iov, ngx_push_array(&header), NGX_CHAIN_ERROR); + if (!(iov = ngx_array_push(&header))) { + return NGX_CHAIN_ERROR; + } + iov->iov_base = (void *) cl->buf->pos; iov->iov_len = size; } @@ -177,8 +192,10 @@ ngx_chain_t *ngx_freebsd_sendfile_chain( iov->iov_len += size; } else { - ngx_test_null(iov, ngx_push_array(&trailer), - NGX_CHAIN_ERROR); + if (!(iov = ngx_array_push(&trailer))) { + return NGX_CHAIN_ERROR; + } + iov->iov_base = (void *) cl->buf->pos; iov->iov_len = size; }
--- a/src/os/unix/ngx_linux_sendfile_chain.c +++ b/src/os/unix/ngx_linux_sendfile_chain.c @@ -19,6 +19,9 @@ */ +#define NGX_HEADERS 8 + + ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) { @@ -28,12 +31,12 @@ ngx_chain_t *ngx_linux_sendfile_chain(ng size_t fsize; ssize_t size, sent; ngx_uint_t eintr, complete; - struct iovec *iov; ngx_err_t err; ngx_buf_t *file; ngx_array_t header; ngx_event_t *wev; ngx_chain_t *cl; + struct iovec *iov, headers[NGX_HEADERS]; #if (HAVE_SENDFILE64) off_t offset; #else @@ -48,6 +51,11 @@ ngx_chain_t *ngx_linux_sendfile_chain(ng send = 0; + header.elts = headers; + header.size = sizeof(struct iovec); + header.nalloc = NGX_HEADERS; + header.pool = c->pool; + for ( ;; ) { file = NULL; fsize = 0; @@ -55,8 +63,7 @@ ngx_chain_t *ngx_linux_sendfile_chain(ng complete = 0; sprev = send; - ngx_init_array(header, c->pool, 10, sizeof(struct iovec), - NGX_CHAIN_ERROR); + header.nelts = 0; prev = NULL; iov = NULL; @@ -85,7 +92,10 @@ ngx_chain_t *ngx_linux_sendfile_chain(ng iov->iov_len += size; } else { - ngx_test_null(iov, ngx_push_array(&header), NGX_CHAIN_ERROR); + if (!(iov = ngx_array_push(&header))) { + return NGX_CHAIN_ERROR; + } + iov->iov_base = (void *) cl->buf->pos; iov->iov_len = size; }
--- a/src/os/unix/ngx_solaris_sendfilev_chain.c +++ b/src/os/unix/ngx_solaris_sendfilev_chain.c @@ -9,6 +9,9 @@ #include <ngx_event.h> +#define NGX_SENDFILEVECS 16 + + ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) { @@ -19,7 +22,7 @@ ngx_chain_t *ngx_solaris_sendfilev_chain ssize_t n; ngx_int_t eintr, complete; ngx_err_t err; - sendfilevec_t *sfv; + sendfilevec_t *sfv, sfvs[NGX_SENDFILEVECS]; ngx_array_t vec; ngx_event_t *wev; ngx_chain_t *cl, *tail; @@ -33,6 +36,11 @@ ngx_chain_t *ngx_solaris_sendfilev_chain send = 0; complete = 0; + vec.elts = sfvs; + vec.size = sizeof(sendfilevec_t); + vec.nalloc = NGX_SENDFILEVECS; + vec.pool = c->pool; + for ( ;; ) { fd = SFV_FD_SELF; prev = NULL; @@ -42,8 +50,7 @@ ngx_chain_t *ngx_solaris_sendfilev_chain sent = 0; sprev = send; - ngx_init_array(vec, c->pool, 10, sizeof(sendfilevec_t), - NGX_CHAIN_ERROR); + vec.nelts = 0; /* create the sendfilevec and coalesce the neighbouring bufs */ @@ -66,7 +73,10 @@ ngx_chain_t *ngx_solaris_sendfilev_chain sfv->sfv_len += size; } else { - ngx_test_null(sfv, ngx_push_array(&vec), NGX_CHAIN_ERROR); + if (!(sfv = ngx_array_push(&vec))) { + return NGX_CHAIN_ERROR; + } + sfv->sfv_fd = SFV_FD_SELF; sfv->sfv_flag = 0; sfv->sfv_off = (off_t) (uintptr_t) cl->buf->pos; @@ -96,7 +106,10 @@ ngx_chain_t *ngx_solaris_sendfilev_chain sfv->sfv_len += size; } else { - ngx_test_null(sfv, ngx_push_array(&vec), NGX_CHAIN_ERROR); + if (!(sfv = ngx_array_push(&vec))) { + return NGX_CHAIN_ERROR; + } + fd = cl->buf->file->fd; sfv->sfv_fd = fd; sfv->sfv_flag = 0;