Browse Source

Reduce buffer allocs for network read

personal/stbuehler/wip
Stefan Bühler 13 years ago
parent
commit
8f69c6bc8d
  1. 2
      include/lighttpd/worker.h
  2. 6
      src/main/network.c
  3. 4
      src/main/worker.c

2
include/lighttpd/worker.h

@ -110,6 +110,8 @@ struct liWorker {
ev_async job_async_queue_watcher;
liStatCache *stat_cache;
GByteArray *network_read_buf; /** internal temporary buffer for network.c */
};
LI_API liWorker* li_worker_new(liServer *srv, struct ev_loop *loop);

6
src/main/network.c

@ -78,6 +78,8 @@ liNetworkStatus li_network_read(liVRequest *vr, int fd, liChunkQueue *cq) {
off_t max_read = 16 * blocksize; /* 256k */
ssize_t r;
off_t len = 0;
liWorker *wrk = vr->wrk;
GByteArray *buf = wrk->network_read_buf;
if (cq->limit && cq->limit->limit > 0) {
if (max_read > cq->limit->limit - cq->limit->current) {
@ -90,10 +92,8 @@ liNetworkStatus li_network_read(liVRequest *vr, int fd, liChunkQueue *cq) {
}
do {
GByteArray *buf = g_byte_array_sized_new(blocksize);
g_byte_array_set_size(buf, blocksize);
if (-1 == (r = li_net_read(fd, buf->data, blocksize))) {
g_byte_array_free(buf, TRUE);
switch (errno) {
case EAGAIN:
#if EWOULDBLOCK != EAGAIN
@ -107,11 +107,11 @@ liNetworkStatus li_network_read(liVRequest *vr, int fd, liChunkQueue *cq) {
return LI_NETWORK_STATUS_FATAL_ERROR;
}
} else if (0 == r) {
g_byte_array_free(buf, TRUE);
return len ? LI_NETWORK_STATUS_SUCCESS : LI_NETWORK_STATUS_CONNECTION_CLOSE;
}
g_byte_array_set_size(buf, r);
li_chunkqueue_append_bytearr(cq, buf);
wrk->network_read_buf = buf = g_byte_array_sized_new(blocksize);
len += r;
} while (r == blocksize && len < max_read);

4
src/main/worker.c

@ -455,6 +455,8 @@ liWorker* li_worker_new(liServer *srv, struct ev_loop *loop) {
li_stat_cache_new(wrk, srv->stat_cache_ttl);
wrk->network_read_buf = g_byte_array_sized_new(0);
return wrk;
}
@ -531,6 +533,8 @@ void li_worker_free(liWorker *wrk) {
wrk->L = NULL;
#endif
g_byte_array_free(wrk->network_read_buf, TRUE);
g_slice_free(liWorker, wrk);
}

Loading…
Cancel
Save