aboutsummaryrefslogtreecommitdiff
path: root/src/os/unix
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2003-10-12 16:49:16 +0000
committerIgor Sysoev <igor@sysoev.ru>2003-10-12 16:49:16 +0000
commit0a280a3fc081877bc45cbdc0511a8cc42675213c (patch)
treeb5ea17e3be5eab555cf40f6304338a88bd641527 /src/os/unix
parentb3e73d869ecef9248468e0ccc2d7d0abdbee495c (diff)
downloadnginx-0a280a3fc081877bc45cbdc0511a8cc42675213c.tar.gz
nginx-0a280a3fc081877bc45cbdc0511a8cc42675213c.zip
nginx-0.0.1-2003-10-12-20:49:16 import
Diffstat (limited to 'src/os/unix')
-rw-r--r--src/os/unix/ngx_aio_write.c1
-rw-r--r--src/os/unix/ngx_aio_write_chain.c39
-rw-r--r--src/os/unix/ngx_freebsd_init.c5
-rw-r--r--src/os/unix/ngx_freebsd_sendfile_chain.c4
-rw-r--r--src/os/unix/ngx_recv.c5
-rw-r--r--src/os/unix/ngx_writev_chain.c5
6 files changed, 42 insertions, 17 deletions
diff --git a/src/os/unix/ngx_aio_write.c b/src/os/unix/ngx_aio_write.c
index 3a4d8e0b4..5eded37b7 100644
--- a/src/os/unix/ngx_aio_write.c
+++ b/src/os/unix/ngx_aio_write.c
@@ -109,6 +109,7 @@ ngx_log_debug(ev->log, "aio: aiocb: %08x" _ &ev->aiocb);
return NGX_ERROR;
}
+ ev->active = 0;
ngx_log_debug(ev->log, "aio_write: %d" _ rc);
return rc;
diff --git a/src/os/unix/ngx_aio_write_chain.c b/src/os/unix/ngx_aio_write_chain.c
index b12afec41..b8760b0fa 100644
--- a/src/os/unix/ngx_aio_write_chain.c
+++ b/src/os/unix/ngx_aio_write_chain.c
@@ -1,6 +1,7 @@
#include <ngx_config.h>
#include <ngx_core.h>
+#include <ngx_event.h>
#include <ngx_aio.h>
@@ -17,10 +18,18 @@ ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in)
ce = in;
while (ce) {
+
+ /* we can post the single aio operation only */
+
+ if (c->write->active) {
+ return ce;
+ }
+
buf = prev = ce->hunk->pos;
size = 0;
/* coalesce the neighbouring chain entries */
+
while (ce && prev == ce->hunk->pos) {
size += ce->hunk->last - ce->hunk->pos;
prev = ce->hunk->last;
@@ -33,34 +42,32 @@ ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in)
ngx_log_debug(c->log, "aio_write rc: %d" _ rc);
#endif
+ if (rc == NGX_ERROR) {
+ return NGX_CHAIN_ERROR;
+ }
+
if (rc > 0) {
sent += rc;
c->sent += rc;
-
- } else if (rc == NGX_ERROR) {
- return NGX_CHAIN_ERROR;
-
- } else if (rc == NGX_AGAIN) {
- break;
}
- }
#if (NGX_DEBUG_WRITE_CHAIN)
- ngx_log_debug(c->log, "aio_write sent: " OFF_FMT _ c->sent);
+ ngx_log_debug(c->log, "aio_write sent: " OFF_FMT _ c->sent);
#endif
- for (ce = in; ce; ce = ce->next) {
+ for (ce = in; ce; ce = ce->next) {
- if (sent >= ce->hunk->last - ce->hunk->pos) {
- sent -= ce->hunk->last - ce->hunk->pos;
- ce->hunk->pos = ce->hunk->last;
+ if (sent >= ce->hunk->last - ce->hunk->pos) {
+ sent -= ce->hunk->last - ce->hunk->pos;
+ ce->hunk->pos = ce->hunk->last;
- continue;
- }
+ continue;
+ }
- ce->hunk->pos += sent;
+ ce->hunk->pos += sent;
- break;
+ break;
+ }
}
return ce;
diff --git a/src/os/unix/ngx_freebsd_init.c b/src/os/unix/ngx_freebsd_init.c
index 1a3077114..058711681 100644
--- a/src/os/unix/ngx_freebsd_init.c
+++ b/src/os/unix/ngx_freebsd_init.c
@@ -19,8 +19,13 @@ ngx_os_io_t ngx_os_io = {
ngx_unix_recv,
ngx_readv_chain,
NULL,
+#if (HAVE_FREEBSD_SENDFILE)
ngx_freebsd_sendfile_chain,
NGX_HAVE_SENDFILE|NGX_HAVE_ZEROCOPY
+#else
+ ngx_writev_chain,
+ NULL
+#endif
};
diff --git a/src/os/unix/ngx_freebsd_sendfile_chain.c b/src/os/unix/ngx_freebsd_sendfile_chain.c
index 5db40808c..f7751a772 100644
--- a/src/os/unix/ngx_freebsd_sendfile_chain.c
+++ b/src/os/unix/ngx_freebsd_sendfile_chain.c
@@ -34,6 +34,10 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
ngx_hunk_t *file;
ngx_chain_t *ce, *tail;
+ if (!c->write->ready) {
+ return in;
+ }
+
do {
ce = in;
file = NULL;
diff --git a/src/os/unix/ngx_recv.c b/src/os/unix/ngx_recv.c
index 154565413..cef432821 100644
--- a/src/os/unix/ngx_recv.c
+++ b/src/os/unix/ngx_recv.c
@@ -43,8 +43,11 @@ ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size)
if (n >= 0) {
if (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) {
rev->available -= n;
- if (rev->available == 0) {
+ if (rev->available <= 0) {
rev->ready = 0;
+ if (rev->available < 0) {
+ rev->available = 0;
+ }
}
return n;
diff --git a/src/os/unix/ngx_writev_chain.c b/src/os/unix/ngx_writev_chain.c
index 32b2dd48d..70141e341 100644
--- a/src/os/unix/ngx_writev_chain.c
+++ b/src/os/unix/ngx_writev_chain.c
@@ -1,6 +1,7 @@
#include <ngx_config.h>
#include <ngx_core.h>
+#include <ngx_event.h>
ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in)
@@ -13,6 +14,10 @@ ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in)
ngx_array_t iovecs;
ngx_chain_t *ce;
+ if (!c->write->ready) {
+ return in;
+ }
+
ngx_init_array(iovecs, c->pool, 10, sizeof(struct iovec), NGX_CHAIN_ERROR);
prev = NULL;