]> mj.ucw.cz Git - libucw.git/commitdiff
Resources: Simplified use of fb_tie()
authorMartin Mares <mj@ucw.cz>
Sun, 17 Apr 2011 11:15:12 +0000 (13:15 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 17 Apr 2011 11:15:12 +0000 (13:15 +0200)
ucw/fastbuf.c
ucw/fastbuf.h
ucw/fb-atomic.c
ucw/fb-direct.c
ucw/fb-file.c
ucw/fb-grow.c
ucw/fb-limfd.c
ucw/fb-mem.c
ucw/fb-mmap.c
ucw/fb-socket.c

index 4cd8bdfd1ccb467cce5bd37d61f75b1d47aa61d5..83c3b0790a60a8915d18ecfaed6e23ae8c282687 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     UCW Library -- Fast Buffered I/O
  *
- *     (c) 1997--2007 Martin Mares <mj@ucw.cz>
+ *     (c) 1997--2011 Martin Mares <mj@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
@@ -314,7 +314,8 @@ static const struct res_class fb_res_class = {
   .free = fb_res_free,
 };
 
-void fb_tie(struct fastbuf *f)
+struct fastbuf *fb_tie(struct fastbuf *f)
 {
   f->res = res_new(&fb_res_class, f);
+  return f;
 }
index 41f339eef813e5ed7f51e09a81248ed8eb9552f9..dfd29d00a8d627c77f5a461a8b00fc69e4e9db57 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     UCW Library -- Fast Buffered I/O
  *
- *     (c) 1997--2008 Martin Mares <mj@ucw.cz>
+ *     (c) 1997--2011 Martin Mares <mj@ucw.cz>
  *     (c) 2004 Robert Spalek <robert@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *
  *   - Initialization:
  *     * out: `buffer <= bstop <= bptr <= bufend` (flushed).
+ *     * @fb_tie() should be called on the newly created fastbuf.
  *
  *   - `refill`:
  *     * in: `buffer <= bstop <= bptr <= bufend` (reading or flushed).
@@ -143,7 +144,7 @@ struct fastbuf {
   struct resource *res;                                /* The fastbuf can be tied to a resource pool */
 };
 
-void fb_tie(struct fastbuf *b);                        /* Tie fastbuf to a resource if there is an active pool */
+struct fastbuf *fb_tie(struct fastbuf *b);     /* Tie fastbuf to a resource if there is an active pool */
 
 /**
  * Fastbuf flags
index 1b4a07bbd1a38296af15a0d6291d162ca6d86719..fca0dfb6582ed997653bed9703e9a47cae45be61 100644 (file)
@@ -133,8 +133,7 @@ fbatomic_open(const char *name, struct fastbuf *master, uns bufsize, int record_
   f->name = af->name;
   f->spout = fbatomic_spout;
   f->close = fbatomic_close;
-  fb_tie(f);
-  return f;
+  return fb_tie(f);
 }
 
 #ifdef TEST
index 264905792acdf4b7e59aee727be86dc7890199a4..ccdb851b1f492211edd069ee7400cd571e9ebea3 100644 (file)
@@ -308,8 +308,7 @@ fbdir_open_fd_internal(int fd, const char *name, struct asio_queue *q, uns buffe
   f->close = fbdir_close;
   f->config = fbdir_config;
   f->can_overwrite_buffer = 2;
-  fb_tie(f);
-  return f;
+  return fb_tie(f);
 }
 
 #ifdef TEST
index 35adbae49c8ffd1a13d3094afe6afabd16082cec..cc5cf22cba1aa951290339c4205326d482589612 100644 (file)
@@ -238,8 +238,7 @@ bfdopen_internal(int fd, const char *name, uns buflen)
   f->close = bfd_close;
   f->config = bfd_config;
   f->can_overwrite_buffer = 2;
-  fb_tie(f);
-  return f;
+  return fb_tie(f);
 }
 
 void
index 27b5bf038b0a8329b8e9ca3e939b838a4762d7c4..19880ed36fd8f299559eae7479b1c5ba79b90097 100644 (file)
@@ -92,8 +92,7 @@ struct fastbuf *fbgrow_create_mp(struct mempool *mp, unsigned basic_size)
   b->spout = fbgrow_spout;
   b->seek = fbgrow_seek;
   b->can_overwrite_buffer = 1;
-  fb_tie(b);
-  return b;
+  return fb_tie(b);
 }
 
 struct fastbuf *fbgrow_create(unsigned basic_size)
index f909da3bb027f77f733f1835a302c319975ebeb7..9bbd2f981c88cbbc4ac9e069da37b6ab95308bf7 100644 (file)
@@ -55,8 +55,7 @@ bopen_limited_fd(int fd, uns buflen, uns limit)
   f->refill = bfl_refill;
   f->close = bfl_close;
   f->can_overwrite_buffer = 2;
-  fb_tie(f);
-  return f;
+  return fb_tie(f);
 }
 
 #ifdef TEST
index 38fa9001d374050f3289ce36243816c0fc88a1ed..bacdf03ff10260d7eb83ff2527297d18bb89f60d 100644 (file)
@@ -162,8 +162,7 @@ fbmem_create(unsigned blocksize)
   f->name = "<fbmem-write>";
   f->spout = fbmem_spout;
   f->close = fbmem_close;
-  fb_tie(f);
-  return f;
+  return fb_tie(f);
 }
 
 struct fastbuf *
@@ -181,8 +180,7 @@ fbmem_clone_read(struct fastbuf *b)
   f->seek = fbmem_seek;
   f->close = fbmem_close;
   f->can_overwrite_buffer = 1;
-  fb_tie(f);
-  return f;
+  return fb_tie(f);
 }
 
 #ifdef TEST
index d1882ee77b848d33a696eb429e33961dd324b942..b6a61248cf42a7ed15fa2da2b70aaff1f1a3fc3e 100644 (file)
@@ -192,8 +192,7 @@ bfmmopen_internal(int fd, const char *name, uns mode)
   f->seek = bfmm_seek;
   f->close = bfmm_close;
   f->config = bfmm_config;
-  fb_tie(f);
-  return f;
+  return fb_tie(f);
 }
 
 #ifdef TEST
index d90f7e7c18bbedfe1bfa24c00ec7091a2deab18e..ae22e7227ed514575451718bf7689bbab917e468 100644 (file)
@@ -125,8 +125,7 @@ fbsock_create(struct fbsock_params *p)
   f->spout = fbs_spout;
   f->close = fbs_close;
   f->can_overwrite_buffer = 1;
-  fb_tie(f);
-  return f;
+  return fb_tie(f);
 }
 
 #ifdef TEST