mirror of
https://github.com/nginx/nginx.git
synced 2024-11-24 04:49:01 +08:00
nginx-0.0.1-2003-11-27-22:01:37 import
This commit is contained in:
parent
0e499db3ed
commit
764543e734
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -22,6 +22,7 @@ fi
|
||||
|
||||
|
||||
NGX_FUNC_INC="#include <sys/sendfile.h>"
|
||||
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)"
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -62,4 +62,9 @@ extern int rotate;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SOLARIS
|
||||
#include <ngx_solaris.h>
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _NGX_OS_H_INCLUDED_ */
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user