]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/fastbuf.h
UCW::CGI: Documented the changes
[libucw.git] / ucw / fastbuf.h
index aa6c493177c920b2ab1dabe885c4236ed1f7e89c..4f0d99d3190be67c6fad8ae22e4e11a46760167d 100644 (file)
  * for how it works.
  **/
 struct fastbuf {
-  byte is_fastbuf[0];                          /* Dummy field for checking of type casts */
   byte *bptr, *bstop;                          /* State of the buffer */
   byte *buffer, *bufend;                       /* Start and end of the buffer */
   char *name;                                  /* File name (used for error messages) */
@@ -160,8 +159,6 @@ struct fastbuf *fb_tie(struct fastbuf *b);  /* Tie fastbuf to a resource if there
  *
  * If you want to use fastbufs to access files, you can choose one of several
  * back-ends and set their parameters.
- *
- * All file fastbufs are tied to resources automatically.
  ***/
 
 /**
@@ -308,8 +305,6 @@ void bclose_file_helper(struct fastbuf *f, int fd, int is_temp_file);
  *
  * The `fblim` back-end reads from a file handle, but at most a given
  * number of bytes. This is frequently used for reading from sockets.
- *
- * All such fastbufs are tied to resources automatically.
  ***/
 
 struct fastbuf *bopen_limited_fd(int fd, uns bufsize, uns limit); /** Create a fastbuf which reads at most @limit bytes from @fd. **/
@@ -324,8 +319,6 @@ struct fastbuf *bopen_limited_fd(int fd, uns bufsize, uns limit); /** Create a f
  * First, you use @fbmem_create() to create the stream and the fastbuf
  * used for writing to it. Then you can call @fbmem_clone_read() to get
  * an arbitrary number of fastbuf for reading from the stream.
- *
- * All in-memory fastbufs are tied to resources automatically.
  ***/
 
 struct fastbuf *fbmem_create(uns blocksize);           /** Create stream and return its writing fastbuf. **/
@@ -378,8 +371,6 @@ static inline uns fbbuf_count_written(struct fastbuf *f) /** Calculates, how man
  * size and it is expanded to accomodate all data.
  *
  * At every moment, you can use `fastbuf->buffer` to gain access to the stream.
- *
- * All fastbufs of this type are tied to resources automatically.
  ***/
 
 struct mempool;
@@ -445,8 +436,6 @@ void *fbpool_end(struct fbpool *fb);
  *
  * Please note that initialization of the clones is not thread-safe,
  * so you have to serialize it yourself.
- *
- * The atomic fastbufs are tied to resources automatically.
  ***/
 
 struct fb_atomic {
@@ -455,7 +444,6 @@ struct fb_atomic {
   byte *expected_max_bptr;
   uns slack_size;
 };
-#define FB_ATOMIC(f) ((struct fb_atomic *)(f)->is_fastbuf)
 
 /**
  * Open an atomic fastbuf.
@@ -485,6 +473,53 @@ static inline void fbatomic_commit(struct fastbuf *b)
     fbatomic_internal_write(b);
 }
 
+/***
+ * === Fastbufs atop other fastbufs [[fbmulti]]
+ *
+ * Imagine some code which does massive string processing. It takes an input
+ * buffer, writes a part of it into an output buffer, then some other string
+ * and then the remaining part of the input buffer. Or anything else where you
+ * copy all the data at each stage of the complicated process.
+ *
+ * This backend takes multiple fastbufs and concatenates them formally into
+ * one. You may then read them consecutively as they were one fastbuf at all.
+ *
+ * This backend is read-only.
+ *
+ * This backend is seekable iff all of the supplied fastbufs are seekable.
+ *
+ * You aren't allowed to do anything with the underlying buffers while these
+ * are connected into fbmulti.
+ *
+ * The fbmulti is inited by @fbmulti_create(). It returns an empty fbmulti.
+ * Then you call @fbmulti_append() for each fbmulti.
+ *
+ * If @bclose() is called on fbmulti, all the underlying buffers get closed
+ * recursively.
+ *
+ * If you want to keep an underlying fastbuf open after @bclose, just remove it
+ * by @fbmulti_remove where the second parameter is a pointer to the removed
+ * fastbuf. If you pass NULL, all the underlying fastbufs are removed.
+ *
+ * After @fbmulti_remove, the state of the fbmulti is undefined. The only allowed
+ * operation is either another @fbmulti_remove or @bclose on the fbmulti.
+ ***/
+
+/**
+ * Create an empty fbmulti
+ **/
+struct fastbuf *fbmulti_create(void);
+
+/**
+ * Append a fb to fbmulti
+ **/
+void fbmulti_append(struct fastbuf *f, struct fastbuf *fb);
+
+/**
+ * Remove a fb from fbmulti
+ **/
+void fbmulti_remove(struct fastbuf *f, struct fastbuf *fb);
+
 /*** === Configuring stream parameters [[bconfig]] ***/
 
 enum bconfig_type {                    /** Parameters that could be configured. **/