summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kneschke <jan@kneschke.de>2005-09-26 08:52:37 +0000
committerJan Kneschke <jan@kneschke.de>2005-09-26 08:52:37 +0000
commitbd893badb91ee55777df80ea867060105afd43c9 (patch)
tree04f67ae84bf3e0d2d1f709fa0720fa90fcb8cbf3
parentc440468249bdc7bd0edf487c67f4bb4b62794c40 (diff)
downloadlighttpd-git-bd893badb91ee55777df80ea867060105afd43c9.tar.gz
added the fd as parameter for the write() functions
- the plugins can use them now too git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@737 152afb58-edef-0310-8abb-c4023f1b3aa9
-rw-r--r--src/network.c12
-rw-r--r--src/network_backends.h14
-rw-r--r--src/network_freebsd_sendfile.c5
-rw-r--r--src/network_linux_sendfile.c12
-rw-r--r--src/network_openssl.c12
-rw-r--r--src/network_solaris_sendfilev.c8
-rw-r--r--src/network_write.c7
-rw-r--r--src/network_writev.c13
8 files changed, 42 insertions, 41 deletions
diff --git a/src/network.c b/src/network.c
index 90023358..d98f6917 100644
--- a/src/network.c
+++ b/src/network.c
@@ -456,20 +456,20 @@ int network_write_chunkqueue(server *srv, connection *con, chunkqueue *cq) {
if (srv_socket->is_ssl) {
#ifdef USE_OPENSSL
- ret = network_write_chunkqueue_openssl(srv, con, cq);
+ ret = network_write_chunkqueue_openssl(srv, con, con->ssl, cq);
#endif
} else {
/* dispatch call */
#if defined USE_LINUX_SENDFILE
- ret = network_write_chunkqueue_linuxsendfile(srv, con, cq);
+ ret = network_write_chunkqueue_linuxsendfile(srv, con, con->fd, cq);
#elif defined USE_FREEBSD_SENDFILE
- ret = network_write_chunkqueue_freebsdsendfile(srv, con, cq);
+ ret = network_write_chunkqueue_freebsdsendfile(srv, con, con->fd, cq);
#elif defined USE_SOLARIS_SENDFILEV
- ret = network_write_chunkqueue_solarissendfilev(srv, con, cq);
+ ret = network_write_chunkqueue_solarissendfilev(srv, con, con->fd, cq);
#elif defined USE_WRITEV
- ret = network_write_chunkqueue_writev(srv, con, cq);
+ ret = network_write_chunkqueue_writev(srv, con, con->fd, cq);
#else
- ret = network_write_chunkqueue_write(srv, con, cq);
+ ret = network_write_chunkqueue_write(srv, con, con->fd, cq);
#endif
}
diff --git a/src/network_backends.h b/src/network_backends.h
index c97238a1..94650a7d 100644
--- a/src/network_backends.h
+++ b/src/network_backends.h
@@ -46,11 +46,13 @@
#include "base.h"
-int network_write_chunkqueue_write(server *srv, connection *con, chunkqueue *cq);
-int network_write_chunkqueue_writev(server *srv, connection *con, chunkqueue *cq);
-int network_write_chunkqueue_linuxsendfile(server *srv, connection *con, chunkqueue *cq);
-int network_write_chunkqueue_freebsdsendfile(server *srv, connection *con, chunkqueue *cq);
-int network_write_chunkqueue_solarissendfilev(server *srv, connection *con, chunkqueue *cq);
-int network_write_chunkqueue_openssl(server *srv, connection *con, chunkqueue *cq);
+int network_write_chunkqueue_write(server *srv, connection *con, int fd, chunkqueue *cq);
+int network_write_chunkqueue_writev(server *srv, connection *con, int fd, chunkqueue *cq);
+int network_write_chunkqueue_linuxsendfile(server *srv, connection *con, int fd, chunkqueue *cq);
+int network_write_chunkqueue_freebsdsendfile(server *srv, connection *con, int fd, chunkqueue *cq);
+int network_write_chunkqueue_solarissendfilev(server *srv, connection *con, int fd, chunkqueue *cq);
+#ifdef USE_OPENSSL
+int network_write_chunkqueue_openssl(server *srv, connection *con, SSL *ssl, chunkqueue *cq);
+#endif
#endif
diff --git a/src/network_freebsd_sendfile.c b/src/network_freebsd_sendfile.c
index ce4a3cc6..53c6746a 100644
--- a/src/network_freebsd_sendfile.c
+++ b/src/network_freebsd_sendfile.c
@@ -31,8 +31,7 @@
# endif
#endif
-int network_write_chunkqueue_freebsdsendfile(server *srv, connection *con, chunkqueue *cq) {
- const int fd = con->fd;
+int network_write_chunkqueue_freebsdsendfile(server *srv, connection *con, int fd, chunkqueue *cq) {
chunk *c;
size_t chunks_written = 0;
@@ -105,7 +104,6 @@ int network_write_chunkqueue_freebsdsendfile(server *srv, connection *con, chunk
/* check which chunks have been written */
cq->bytes_out += r;
- con->bytes_written += r;
for(i = 0, tc = c; i < num_chunks; i++, tc = tc->next) {
if (r >= (ssize_t)chunks[i].iov_len) {
@@ -181,7 +179,6 @@ int network_write_chunkqueue_freebsdsendfile(server *srv, connection *con, chunk
close(ifd);
c->offset += r;
- con->bytes_written += r;
cq->bytes_out += r;
if (c->offset == c->file.length) {
diff --git a/src/network_linux_sendfile.c b/src/network_linux_sendfile.c
index ef1ddffd..9939247f 100644
--- a/src/network_linux_sendfile.c
+++ b/src/network_linux_sendfile.c
@@ -22,8 +22,7 @@
#include "log.h"
#include "stat_cache.h"
-int network_write_chunkqueue_linuxsendfile(server *srv, connection *con, chunkqueue *cq) {
- const int fd = con->fd;
+int network_write_chunkqueue_linuxsendfile(server *srv, connection *con, int fd, chunkqueue *cq) {
chunk *c;
size_t chunks_written = 0;
@@ -96,7 +95,6 @@ int network_write_chunkqueue_linuxsendfile(server *srv, connection *con, chunkqu
/* check which chunks have been written */
cq->bytes_out += r;
- con->bytes_written += r;
for(i = 0, tc = c; i < num_chunks; i++, tc = tc->next) {
if (r >= (ssize_t)chunks[i].iov_len) {
@@ -173,11 +171,17 @@ int network_write_chunkqueue_linuxsendfile(server *srv, connection *con, chunkqu
}
c->offset += r;
- con->bytes_written += r;
cq->bytes_out += r;
if (c->offset == c->file.length) {
chunk_finished = 1;
+
+ /* chunk_free() / chunk_reset() will cleanup for us but it is a ok to be faster :) */
+
+ if (c->file.fd != -1) {
+ close(c->file.fd);
+ c->file.fd = -1;
+ }
}
break;
diff --git a/src/network_openssl.c b/src/network_openssl.c
index 9949d64f..9385209c 100644
--- a/src/network_openssl.c
+++ b/src/network_openssl.c
@@ -26,7 +26,7 @@
# include <openssl/ssl.h>
# include <openssl/err.h>
-int network_write_chunkqueue_openssl(server *srv, connection *con, chunkqueue *cq) {
+int network_write_chunkqueue_openssl(server *srv, connection *con, SSL *ssl, chunkqueue *cq) {
int ssl_r;
chunk *c;
size_t chunks_written = 0;
@@ -76,10 +76,10 @@ int network_write_chunkqueue_openssl(server *srv, connection *con, chunkqueue *c
*
*/
- if ((r = SSL_write(con->ssl, offset, toSend)) <= 0) {
+ if ((r = SSL_write(ssl, offset, toSend)) <= 0) {
unsigned long err;
- switch ((ssl_r = SSL_get_error(con->ssl, r))) {
+ switch ((ssl_r = SSL_get_error(ssl, r))) {
case SSL_ERROR_WANT_WRITE:
break;
case SSL_ERROR_SYSCALL:
@@ -122,7 +122,6 @@ int network_write_chunkqueue_openssl(server *srv, connection *con, chunkqueue *c
}
} else {
c->offset += r;
- con->bytes_written += r;
cq->bytes_out += r;
}
@@ -176,8 +175,8 @@ int network_write_chunkqueue_openssl(server *srv, connection *con, chunkqueue *c
close(ifd);
- if ((r = SSL_write(con->ssl, s, toSend)) <= 0) {
- switch ((ssl_r = SSL_get_error(con->ssl, r))) {
+ if ((r = SSL_write(ssl, s, toSend)) <= 0) {
+ switch ((ssl_r = SSL_get_error(ssl, r))) {
case SSL_ERROR_WANT_WRITE:
write_wait = 1;
break;
@@ -208,7 +207,6 @@ int network_write_chunkqueue_openssl(server *srv, connection *con, chunkqueue *c
}
} else {
c->offset += r;
- con->bytes_written += r;
cq->bytes_out += r;
}
diff --git a/src/network_solaris_sendfilev.c b/src/network_solaris_sendfilev.c
index b70429d7..9c4ca625 100644
--- a/src/network_solaris_sendfilev.c
+++ b/src/network_solaris_sendfilev.c
@@ -38,8 +38,7 @@
*/
-int network_write_chunkqueue_solarissendfilev(server *srv, connection *con, chunkqueue *cq) {
- const int fd = con->fd;
+int network_write_chunkqueue_solarissendfilev(server *srv, connection *con, int fd, chunkqueue *cq) {
chunk *c;
size_t chunks_written = 0;
@@ -110,13 +109,13 @@ int network_write_chunkqueue_solarissendfilev(server *srv, connection *con, chun
}
/* check which chunks have been written */
+ cq->bytes_out += r;
for(i = 0, tc = c; i < num_chunks; i++, tc = tc->next) {
if (r >= (ssize_t)chunks[i].iov_len) {
/* written */
r -= chunks[i].iov_len;
tc->offset += chunks[i].iov_len;
- con->bytes_written += chunks[i].iov_len;
if (chunk_finished) {
/* skip the chunks from further touches */
@@ -130,7 +129,6 @@ int network_write_chunkqueue_solarissendfilev(server *srv, connection *con, chun
/* partially written */
tc->offset += r;
- con->bytes_written += r;
chunk_finished = 0;
break;
@@ -187,7 +185,7 @@ int network_write_chunkqueue_solarissendfilev(server *srv, connection *con, chun
close(ifd);
c->offset += written;
- con->bytes_written += written;
+ cq->bytes_out += written;
if (c->offset == c->file.length) {
chunk_finished = 1;
diff --git a/src/network_write.c b/src/network_write.c
index 7c0139ae..9e713c63 100644
--- a/src/network_write.c
+++ b/src/network_write.c
@@ -24,8 +24,7 @@
#include <sys/resource.h>
#endif
-int network_write_chunkqueue_write(server *srv, connection *con, chunkqueue *cq) {
- const int fd = con->fd;
+int network_write_chunkqueue_write(server *srv, connection *con, int fd, chunkqueue *cq) {
chunk *c;
size_t chunks_written = 0;
@@ -60,7 +59,6 @@ int network_write_chunkqueue_write(server *srv, connection *con, chunkqueue *cq)
#endif
c->offset += r;
- con->bytes_written += r;
cq->bytes_out += r;
if (c->offset == (off_t)c->mem->used - 1) {
@@ -109,7 +107,7 @@ int network_write_chunkqueue_write(server *srv, connection *con, chunkqueue *cq)
return -1;
}
close(ifd);
-
+
if ((r = write(fd, p + offset, toSend)) <= 0) {
log_error_write(srv, __FILE__, __LINE__, "ss", "write failed: ", strerror(errno));
@@ -136,7 +134,6 @@ int network_write_chunkqueue_write(server *srv, connection *con, chunkqueue *cq)
}
#endif
c->offset += r;
- con->bytes_written += r;
cq->bytes_out += r;
if (c->offset == c->file.length) {
diff --git a/src/network_writev.c b/src/network_writev.c
index 70850417..b7e4dc28 100644
--- a/src/network_writev.c
+++ b/src/network_writev.c
@@ -46,8 +46,7 @@
# endif
#endif
-int network_write_chunkqueue_writev(server *srv, connection *con, chunkqueue *cq) {
- const int fd = con->fd;
+int network_write_chunkqueue_writev(server *srv, connection *con, int fd, chunkqueue *cq) {
chunk *c;
size_t chunks_written = 0;
@@ -117,7 +116,6 @@ int network_write_chunkqueue_writev(server *srv, connection *con, chunkqueue *cq
}
cq->bytes_out += r;
- con->bytes_written += r;
/* check which chunks have been written */
@@ -187,6 +185,8 @@ int network_write_chunkqueue_writev(server *srv, connection *con, chunkqueue *cq
close(c->file.fd);
c->file.fd = -1;
+ c->file.mmap.length = sce->st.st_size;
+
/* chunk_reset() or chunk_free() will cleanup for us */
}
@@ -208,11 +208,16 @@ int network_write_chunkqueue_writev(server *srv, connection *con, chunkqueue *cq
}
c->offset += r;
- con->bytes_written += r;
cq->bytes_out += r;
if (c->offset == c->file.length) {
chunk_finished = 1;
+
+ /* we don't need the mmaping anymore */
+ if (c->file.mmap.start != MAP_FAILED) {
+ munmap(c->file.mmap.start, c->file.mmap.length);
+ c->file.mmap.start = MAP_FAILED;
+ }
}
break;