diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2014-12-06 17:51:14 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2014-12-06 17:51:14 +0000 |
commit | 6319ac5225aec738f134f338f68109822581bff1 (patch) | |
tree | 17e827cff6841eaae0de6b0b733ee2e8958cc9e0 /src/include | |
parent | 5d6810d9eb833f923f1543fbb369823f7cd289df (diff) | |
download | skalibs-6319ac5225aec738f134f338f68109822581bff1.tar.xz |
Rewrite unixmessage_receiver without buffer, only cbuffer
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/skalibs/buffer.h | 13 | ||||
-rw-r--r-- | src/include/skalibs/unixmessage.h | 27 |
2 files changed, 18 insertions, 22 deletions
diff --git a/src/include/skalibs/buffer.h b/src/include/skalibs/buffer.h index 3064c51..9060d08 100644 --- a/src/include/skalibs/buffer.h +++ b/src/include/skalibs/buffer.h @@ -9,7 +9,7 @@ #include <skalibs/diuint.h> #include <skalibs/siovec.h> -typedef int buffer_io_func_t (int, siovec_t const *, unsigned int, void *) ; +typedef int buffer_io_func_t (int, siovec_t const *, unsigned int) ; typedef buffer_io_func_t *buffer_io_func_t_ref ; typedef struct buffer_s buffer, buffer_t, *buffer_ref, *buffer_t_ref ; @@ -18,14 +18,13 @@ struct buffer_s buffer_io_func_t *op ; int fd ; cbuffer_t c ; - void *aux ; } ; -#define BUFFER_ZERO { .op = 0, .fd = -1, .c = CBUFFER_ZERO, .aux = 0 } +#define BUFFER_ZERO { .op = 0, .fd = -1, .c = CBUFFER_ZERO } /* Circular buffers need to be 1 char bigger than the storage space, - so that the head == tail case is nonambiguous (empty). + so that the head == tail case is nonambiguous (empty, not full). */ #define BUFFER_INSIZE 8193 @@ -34,10 +33,8 @@ struct buffer_s #define BUFFER_INSIZE_SMALL 513 #define BUFFER_OUTSIZE_SMALL 513 -#define BUFFER_INIT_AUX(f, d, buf, len, data) { .op = (f), .fd = (d), .c = CBUFFER_INIT(buf, len), .aux = (data) } -#define BUFFER_INIT(f, d, buf, len) BUFFER_INIT_AUX(f, d, buf, (len), 0) -extern int buffer_init_aux (buffer *, buffer_io_func_t *, int, char *, unsigned int, void *) ; -#define buffer_init(b, f, d, buf, len) buffer_init_aux(b, f, d, buf, len, 0) +#define BUFFER_INIT(f, d, buf, len) { .op = (f), .fd = (d), .c = CBUFFER_INIT(buf, len) } +extern int buffer_init (buffer *, buffer_io_func_t *, int, char *, unsigned int) ; /* Writing */ diff --git a/src/include/skalibs/unixmessage.h b/src/include/skalibs/unixmessage.h index d603a86..28e084c 100644 --- a/src/include/skalibs/unixmessage.h +++ b/src/include/skalibs/unixmessage.h @@ -6,6 +6,7 @@ #include <skalibs/buffer.h> #include <skalibs/cbuffer.h> #include <skalibs/gccattributes.h> +#include <skalibs/stralloc.h> #include <skalibs/genalloc.h> #include <skalibs/siovec.h> #include <skalibs/stralloc.h> @@ -81,36 +82,34 @@ extern int unixmessage_sender_timed_flush (unixmessage_sender_t *, tain_t const typedef struct unixmessage_receiver_s unixmessage_receiver_t, *unixmessage_receiver_t_ref ; struct unixmessage_receiver_s { - buffer mainb ; + int fd ; + cbuffer_t mainb ; cbuffer_t auxb ; unsigned int mainlen ; unsigned int auxlen ; - stralloc data ; - int fds[UNIXMESSAGE_MAXFDS] ; - unsigned int auxw ; + stralloc maindata ; + stralloc auxdata ; } ; -#define UNIXMESSAGE_RECEIVER_ZERO { .mainb = BUFFER_ZERO, .auxb = CBUFFER_ZERO, .mainlen = 0, .auxlen = 0, .data = STRALLOC_ZERO, .fds = { -1 }, .auxw = 0 } -#define UNIXMESSAGE_RECEIVER_INIT(var, fd, s, n, auxs, auxn) \ +#define UNIXMESSAGE_RECEIVER_ZERO { .fd = -1, .mainb = CBUFFER_ZERO, .auxb = CBUFFER_ZERO, .mainlen = 0, .auxlen = 0, .maindata = STRALLOC_ZERO, .auxdata = STRALLOC_ZERO } +#define UNIXMESSAGE_RECEIVER_INIT(d, mains, mainn, auxs, auxn) \ { \ - .mainb = BUFFER_INIT_AUX(&unixmessage_read, fd, s, n, &(var).auxb), \ + .fd = d, \ + .mainb = CBUFFER_INIT(mains, mainn), \ .auxb = CBUFFER_INIT(auxs, auxn), \ .mainlen = 0, \ .auxlen = 0, \ - .data = STRALLOC_ZERO, \ - .auxw = 0 \ + .maindata = STRALLOC_ZERO, \ + .auxdata = STRALLOC_ZERO \ } -#define UNIXMESSAGE_RECEIVER_DECLARE_AND_INIT(var, fd, s, n, auxs, auxn) unixmessage_receiver_t var = UNIXMESSAGE_RECEIVER_INIT(var, fd, s, n, auxs, auxn) extern int unixmessage_receiver_init (unixmessage_receiver_t *, int, char *, unsigned int, char *, unsigned int) ; extern void unixmessage_receiver_free (unixmessage_receiver_t *) ; -#define unixmessage_receiver_fd(b) buffer_fd(&(b)->mainb) -#define unixmessage_receiver_isempty(b) (buffer_isempty(&(b)->mainb) && cbuffer_isempty(&(b)->auxb)) +#define unixmessage_receiver_fd(b) ((b)->fd) +#define unixmessage_receiver_isempty(b) (cbuffer_isempty(&(b)->mainb) && cbuffer_isempty(&(b)->auxb)) extern int unixmessage_receive (unixmessage_receiver_t *, unixmessage_t *) ; extern int unixmessage_timed_receive (unixmessage_receiver_t *, unixmessage_t *, tain_t const *, tain_t *) ; #define unixmessage_timed_receive_g(receiver, msg, deadline) unixmessage_timed_receive(receiver, msg, (deadline), &STAMP) -extern buffer_io_func_t unixmessage_read ; - typedef int unixmessage_handler_func_t (unixmessage_t const *, void *) ; typedef unixmessage_handler_func_t *unixmessage_handler_func_t_ref ; |