summaryrefslogtreecommitdiff
path: root/lib/stream.c
diff options
context:
space:
mode:
authorRafael Zalamena <rzalamena@opensourcerouting.org>2020-05-11 11:41:23 -0300
committerRafael Zalamena <rzalamena@opensourcerouting.org>2020-11-24 07:54:07 -0300
commit91804f630cfe6ce783743c8bc9216132613e7975 (patch)
tree91f34124fcc722064cb9da4a9a477c03d0f13e4c /lib/stream.c
parent9bcab3130beb309d8a9e109162cd3010cd98ffa3 (diff)
lib: add new stream function to reorganize buffer
The function was originally implemented for zebra data plane FPM plugin, but another code places could use it. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
Diffstat (limited to 'lib/stream.c')
-rw-r--r--lib/stream.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/stream.c b/lib/stream.c
index dc207c16a4..e4e37b7315 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -1372,3 +1372,19 @@ void stream_fifo_free(struct stream_fifo *fifo)
stream_fifo_deinit(fifo);
XFREE(MTYPE_STREAM_FIFO, fifo);
}
+
+void stream_pulldown(struct stream *s)
+{
+ size_t rlen = STREAM_READABLE(s);
+
+ /* No more data, so just move the pointers. */
+ if (rlen == 0) {
+ stream_reset(s);
+ return;
+ }
+
+ /* Move the available data to the beginning. */
+ memmove(s->data, &s->data[s->getp], rlen);
+ s->getp = 0;
+ s->endp = rlen;
+}