diff options
| author | Ted Ross <tross@apache.org> | 2013-05-20 20:02:56 +0000 |
|---|---|---|
| committer | Ted Ross <tross@apache.org> | 2013-05-20 20:02:56 +0000 |
| commit | 2b6a20de7d1f090063f9ca9ffc9741aaa5f71f1e (patch) | |
| tree | d3ee1dc7a0f81d0d10a262653f56e34a86594b18 | |
| parent | 58d7bffec0109a86f44620b1ebff44f38af7af8f (diff) | |
| download | qpid-python-2b6a20de7d1f090063f9ca9ffc9741aaa5f71f1e.tar.gz | |
NO-JIRA - Generalized the generation of iovectors from field iterators.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1484576 13f79535-47bb-0310-9956-ffa450edef68
| -rw-r--r-- | extras/dispatch/include/qpid/dispatch/iterator.h | 2 | ||||
| -rw-r--r-- | extras/dispatch/include/qpid/dispatch/message.h | 2 | ||||
| -rw-r--r-- | extras/dispatch/src/iterator.c | 56 |
3 files changed, 58 insertions, 2 deletions
diff --git a/extras/dispatch/include/qpid/dispatch/iterator.h b/extras/dispatch/include/qpid/dispatch/iterator.h index be10990f40..2412995432 100644 --- a/extras/dispatch/include/qpid/dispatch/iterator.h +++ b/extras/dispatch/include/qpid/dispatch/iterator.h @@ -20,6 +20,7 @@ */ #include <qpid/dispatch/buffer.h> +#include <qpid/dispatch/iovec.h> /** * The field iterator is used to access fields within a buffer chain. @@ -149,6 +150,7 @@ int dx_field_iterator_prefix(dx_field_iterator_t *iter, const char *prefix); unsigned char *dx_field_iterator_copy(dx_field_iterator_t *iter); +dx_iovec_t *dx_field_iterator_iovec(const dx_field_iterator_t *iter); typedef struct dx_field_map_t dx_field_map_t; diff --git a/extras/dispatch/include/qpid/dispatch/message.h b/extras/dispatch/include/qpid/dispatch/message.h index 8311f846d6..c725deb923 100644 --- a/extras/dispatch/include/qpid/dispatch/message.h +++ b/extras/dispatch/include/qpid/dispatch/message.h @@ -24,7 +24,6 @@ #include <qpid/dispatch/alloc.h> #include <qpid/dispatch/iterator.h> #include <qpid/dispatch/buffer.h> -#include <qpid/dispatch/iovec.h> // Callback for status change (confirmed persistent, loaded-in-memory, etc.) @@ -110,7 +109,6 @@ void dx_message_send(dx_message_t *msg, pn_link_t *link); int dx_message_check(dx_message_t *msg, dx_message_depth_t depth); dx_field_iterator_t *dx_message_field_iterator(dx_message_t *msg, dx_message_field_t field); -dx_iovec_t *dx_message_field_iovec(dx_message_t *msg, dx_message_field_t field); ssize_t dx_message_field_length(dx_message_t *msg, dx_message_field_t field); ssize_t dx_message_field_copy(dx_message_t *msg, dx_message_field_t field, void *buffer); diff --git a/extras/dispatch/src/iterator.c b/extras/dispatch/src/iterator.c index 68d0701f6c..676413382e 100644 --- a/extras/dispatch/src/iterator.c +++ b/extras/dispatch/src/iterator.c @@ -663,3 +663,59 @@ dx_field_iterator_t *dx_field_raw(dx_field_iterator_t *iter) return result; } + +dx_iovec_t *dx_field_iterator_iovec(const dx_field_iterator_t *iter) +{ + assert(!iter->view_prefix); // Not supported for views with a prefix + + // + // Count the number of buffers this field straddles + // + pointer_t pointer = iter->view_start_pointer; + int bufcnt = 1; + dx_buffer_t *buf = pointer.buffer; + size_t bufsize = dx_buffer_size(buf) - (pointer.cursor - dx_buffer_base(pointer.buffer)); + ssize_t remaining = pointer.length - bufsize; + + while (remaining > 0) { + bufcnt++; + buf = buf->next; + if (!buf) + return 0; + remaining -= dx_buffer_size(buf); + } + + // + // Allocate an iovec object big enough to hold the number of buffers + // + dx_iovec_t *iov = dx_iovec(bufcnt); + if (!iov) + return 0; + + // + // Build out the io vectors with pointers to the segments of the field in buffers + // + bufcnt = 0; + buf = pointer.buffer; + bufsize = dx_buffer_size(buf) - (pointer.cursor - dx_buffer_base(pointer.buffer)); + void *base = pointer.cursor; + remaining = pointer.length; + + while (remaining > 0) { + if (bufsize > remaining) + bufsize = remaining; + dx_iovec_array(iov)[bufcnt].iov_base = base; + dx_iovec_array(iov)[bufcnt].iov_len = bufsize; + bufcnt++; + remaining -= bufsize; + if (remaining > 0) { + buf = buf->next; + base = dx_buffer_base(buf); + bufsize = dx_buffer_size(buf); + } + } + + return iov; +} + + |
