aboutsummaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
Diffstat (limited to 'src/os')
-rw-r--r--src/os/unix/ngx_files.c2
-rw-r--r--src/os/unix/ngx_freebsd_sendfile_chain.c7
-rw-r--r--src/os/unix/ngx_linux_sendfile_chain.c59
-rw-r--r--src/os/unix/ngx_solaris_sendfilev_chain.c46
-rw-r--r--src/os/win32/ngx_files.c2
-rw-r--r--src/os/win32/ngx_wsasend_chain.c177
6 files changed, 60 insertions, 233 deletions
diff --git a/src/os/unix/ngx_files.c b/src/os/unix/ngx_files.c
index 5d551ebe7..8b906f097 100644
--- a/src/os/unix/ngx_files.c
+++ b/src/os/unix/ngx_files.c
@@ -125,7 +125,7 @@ ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl,
ngx_err_t err;
ngx_array_t io;
- /* use pwrite() if there's the only hunk in a chain */
+ /* use pwrite() if there's the only buf in a chain */
if (cl->next == NULL) {
return ngx_write_file(file, cl->buf->pos,
diff --git a/src/os/unix/ngx_freebsd_sendfile_chain.c b/src/os/unix/ngx_freebsd_sendfile_chain.c
index 694ea2226..abc3d19b5 100644
--- a/src/os/unix/ngx_freebsd_sendfile_chain.c
+++ b/src/os/unix/ngx_freebsd_sendfile_chain.c
@@ -162,7 +162,9 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
if (file) {
- if (ngx_freebsd_use_tcp_nopush && c->tcp_nopush == 0) {
+ if (ngx_freebsd_use_tcp_nopush
+ && c->tcp_nopush == NGX_TCP_NOPUSH_UNSET)
+ {
if (ngx_tcp_nopush(c->fd) == NGX_ERROR) {
err = ngx_errno;
@@ -180,7 +182,8 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
}
} else {
- c->tcp_nopush = 1;
+ c->tcp_nopush = NGX_TCP_NOPUSH_SET;
+
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
"tcp_nopush");
}
diff --git a/src/os/unix/ngx_linux_sendfile_chain.c b/src/os/unix/ngx_linux_sendfile_chain.c
index 0c6b9d0e8..75f51cfd1 100644
--- a/src/os/unix/ngx_linux_sendfile_chain.c
+++ b/src/os/unix/ngx_linux_sendfile_chain.c
@@ -58,32 +58,32 @@ ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
/* create the iovec and coalesce the neighbouring bufs */
for (cl = in; cl && header.nelts < IOV_MAX; cl = cl->next) {
- if (ngx_hunk_special(cl->hunk)) {
+ if (ngx_buf_special(cl->buf)) {
continue;
}
- if (!ngx_hunk_in_memory_only(cl->hunk)) {
+ if (!ngx_buf_in_memory_only(cl->buf)) {
break;
}
- if (prev == cl->hunk->pos) {
- iov->iov_len += cl->hunk->last - cl->hunk->pos;
+ if (prev == cl->buf->pos) {
+ iov->iov_len += cl->buf->last - cl->buf->pos;
} else {
ngx_test_null(iov, ngx_push_array(&header), NGX_CHAIN_ERROR);
- iov->iov_base = (void *) cl->hunk->pos;
- iov->iov_len = cl->hunk->last - cl->hunk->pos;
+ iov->iov_base = (void *) cl->buf->pos;
+ iov->iov_len = cl->buf->last - cl->buf->pos;
}
- prev = cl->hunk->last;
+ prev = cl->buf->last;
}
/* set TCP_CORK if there is a header before a file */
- if (!c->tcp_nopush == 0
+ if (c->tcp_nopush == NGX_TCP_NOPUSH_UNSET
&& header.nelts != 0
&& cl
- && cl->hunk->type & NGX_HUNK_FILE)
+ && cl->buf->in_file)
{
if (ngx_tcp_nopush(c->fd) == NGX_ERROR) {
err = ngx_errno;
@@ -100,32 +100,33 @@ ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
}
} else {
- c->tcp_nopush = 1;
+ c->tcp_nopush = NGX_TCP_NOPUSH_SET;
+
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
"tcp_nopush");
}
}
- if (header.nelts == 0 && cl && cl->hunk->type & NGX_HUNK_FILE) {
+ if (header.nelts == 0 && cl && cl->buf->in_file) {
- /* get the file hunk */
+ /* get the file buf */
- file = cl->hunk;
+ file = cl->buf;
fsize = (size_t) (file->file_last - file->file_pos);
fprev = file->file_last;
cl = cl->next;
- /* coalesce the neighbouring file hunks */
+ /* coalesce the neighbouring file bufs */
- while (cl && (cl->hunk->type & NGX_HUNK_FILE)) {
- if (file->file->fd != cl->hunk->file->fd
- || fprev != cl->hunk->file_pos)
+ while (cl && (cl->buf->in_file)) {
+ if (file->file->fd != cl->buf->file->fd
+ || fprev != cl->buf->file_pos)
{
break;
}
- fsize += (size_t) (cl->hunk->file_last - cl->hunk->file_pos);
- fprev = cl->hunk->file_last;
+ fsize += (size_t) (cl->buf->file_last - cl->buf->file_pos);
+ fprev = cl->buf->file_last;
cl = cl->next;
}
}
@@ -199,7 +200,7 @@ ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
for (cl = in; cl; cl = cl->next) {
- if (ngx_hunk_special(cl->hunk)) {
+ if (ngx_buf_special(cl->buf)) {
continue;
}
@@ -207,28 +208,28 @@ ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
break;
}
- size = ngx_hunk_size(cl->hunk);
+ size = ngx_buf_size(cl->buf);
if (sent >= size) {
sent -= size;
- if (cl->hunk->type & NGX_HUNK_IN_MEMORY) {
- cl->hunk->pos = cl->hunk->last;
+ if (ngx_buf_in_memory(cl->buf)) {
+ cl->buf->pos = cl->buf->last;
}
- if (cl->hunk->type & NGX_HUNK_FILE) {
- cl->hunk->file_pos = cl->hunk->file_last;
+ if (cl->buf->in_file) {
+ cl->buf->file_pos = cl->buf->file_last;
}
continue;
}
- if (cl->hunk->type & NGX_HUNK_IN_MEMORY) {
- cl->hunk->pos += sent;
+ if (ngx_buf_in_memory(cl->buf)) {
+ cl->buf->pos += sent;
}
- if (cl->hunk->type & NGX_HUNK_FILE) {
- cl->hunk->file_pos += sent;
+ if (cl->buf->in_file) {
+ cl->buf->file_pos += sent;
}
break;
diff --git a/src/os/unix/ngx_solaris_sendfilev_chain.c b/src/os/unix/ngx_solaris_sendfilev_chain.c
index 964027f65..352c1623d 100644
--- a/src/os/unix/ngx_solaris_sendfilev_chain.c
+++ b/src/os/unix/ngx_solaris_sendfilev_chain.c
@@ -43,42 +43,42 @@ ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in)
/* create the sendfilevec and coalesce the neighbouring bufs */
for (cl = in; cl && vec.nelts < IOV_MAX; cl = cl->next) {
- if (ngx_hunk_special(cl->hunk)) {
+ if (ngx_buf_special(cl->buf)) {
continue;
}
- if (ngx_hunk_in_memory_only(cl->hunk)) {
+ if (ngx_buf_in_memory_only(cl->buf)) {
fd = SFV_FD_SELF;
- if (prev == cl->hunk->pos) {
- sfv->sfv_len += cl->hunk->last - cl->hunk->pos;
+ if (prev == cl->buf->pos) {
+ sfv->sfv_len += cl->buf->last - cl->buf->pos;
} else {
ngx_test_null(sfv, ngx_push_array(&vec), NGX_CHAIN_ERROR);
sfv->sfv_fd = SFV_FD_SELF;
sfv->sfv_flag = 0;
- sfv->sfv_off = (off_t) (uintptr_t) cl->hunk->pos;
- sfv->sfv_len = cl->hunk->last - cl->hunk->pos;
+ sfv->sfv_off = (off_t) (uintptr_t) cl->buf->pos;
+ sfv->sfv_len = cl->buf->last - cl->buf->pos;
}
- prev = cl->hunk->last;
+ prev = cl->buf->last;
} else {
prev = NULL;
- if (fd == cl->hunk->file->fd && fprev == cl->hunk->file_pos) {
- sfv->sfv_len += cl->hunk->file_last - cl->hunk->file_pos;
+ if (fd == cl->buf->file->fd && fprev == cl->buf->file_pos) {
+ sfv->sfv_len += cl->buf->file_last - cl->buf->file_pos;
} else {
ngx_test_null(sfv, ngx_push_array(&vec), NGX_CHAIN_ERROR);
- fd = cl->hunk->file->fd;
+ fd = cl->buf->file->fd;
sfv->sfv_fd = fd;
sfv->sfv_flag = 0;
- sfv->sfv_off = cl->hunk->file_pos;
- sfv->sfv_len = cl->hunk->file_last - cl->hunk->file_pos;
+ sfv->sfv_off = cl->buf->file_pos;
+ sfv->sfv_len = cl->buf->file_last - cl->buf->file_pos;
}
- fprev = cl->hunk->file_last;
+ fprev = cl->buf->file_last;
}
}
@@ -117,7 +117,7 @@ ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in)
for (cl = in; cl; cl = cl->next) {
- if (ngx_hunk_special(cl->hunk)) {
+ if (ngx_buf_special(cl->buf)) {
continue;
}
@@ -125,28 +125,28 @@ ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in)
break;
}
- size = ngx_hunk_size(cl->hunk);
+ size = ngx_buf_size(cl->buf);
if (sent >= size) {
sent -= size;
- if (cl->hunk->type & NGX_HUNK_IN_MEMORY) {
- cl->hunk->pos = cl->hunk->last;
+ if (ngx_buf_in_memory(cl->buf)) {
+ cl->buf->pos = cl->buf->last;
}
- if (cl->hunk->type & NGX_HUNK_FILE) {
- cl->hunk->file_pos = cl->hunk->file_last;
+ if (cl->buf->in_file) {
+ cl->buf->file_pos = cl->buf->file_last;
}
continue;
}
- if (cl->hunk->type & NGX_HUNK_IN_MEMORY) {
- cl->hunk->pos += sent;
+ if (ngx_buf_in_memory(cl->buf)) {
+ cl->buf->pos += sent;
}
- if (cl->hunk->type & NGX_HUNK_FILE) {
- cl->hunk->file_pos += sent;
+ if (cl->buf->in_file) {
+ cl->buf->file_pos += sent;
}
break;
diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c
index 2185dcf5a..6ed4ff00f 100644
--- a/src/os/win32/ngx_files.c
+++ b/src/os/win32/ngx_files.c
@@ -143,7 +143,7 @@ ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl,
prev = buf;
size = 0;
- /* coalesce the neighbouring hunks */
+ /* coalesce the neighbouring bufs */
while (cl && prev == cl->buf->pos) {
size += cl->buf->last - cl->buf->pos;
diff --git a/src/os/win32/ngx_wsasend_chain.c b/src/os/win32/ngx_wsasend_chain.c
index 46e03da65..4ada9ea4e 100644
--- a/src/os/win32/ngx_wsasend_chain.c
+++ b/src/os/win32/ngx_wsasend_chain.c
@@ -241,180 +241,3 @@ ngx_chain_t *ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in)
return cl;
}
-
-
-#if 0
-
-ngx_chain_t *ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in)
-{
- int rc;
- char *prev;
- size_t size, sent;
- LPWSABUF wsabuf;
- ngx_err_t err;
- ngx_event_t *wev;
- ngx_array_t wsabufs;
- ngx_chain_t *ce;
- LPWSAOVERLAPPED ovlp;
-
-#if 0
-
-iocp:
- if ready
- get result
- update chain
- return if done;
- wsasend
-
-non-block
- for ( ;; ) {
- wsasend
- if no again
- update chain
- return if done;
- }
-
-
- for ( ;; ) {
-
- make buffers and limit data for both ovlp and nonblocked,
- configured in events module
-
- if (iocp && ready) {
- get result
-
- } else {
- if (file)
- transmitfile
- else
- wsasend
-
- if (iocp)
- return chain
- return chain if again
- here is result
- }
-
- if (result)
- update chain;
- return chain if done
- }
- }
-
-
-#endif
-
- wev = c->write;
-
- if (((ngx_event_flags & NGX_USE_AIO_EVENT) && !wev->ready)
- || ((ngx_event_flags & NGX_USE_AIO_EVENT) == 0))
- {
- /*
- * WSABUFs must be 4-byte aligned otherwise
- * WSASend() will return undocumented WSAEINVAL error.
- */
-
- ngx_init_array(wsabufs, c->pool, 10, sizeof(WSABUF), NGX_CHAIN_ERROR);
-
- prev = NULL;
- wsabuf = NULL;
-
- /* create the WSABUF and coalesce the neighbouring chain entries */
- for (ce = in; ce; ce = ce->next) {
-
- if (prev == ce->hunk->pos) {
- wsabuf->len += ce->hunk->last - ce->hunk->pos;
- prev = ce->hunk->last;
-
- } else {
- ngx_test_null(wsabuf, ngx_push_array(&wsabufs),
- NGX_CHAIN_ERROR);
- wsabuf->buf = ce->hunk->pos;
- wsabuf->len = ce->hunk->last - ce->hunk->pos;
- prev = ce->hunk->last;
- }
- }
-
- if (ngx_event_flags & NGX_USE_AIO_EVENT) {
- ovlp = (LPWSAOVERLAPPED) &c->write->ovlp;
- ngx_memzero(ovlp, sizeof(WSAOVERLAPPED));
-
- } else {
- ovlp = NULL;
- }
-
- rc = WSASend(c->fd, wsabufs.elts, wsabufs.nelts, &sent, 0, ovlp, NULL);
-
- if (rc == -1) {
- err = ngx_errno;
- if (err == WSA_IO_PENDING) {
- sent = 0;
-
- } else if (err == WSAEWOULDBLOCK) {
- sent = 0;
- ngx_log_error(NGX_LOG_INFO, c->log, err, "WSASend() EAGAIN");
-
- } else {
- ngx_log_error(NGX_LOG_CRIT, c->log, err, "WSASend() failed");
- return NGX_CHAIN_ERROR;
- }
-
- } else {
-
- if (ngx_event_flags & NGX_USE_IOCP_EVENT) {
-
- /*
- * If a socket was bound with I/O completion port then
- * GetQueuedCompletionStatus() would anyway return its status
- * despite that WSASend() was already completed.
- */
-
- sent = 0;
- }
- }
-
- } else {
- if (ngx_event_flags & NGX_USE_IOCP_EVENT) {
- wev->ready = 0;
-
- /* the overlapped WSASend() completed */
-
- if (wev->ovlp.error) {
- ngx_log_error(NGX_LOG_ERR, c->log, wev->ovlp.error,
- "WSASend() failed");
- return NGX_CHAIN_ERROR;
- }
-
- sent = wev->available;
- }
- }
-
- ngx_log_debug(c->log, "WSASend(): %d" _ sent);
-
- c->sent += sent;
-
- for (ce = in; ce && sent > 0; ce = ce->next) {
-
- size = ce->hunk->last - ce->hunk->pos;
-
- if (sent >= size) {
- sent -= size;
-
- if (ce->hunk->type & NGX_HUNK_IN_MEMORY) {
- ce->hunk->pos = ce->hunk->last;
- }
-
- continue;
- }
-
- if (ce->hunk->type & NGX_HUNK_IN_MEMORY) {
- ce->hunk->pos += sent;
- }
-
- break;
- }
-
- return ce;
-}
-
-#endif