summaryrefslogtreecommitdiff
path: root/src/network_linux_sendfile.c
diff options
context:
space:
mode:
authorArno Töll <arno@debian.org>2012-11-21 23:03:36 +0100
committerArno Töll <arno@debian.org>2012-11-21 23:03:36 +0100
commit0e7d1e864fb7bc92f3bbab4a9a0f154ad00fd76e (patch)
treee0098274febb4c76579f70e9f6a7bd35ba189a7d /src/network_linux_sendfile.c
parenteb45c46b906e492f063f1469486190e93ff340ff (diff)
downloadlighttpd-0e7d1e864fb7bc92f3bbab4a9a0f154ad00fd76e.tar.gz
Imported Upstream version 1.4.11upstream/1.4.11
Diffstat (limited to 'src/network_linux_sendfile.c')
-rw-r--r--src/network_linux_sendfile.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/network_linux_sendfile.c b/src/network_linux_sendfile.c
index 6426568..580ba87 100644
--- a/src/network_linux_sendfile.c
+++ b/src/network_linux_sendfile.c
@@ -23,6 +23,9 @@
#include "log.h"
#include "stat_cache.h"
+/* on linux 2.4.29 + debian/ubuntu we have crashes if this is enabled */
+#undef HAVE_POSIX_FADVISE
+
int network_write_chunkqueue_linuxsendfile(server *srv, connection *con, int fd, chunkqueue *cq) {
chunk *c;
size_t chunks_written = 0;
@@ -129,23 +132,11 @@ int network_write_chunkqueue_linuxsendfile(server *srv, connection *con, int fd,
size_t toSend;
stat_cache_entry *sce = NULL;
- if (HANDLER_ERROR == stat_cache_get_entry(srv, con, c->file.name, &sce)) {
- log_error_write(srv, __FILE__, __LINE__, "sb",
- strerror(errno), c->file.name);
- return -1;
- }
-
offset = c->file.start + c->offset;
/* limit the toSend to 2^31-1 bytes in a chunk */
toSend = c->file.length - c->offset > ((1 << 30) - 1) ?
((1 << 30) - 1) : c->file.length - c->offset;
- if (offset > sce->st.st_size) {
- log_error_write(srv, __FILE__, __LINE__, "sb", "file was shrinked:", c->file.name);
-
- return -1;
- }
-
/* open file if not already opened */
if (-1 == c->file.fd) {
if (-1 == (c->file.fd = open(c->file.name->ptr, O_RDONLY))) {
@@ -159,14 +150,14 @@ int network_write_chunkqueue_linuxsendfile(server *srv, connection *con, int fd,
#ifdef HAVE_POSIX_FADVISE
/* tell the kernel that we want to stream the file */
if (-1 == posix_fadvise(c->file.fd, 0, 0, POSIX_FADV_SEQUENTIAL)) {
- log_error_write(srv, __FILE__, __LINE__, "ssd",
- "posix_fadvise failed:", strerror(errno), c->file.fd);
+ if (ENOSYS != errno) {
+ log_error_write(srv, __FILE__, __LINE__, "ssd",
+ "posix_fadvise failed:", strerror(errno), c->file.fd);
+ }
}
#endif
}
-
- /* Linux sendfile() */
if (-1 == (r = sendfile(fd, c->file.fd, &offset, toSend))) {
switch (errno) {
case EAGAIN:
@@ -184,7 +175,21 @@ int network_write_chunkqueue_linuxsendfile(server *srv, connection *con, int fd,
}
if (r == 0) {
- /* we got a event to write put we couldn't. remote side closed ? */
+ /* We got an event to write but we wrote nothing
+ *
+ * - the file shrinked -> error
+ * - the remote side closed inbetween -> remote-close */
+
+ if (HANDLER_ERROR == stat_cache_get_entry(srv, con, c->file.name, &sce)) {
+ /* file is gone ? */
+ return -1;
+ }
+
+ if (offset > sce->st.st_size) {
+ /* file shrinked, close the connection */
+ return -1;
+ }
+
return -2;
}