From 27a113bc207b11419015b87210906930b5b79805 Mon Sep 17 00:00:00 2001 From: Jan Kneschke Date: Fri, 11 Nov 2005 12:46:06 +0000 Subject: [PATCH] cached FDs for the uploading chunk git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@839 152afb58-edef-0310-8abb-c4023f1b3aa9 --- src/connections.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/connections.c b/src/connections.c index 42e781e5..6fc5e988 100644 --- a/src/connections.c +++ b/src/connections.c @@ -981,11 +981,26 @@ int connection_handle_read_state(server *srv, connection *con) { if (dst_cq->last && dst_cq->last->type == FILE_CHUNK && dst_cq->last->file.is_temp && - dst_cq->last->offset == 0 && - dst_cq->last->file.length < 1 * 1024 * 1024) { + dst_cq->last->offset == 0) { /* ok, take the last chunk for our job */ - dst_c = dst_cq->last; - dst_c->file.fd = open(dst_c->file.name->ptr, O_WRONLY | O_APPEND); + + if (dst_cq->last->file.length < 1 * 1024 * 1024) { + dst_c = dst_cq->last; + + if (dst_c->file.fd == -1) { + /* this should not happen as we cache the fd, but you never know */ + dst_c->file.fd = open(dst_c->file.name->ptr, O_WRONLY | O_APPEND); + } + } else { + /* the chunk is too large now, close it */ + dst_c = dst_cq->last; + + if (dst_c->file.fd != -1) { + close(dst_c->file.fd); + dst_c->file.fd = -1; + } + dst_c = chunkqueue_get_append_tempfile(dst_cq); + } } else { dst_c = chunkqueue_get_append_tempfile(dst_cq); } @@ -1028,8 +1043,11 @@ int connection_handle_read_state(server *srv, connection *con) { dst_c->file.length += toRead; - close(dst_c->file.fd); - dst_c->file.fd = -1; + if (dst_cq->bytes_in + toRead == con->request.content_length) { + /* we read everything, close the chunk */ + close(dst_c->file.fd); + dst_c->file.fd = -1; + } } else { buffer *b;