summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_sendbuf.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2017-02-22 15:09:59 +0300
committerIgor Sysoev <igor@sysoev.ru>2017-02-22 15:09:59 +0300
commit029942f4eb7196c2cff0d0e26bc6ff274138f7d8 (patch)
treef4686c4d7b9cd574fe94c6f4918479a580fecf75 /src/nxt_sendbuf.c
parent059a8642898a6bd4b47d13a1c1d599cd44af7e1c (diff)
downloadunit-029942f4eb7196c2cff0d0e26bc6ff274138f7d8.tar.gz
unit-029942f4eb7196c2cff0d0e26bc6ff274138f7d8.tar.bz2
I/O operations refactoring.
Diffstat (limited to 'src/nxt_sendbuf.c')
-rw-r--r--src/nxt_sendbuf.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/nxt_sendbuf.c b/src/nxt_sendbuf.c
index 309d3147..21a25e68 100644
--- a/src/nxt_sendbuf.c
+++ b/src/nxt_sendbuf.c
@@ -12,6 +12,77 @@ static nxt_bool_t nxt_sendbuf_copy(nxt_buf_mem_t *bm, nxt_buf_t *b,
nxt_uint_t
+nxt_sendbuf_mem_coalesce0(nxt_task_t *task, nxt_sendbuf_t *sb,
+ struct iovec *iov, nxt_uint_t niov_max)
+{
+ u_char *last;
+ size_t size, total;
+ nxt_buf_t *b;
+ nxt_uint_t n;
+
+ total = sb->size;
+ last = NULL;
+ n = (nxt_uint_t) -1;
+
+ for (b = sb->buf; b != NULL && total < sb->limit; b = b->next) {
+
+ nxt_prefetch(b->next);
+
+ if (nxt_buf_is_file(b)) {
+ break;
+ }
+
+ if (nxt_buf_is_mem(b)) {
+
+ size = b->mem.free - b->mem.pos;
+
+ if (size != 0) {
+
+ if (total + size > sb->limit) {
+ size = sb->limit - total;
+
+ if (size == 0) {
+ break;
+ }
+ }
+
+ if (b->mem.pos != last) {
+
+ if (++n >= niov_max) {
+ goto done;
+ }
+
+ iov[n].iov_base = b->mem.pos;
+ iov[n].iov_len = size;
+
+ } else {
+ iov[n].iov_len += size;
+ }
+
+ nxt_debug(task, "sendbuf: %ui, %p, %uz",
+ n, iov[n].iov_base, iov[n].iov_len);
+
+ total += size;
+ last = b->mem.pos + size;
+ }
+
+ } else {
+ sb->sync = 1;
+ sb->last |= nxt_buf_is_last(b);
+ }
+ }
+
+ n++;
+
+done:
+
+ sb->buf = b;
+
+ return n;
+}
+
+
+nxt_uint_t
nxt_sendbuf_mem_coalesce(nxt_task_t *task, nxt_sendbuf_coalesce_t *sb)
{
u_char *last;