]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
mbuffers: introduce _mbuffer_head_push_first
authorDaiki Ueno <dueno@redhat.com>
Fri, 27 Jul 2018 04:23:12 +0000 (06:23 +0200)
committerDaiki Ueno <dueno@redhat.com>
Mon, 6 Aug 2018 10:36:39 +0000 (12:36 +0200)
This is similar to _mbuffer_enqueue, but adds an element to the
beginning of the buffer.

This is to make the incomplete header handling case easier.

Signed-off-by: Daiki Ueno <dueno@redhat.com>
lib/mbuffers.c
lib/mbuffers.h

index 2bcd57e4262ed405a3d18a2203e52d171f8d6bee..2e4c62a295635dcf8ef4439d983ee3a11a3bcfa7 100644 (file)
@@ -126,6 +126,25 @@ mbuffer_st *_mbuffer_dequeue(mbuffer_head_st * buf, mbuffer_st * bufel)
        return ret;
 }
 
+/* Append a segment to the beginning of this buffer.
+ *
+ * Cost: O(1)
+ */
+void _mbuffer_head_push_first(mbuffer_head_st * buf, mbuffer_st * bufel)
+{
+       bufel->prev = NULL;
+       bufel->next = buf->head;
+
+       buf->length++;
+       buf->byte_length += bufel->msg.size - bufel->mark;
+
+       if (buf->head != NULL)
+               buf->head->prev = bufel;
+       else
+               buf->tail = bufel;
+       buf->head = bufel;
+}
+
 /* Get a reference to the first segment of the buffer and
  * remove it from the list.
  *
index 034f8a3cb9cb202b9240464b1cb88836a57fb4fe..bbbe079dafe9836076ecbf42e7023ff5f4568031 100644 (file)
@@ -39,6 +39,8 @@ mbuffer_st *_mbuffer_head_get_first(mbuffer_head_st * buf,
                                    gnutls_datum_t * msg);
 mbuffer_st *_mbuffer_head_get_next(mbuffer_st * cur, gnutls_datum_t * msg);
 
+void _mbuffer_head_push_first(mbuffer_head_st * buf, mbuffer_st * bufel);
+
 mbuffer_st *_mbuffer_head_pop_first(mbuffer_head_st * buf);
 
 /* This is dangerous since it will replace bufel with a new