]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/fb-socket.c
Config: Added support for terabyte values, for example "123T".
[libucw.git] / ucw / fb-socket.c
index ae22e7227ed514575451718bf7689bbab917e468..19f27bd52130b480a40f4b0418794958d0e14ae4 100644 (file)
@@ -2,14 +2,15 @@
  *     UCW Library -- Fast Buffered I/O on Sockets with Timeouts
  *
  *     (c) 2008 Martin Mares <mj@ucw.cz>
+ *     (c) 2017 Pavel Charvat <pchar@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
  */
 
-#include "ucw/lib.h"
-#include "ucw/fastbuf.h"
-#include "ucw/fb-socket.h"
+#include <ucw/lib.h>
+#include <ucw/fastbuf.h>
+#include <ucw/fb-socket.h>
 
 #include <stdio.h>
 #include <unistd.h>
@@ -22,7 +23,7 @@ struct fb_sock {
   byte buf[0];
 };
 
-#define FB_SOCK(f) ((struct fb_sock *)(f)->is_fastbuf)
+#define FB_SOCK(f) ((struct fb_sock *)(f))
 
 static int
 fbs_refill(struct fastbuf *f)
@@ -71,9 +72,10 @@ fbs_spout(struct fastbuf *f)
       .events = POLLOUT,
   };
 
-  int l = f->bptr - f->buffer;
-  f->bptr = f->buffer;
-  char *buf = f->buffer;
+  int l = f->bptr - f->bstop;
+  f->bptr = f->bstop;
+  f->pos += l;
+  char *buf = f->bstop;
 
   while (l)
     {
@@ -105,7 +107,8 @@ fbs_spout(struct fastbuf *f)
 static void
 fbs_close(struct fastbuf *f)
 {
-  close(FB_SOCK(f)->par.fd);
+  if (!FB_SOCK(f)->par.fd_is_shared)
+    close(FB_SOCK(f)->par.fd);
   xfree(f);
 }
 
@@ -125,14 +128,14 @@ fbsock_create(struct fbsock_params *p)
   f->spout = fbs_spout;
   f->close = fbs_close;
   f->can_overwrite_buffer = 1;
-  return fb_tie(f);
+  return f;
 }
 
 #ifdef TEST
 
 #include <stdlib.h>
 
-static void test_err(void *x UNUSED, uns flags, char *msg UNUSED)
+static void test_err(void *x UNUSED, uint flags, char *msg UNUSED)
 {
   if (flags & FBSOCK_READ)
     printf("READ");