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-c4023f1b3aa9svn/tags/lighttpd-1.4.6
parent
c440468249
commit
bd893badb9
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue