Author: tross
Date: Mon May 20 20:02:56 2013
New Revision: 1484576

URL: http://svn.apache.org/r1484576
Log:
NO-JIRA - Generalized the generation of iovectors from field iterators.

Modified:
    qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch/iterator.h
    qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch/message.h
    qpid/trunk/qpid/extras/dispatch/src/iterator.c

Modified: qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch/iterator.h
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch/iterator.h?rev=1484576&r1=1484575&r2=1484576&view=diff
==============================================================================
--- qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch/iterator.h (original)
+++ qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch/iterator.h Mon May 20 
20:02:56 2013
@@ -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_it
 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;
 

Modified: qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch/message.h
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch/message.h?rev=1484576&r1=1484575&r2=1484576&view=diff
==============================================================================
--- qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch/message.h (original)
+++ qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch/message.h Mon May 20 
20:02:56 2013
@@ -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, 
 
 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);

Modified: qpid/trunk/qpid/extras/dispatch/src/iterator.c
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/extras/dispatch/src/iterator.c?rev=1484576&r1=1484575&r2=1484576&view=diff
==============================================================================
--- qpid/trunk/qpid/extras/dispatch/src/iterator.c (original)
+++ qpid/trunk/qpid/extras/dispatch/src/iterator.c Mon May 20 20:02:56 2013
@@ -663,3 +663,59 @@ dx_field_iterator_t *dx_field_raw(dx_fie
     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;
+}
+
+



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to