]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Introduce btr_pool_get_buffers().
authorAndre Noll <maan@systemlinux.org>
Sat, 13 Feb 2010 11:57:35 +0000 (12:57 +0100)
committerAndre Noll <maan@systemlinux.org>
Sat, 13 Feb 2010 11:57:35 +0000 (12:57 +0100)
This allows the users of the buffer pool API to obtain references to both parts
of the buffer pool area in case there is free space available at the end of the
area as well as at the beginning.

This is needed for reading from file descriptors where reading less than a full
datagram would discard the remaining part (DCCP and UDP).

buffer_tree.c
buffer_tree.h

index 4aeb790a6e3c6e8efe9a841e4b12fbe331f360f9..2a78959c5ad569bc6c950be20f6b0def1d801772 100644 (file)
@@ -159,6 +159,35 @@ size_t btr_pool_get_buffer(struct btr_pool *btrp, char **result)
        return btr_pool_available(btrp);
 }
 
+/**
+ * Get references to buffers pointing to free space of the buffer pool area.
+ *
+ * \param btrp The buffer pool.
+ * \param iov The scatter array.
+ *
+ * \return Zero if the buffer pool is full, one if the free space of the buffer
+ * pool area is available as a single contiguous buffer, two if the free space
+ * consists of two buffers. If this function returns the value n, then n
+ * elements of \a iov are initialized.
+ */
+int btr_pool_get_buffers(struct btr_pool *btrp, struct iovec iov[2])
+{
+       size_t sz, unused;
+       char *buf;
+
+       sz = btr_pool_get_buffer(btrp, &buf);
+       if (sz == 0)
+               return 0;
+       iov[0].iov_len = sz;
+       iov[0].iov_base = buf;
+       unused = btr_pool_unused(btrp);
+       if (sz == unused)
+               return 1;
+       iov[1].iov_len = unused - sz;
+       iov[1].iov_base = btrp->area_start;
+       return 2;
+}
+
 /**
  * Mark a part of the buffer pool area as allocated.
  *
index e2af2fc8489944fd1e4b847b13d491d8201e4bff..f8fed361f368a44084f2880b2ce4a1b0214f5a3a 100644 (file)
@@ -168,6 +168,7 @@ size_t btr_pool_size(struct btr_pool *btrp);
 struct btr_pool *btr_pool_new(const char *name, size_t area_size);
 void btr_pool_free(struct btr_pool *btrp);
 size_t btr_pool_get_buffer(struct btr_pool *btrp, char **result);
+int btr_pool_get_buffers(struct btr_pool *btrp, struct iovec iov[2]);
 void btr_add_output_pool(struct btr_pool *btrp, size_t size,
        struct btr_node *btrn);
 size_t btr_pool_unused(struct btr_pool *btrp);