Drop rconn's responsibility for limiting the tx queue.
[openvswitch] / lib / buffer.c
index 8604913f14018342e85477cd0a90c6aed9d76397..47600e6ae3346d6befc3b98305be48df7067fc25 100644 (file)
@@ -31,6 +31,7 @@
  * derivatives without specific, written prior permission.
  */
 
+#include <config.h>
 #include "buffer.h"
 #include <assert.h>
 #include <stdlib.h>
@@ -50,8 +51,9 @@ buffer_use(struct buffer *b, void *base, size_t allocated)
     b->base = b->data = base;
     b->allocated = allocated;
     b->size = 0;
-    b->l2 = b->l3 = b->l4 = NULL;
+    b->l2 = b->l3 = b->l4 = b->l7 = NULL;
     b->next = NULL;
+    b->private = NULL;
 }
 
 /* Initializes 'b' as a buffer with an initial capacity of 'size' bytes. */
@@ -148,6 +150,9 @@ buffer_prealloc_tailroom(struct buffer *b, size_t size)
         if (b->l4) {
             b->l4 += base_delta;
         }
+        if (b->l7) {
+            b->l7 += base_delta;
+        }
     }
 }
 
@@ -181,6 +186,16 @@ buffer_put(struct buffer *b, const void *p, size_t size)
     return dst;
 }
 
+/* Reserves 'size' bytes of headroom so that they can be later allocated with
+ * buffer_push_uninit() without reallocating the buffer. */
+void
+buffer_reserve(struct buffer *b, size_t size) 
+{
+    assert(!b->size);
+    buffer_prealloc_tailroom(b, size);
+    b->data += size;
+}
+
 void *
 buffer_push_uninit(struct buffer *b, size_t size) 
 {
@@ -190,8 +205,16 @@ buffer_push_uninit(struct buffer *b, size_t size)
     return b->data;
 }
 
+void *
+buffer_push(struct buffer *b, const void *p, size_t size) 
+{
+    void *dst = buffer_push_uninit(b, size);
+    memcpy(dst, p, size);
+    return dst;
+}
+
 /* If 'b' contains at least 'offset + size' bytes of data, returns a pointer to
- * byte 'offset'.  Otherwise, returns a null pointers. */
+ * byte 'offset'.  Otherwise, returns a null pointer. */
 void *
 buffer_at(const struct buffer *b, size_t offset, size_t size) 
 {
@@ -242,3 +265,11 @@ buffer_pull(struct buffer *b, size_t size)
     return data;
 }
 
+/* If 'b' has at least 'size' bytes of data, removes that many bytes from the
+ * head end of 'b' and returns the first byte removed.  Otherwise, returns a
+ * null pointer without modifying 'b'. */
+void *
+buffer_try_pull(struct buffer *b, size_t size) 
+{
+    return b->size >= size ? buffer_pull(b, size) : NULL;
+}