summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kneschke <jan@kneschke.de>2006-02-15 10:46:17 +0000
committerJan Kneschke <jan@kneschke.de>2006-02-15 10:46:17 +0000
commit3331b5a6169ddb95dead588a979067db56e072e4 (patch)
tree2e41fc9a151a1ce795d1eeb3e2c6c179c05ac903
parentde0bace2eff635ddc6b087a601d2eccb27a3a50e (diff)
downloadlighttpd-git-3331b5a6169ddb95dead588a979067db56e072e4.tar.gz
- move the extra-stat() out of the main-path
it was only used to detect file-shrinks, but also resulted in interupted transfers if the file was removed, but still open. - we detect file-shrinks now if sendfile() returns 0 git-svn-id: svn+ssh://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@998 152afb58-edef-0310-8abb-c4023f1b3aa9
-rw-r--r--src/network_linux_sendfile.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/network_linux_sendfile.c b/src/network_linux_sendfile.c
index 6265f40e..101d3295 100644
--- a/src/network_linux_sendfile.c
+++ b/src/network_linux_sendfile.c
@@ -132,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))) {
@@ -170,8 +158,6 @@ int network_write_chunkqueue_linuxsendfile(server *srv, connection *con, int fd,
#endif
}
-
- /* Linux sendfile() */
if (-1 == (r = sendfile(fd, c->file.fd, &offset, toSend))) {
switch (errno) {
case EAGAIN:
@@ -189,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 (abs_offset > sce->st.st_size) {
+ /* file shrinked, close the connection */
+ return -1;
+ }
+
return -2;
}