aboutsummaryrefslogtreecommitdiff
path: root/src/os/unix/ngx_linux_sendfile_chain.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2004-02-09 07:46:43 +0000
committerIgor Sysoev <igor@sysoev.ru>2004-02-09 07:46:43 +0000
commit7af6b16936b630feabecbce0dbc9cf84b4943481 (patch)
tree18301d35a84907e66fe94ddc7600d4ec6d600409 /src/os/unix/ngx_linux_sendfile_chain.c
parent9260294400c902904cdf791c9c2e8fd069feec63 (diff)
downloadnginx-7af6b16936b630feabecbce0dbc9cf84b4943481.tar.gz
nginx-7af6b16936b630feabecbce0dbc9cf84b4943481.zip
nginx-0.0.2-2004-02-09-10:46:43 import
Diffstat (limited to 'src/os/unix/ngx_linux_sendfile_chain.c')
-rw-r--r--src/os/unix/ngx_linux_sendfile_chain.c73
1 files changed, 42 insertions, 31 deletions
diff --git a/src/os/unix/ngx_linux_sendfile_chain.c b/src/os/unix/ngx_linux_sendfile_chain.c
index 73e2aec3b..39c2e831d 100644
--- a/src/os/unix/ngx_linux_sendfile_chain.c
+++ b/src/os/unix/ngx_linux_sendfile_chain.c
@@ -6,8 +6,8 @@
/*
* On Linux up to 2.4.21 sendfile() (syscall #187) works with 32-bit
- * offsets only and the including <sys/sendfile.h> breaks the compiling if
- * off_t is 64 bit wide. So we use own sendfile() definition where offset
+ * offsets only and the including <sys/sendfile.h> breaks the compiling
+ * if off_t is 64 bit wide. So we use own sendfile() definition where offset
* parameter is int32_t and use sendfile() with the file parts below 2G.
*
* Linux 2.4.21 has a new sendfile64() syscall #239.
@@ -80,14 +80,24 @@ ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
&& cl
&& cl->hunk->type & NGX_HUNK_FILE)
{
- c->tcp_nopush = 1;
+ if (ngx_tcp_nopush(c->fd) == NGX_ERROR) {
+ err = ngx_errno;
- ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "tcp_nopush");
+ /*
+ * there is a tiny chance to be interrupted, however
+ * we continue a processing without the TCP_CORK
+ */
- if (ngx_tcp_nopush(c->fd) == NGX_ERROR) {
- ngx_log_error(NGX_LOG_CRIT, c->log, ngx_errno,
- ngx_tcp_nopush_n " failed");
- return NGX_CHAIN_ERROR;
+ if (err != NGX_EINTR) {
+ wev->error = 1;
+ ngx_connection_error(c, err, ngx_tcp_nopush_n " failed");
+ return NGX_CHAIN_ERROR;
+ }
+
+ } else {
+ c->tcp_nopush = 1;
+ ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
+ "tcp_nopush");
}
}
@@ -132,51 +142,52 @@ ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
if (rc == -1) {
err = ngx_errno;
- if (err == NGX_EAGAIN) {
- ngx_log_error(NGX_LOG_INFO, c->log, err,
- "sendfile() EAGAIN");
- } else if (err == NGX_EINTR) {
- eintr = 1;
- ngx_log_error(NGX_LOG_INFO, c->log, err,
- "sendfile() EINTR");
+ if (err == NGX_EAGAIN || err == NGX_EINTR) {
+ if (err == NGX_EINTR) {
+ eintr = 1;
+ }
+
+ ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
+ "sendfile() is not ready");
} else {
- ngx_log_error(NGX_LOG_CRIT, c->log, err,
- "sendfile() failed");
+ wev->error = 1;
+ ngx_connection_error(c, err, "sendfile() failed");
return NGX_CHAIN_ERROR;
}
}
sent = rc > 0 ? rc : 0;
-#if (NGX_DEBUG_WRITE_CHAIN)
- ngx_log_debug(c->log, "sendfile: %d, @" OFF_T_FMT " %d:%d" _
- rc _ file->file_pos _ sent _ fsize);
-#endif
+ ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0,
+ "sendfile: %d, @" OFF_T_FMT " %d:%d",
+ rc, file->file_pos, sent, fsize);
+
} else {
rc = writev(c->fd, header.elts, header.nelts);
if (rc == -1) {
err = ngx_errno;
- if (err == NGX_EAGAIN) {
- ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EAGAIN");
- } else if (err == NGX_EINTR) {
- eintr = 1;
- ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EINTR");
+ if (err == NGX_EAGAIN || err == NGX_EINTR) {
+ if (err == NGX_EINTR) {
+ eintr = 1;
+ }
+
+ ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
+ "writev() not ready");
} else {
- ngx_log_error(NGX_LOG_CRIT, c->log, err, "writev() failed");
- return NGX_CHAIN_ERROR;
+ wev->error = 1;
+ ngx_connection_error(c, err, "writev() failed");
+ return NGX_CHAIN_ERROR;
}
}
sent = rc > 0 ? rc : 0;
-#if (NGX_DEBUG_WRITE_CHAIN)
- ngx_log_debug(c->log, "writev: %d" _ sent);
-#endif
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "writev: %d", sent);
}
c->sent += sent;