diff options
author | Arno Töll <arno@debian.org> | 2012-11-21 23:03:42 +0100 |
---|---|---|
committer | Arno Töll <arno@debian.org> | 2012-11-21 23:03:42 +0100 |
commit | 1b24d86e6b2179692e60091dec59f797cd308b9e (patch) | |
tree | c5502d40d82fdef69ab9c1e4ed69904fefea9ac1 /src/network_solaris_sendfilev.c | |
parent | 6a6df8dc258631c6eaccb03bf08845241f6dfa4a (diff) | |
download | lighttpd-1b24d86e6b2179692e60091dec59f797cd308b9e.tar.gz |
Imported Upstream version 1.4.13upstream/1.4.13
Diffstat (limited to 'src/network_solaris_sendfilev.c')
-rw-r--r-- | src/network_solaris_sendfilev.c | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/src/network_solaris_sendfilev.c b/src/network_solaris_sendfilev.c index 0ab669f..fcb7d10 100644 --- a/src/network_solaris_sendfilev.c +++ b/src/network_solaris_sendfilev.c @@ -29,11 +29,11 @@ #endif /** - * a very simple sendfilev() interface for solaris which can be optimised a lot more + * a very simple sendfilev() interface for solaris which can be optimised a lot more * as solaris sendfilev() supports 'sending everythin in one syscall()' - * - * If you want such an interface and need the performance, just give me an account on - * a solaris box. + * + * If you want such an interface and need the performance, just give me an account on + * a solaris box. * - jan@kneschke.de */ @@ -41,31 +41,31 @@ int network_write_chunkqueue_solarissendfilev(server *srv, connection *con, int fd, chunkqueue *cq) { chunk *c; size_t chunks_written = 0; - + for(c = cq->first; c; c = c->next, chunks_written++) { int chunk_finished = 0; - + switch(c->type) { case MEM_CHUNK: { char * offset; size_t toSend; ssize_t r; - + size_t num_chunks, i; struct iovec chunks[UIO_MAXIOV]; chunk *tc; - + size_t num_bytes = 0; - + /* we can't send more then SSIZE_MAX bytes in one chunk */ - - /* build writev list - * + + /* build writev list + * * 1. limit: num_chunks < UIO_MAXIOV * 2. limit: num_bytes < SSIZE_MAX */ for(num_chunks = 0, tc = c; tc && tc->type == MEM_CHUNK && num_chunks < UIO_MAXIOV; num_chunks++, tc = tc->next); - + for(tc = c, i = 0; i < num_chunks; tc = tc->next, i++) { if (tc->mem->used == 0) { chunks[i].iov_base = tc->mem->ptr; @@ -73,24 +73,24 @@ int network_write_chunkqueue_solarissendfilev(server *srv, connection *con, int } else { offset = tc->mem->ptr + tc->offset; toSend = tc->mem->used - 1 - tc->offset; - + chunks[i].iov_base = offset; - + /* protect the return value of writev() */ if (toSend > SSIZE_MAX || num_bytes + toSend > SSIZE_MAX) { chunks[i].iov_len = SSIZE_MAX - num_bytes; - + num_chunks = i + 1; break; } else { chunks[i].iov_len = toSend; } - + num_bytes += toSend; } } - + if ((r = writev(fd, chunks, num_chunks)) < 0) { switch (errno) { case EAGAIN: @@ -101,22 +101,22 @@ int network_write_chunkqueue_solarissendfilev(server *srv, connection *con, int case ECONNRESET: return -2; default: - log_error_write(srv, __FILE__, __LINE__, "ssd", + log_error_write(srv, __FILE__, __LINE__, "ssd", "writev failed:", strerror(errno), fd); - + return -1; } } - + /* 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; - + if (chunk_finished) { /* skip the chunks from further touches */ chunks_written++; @@ -127,14 +127,14 @@ int network_write_chunkqueue_solarissendfilev(server *srv, connection *con, int } } else { /* partially written */ - + tc->offset += r; chunk_finished = 0; - + break; } } - + break; } case FILE_CHUNK: { @@ -144,25 +144,25 @@ int network_write_chunkqueue_solarissendfilev(server *srv, connection *con, int sendfilevec_t fvec; stat_cache_entry *sce = NULL; int ifd; - + 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; toSend = 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; } if (-1 == (ifd = open(c->file.name->ptr, O_RDONLY))) { log_error_write(srv, __FILE__, __LINE__, "ss", "open failed: ", strerror(errno)); - + return -1; } @@ -170,39 +170,39 @@ int network_write_chunkqueue_solarissendfilev(server *srv, connection *con, int fvec.sfv_flag = 0; fvec.sfv_off = offset; fvec.sfv_len = toSend; - + /* Solaris sendfilev() */ if (-1 == (r = sendfilev(fd, &fvec, 1, &written))) { if (errno != EAGAIN) { log_error_write(srv, __FILE__, __LINE__, "ssd", "sendfile: ", strerror(errno), errno); - + close(ifd); return -1; } - + r = 0; } - + close(ifd); c->offset += written; cq->bytes_out += written; - + if (c->offset == c->file.length) { chunk_finished = 1; } - + break; } default: - + log_error_write(srv, __FILE__, __LINE__, "ds", c, "type not known"); - + return -1; } - + if (!chunk_finished) { /* not finished yet */ - + break; } } |