From 9fa0d3b00b6e436831d37ff6257a6ee8b222fa8e Mon Sep 17 00:00:00 2001 From: Jan 'Moskyt' Matejka Date: Mon, 16 Jul 2012 11:27:28 +0200 Subject: [PATCH] Fastbuf: fbmulti_remove --- ucw/fastbuf.h | 5 +++++ ucw/fb-multi.c | 25 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ucw/fastbuf.h b/ucw/fastbuf.h index 5c3ad129..40b60dca 100644 --- a/ucw/fastbuf.h +++ b/ucw/fastbuf.h @@ -509,11 +509,16 @@ static inline void fbatomic_commit(struct fastbuf *b) * fbmulti is seeked to the beginning, flushed and ready to read the whole buffer. * * For performance reasons, use @fbmulti_flatten() only once, just before reading. + * + * If you want to remove a fastbuf from the chain, just call @fbmulti_remove + * where the second parameter is a pointer to the removed fastbuf. If you pass + * NULL, all the underlying fastbufs are removed. ***/ struct fastbuf *fbmulti_create(uns bufsize, ...) SENTINEL_CHECK; void fbmulti_append(struct fastbuf *f, struct fastbuf *fa, int allow_close); void fbmulti_flatten(struct fastbuf *f); +void fbmulti_remove(struct fastbuf *f, struct fastbuf *fb); /*** === Configuring stream parameters [[bconfig]] ***/ diff --git a/ucw/fb-multi.c b/ucw/fb-multi.c index 0bf6d9e4..8071aa0c 100644 --- a/ucw/fb-multi.c +++ b/ucw/fb-multi.c @@ -154,7 +154,7 @@ fbmulti_update_capability(struct fastbuf *f) CLIST_FOR_EACH(struct subbuf *, n, *(FB_MULTI(f)->subbufs)) { - ASSERT(n->fb->refill) + ASSERT(n->fb->refill); if (!n->fb->seek) f->seek = NULL; @@ -210,6 +210,29 @@ fbmulti_append(struct fastbuf *f, struct fastbuf *fb, int allow_close) sb->fb = fb; sb->allow_close = allow_close; clist_add_tail(FB_MULTI(f)->subbufs, &(sb->n)); + fbmulti_update_capability(f); +} + +void +fbmulti_remove(struct fastbuf *f, struct fastbuf *fb) +{ + if (fb) + { + CLIST_FOR_EACH(struct subbuf *, n, *(FB_MULTI(f)->subbufs)) + if (fb == n->fb) + { + // TODO: fix seek positions + clist_remove(&(n->n)); + fbmulti_update_capability(f); + return; + } + + die("Given fastbuf %p not in given fbmulti %p.", fb, f); + } + else + clist_init(FB_MULTI(f)->subbufs); + + fbmulti_update_capability(f); } static void fbmulti_flatten_internal(struct fastbuf *f, clist *c, int allow_close) -- 2.39.5