skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

commit 82724c82fd69720a579a8b245637ac247c08c700
parent 8ddcb8ca23638109b0b4c31b2214cd0cad700b6a
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Thu,  4 Dec 2014 16:30:20 +0000

Better interface for simple skaclient servers

Diffstat:
Msrc/include/skalibs/skaclient.h | 6++++--
Msrc/include/skalibs/unixmessage.h | 16++++++++++++++++
Asrc/libunixonacid/skaclient_server_01x.c | 21+++++++++++++++++++++
Msrc/libunixonacid/skaclient_server_init.c | 10++++------
Asrc/libunixonacid/unixmessage_receiver_0.c | 15+++++++++++++++
Asrc/libunixonacid/unixmessage_sender_1.c | 7+++++++
Asrc/libunixonacid/unixmessage_sender_x.c | 7+++++++
7 files changed, 74 insertions(+), 8 deletions(-)

diff --git a/src/include/skalibs/skaclient.h b/src/include/skalibs/skaclient.h @@ -15,8 +15,10 @@ extern int skaclient_server_ack (unixmessage_t const *, unixmessage_sender_t *, unixmessage_sender_t *, char const *, unsigned int, char const *, unsigned int) ; extern int skaclient_server_bidi_ack (unixmessage_t const *, unixmessage_sender_t *, unixmessage_sender_t *, unixmessage_receiver_t *, char *, unsigned int, char *, unsigned int, char const *, unsigned int, char const *, unsigned int) ; -extern int skaclient_server_init (unixmessage_receiver_t *, char *, unsigned int, char *, unsigned int, unixmessage_sender_t *, unixmessage_sender_t *, char const *, unsigned int, char const *, unsigned int, tain_t const *, tain_t *) ; -#define skaclient_server_init_g(in, mainbuf, mainlen, auxbuf, auxlen, out, asyncout, before, beforelen, after, afterlen, deadline) skaclient_server_init(in, mainbuf, mainlen, auxbuf, auxlen, out, asyncout, before, beforelen, after, afterlen, (deadline), &STAMP) +extern int skaclient_server_init (unixmessage_receiver_t *, unixmessage_sender_t *, unixmessage_sender_t *, char const *, unsigned int, char const *, unsigned int, tain_t const *, tain_t *) ; +#define skaclient_server_init_g(in, out, asyncout, before, beforelen, after, afterlen, deadline) skaclient_server_init(in, out, asyncout, before, beforelen, after, afterlen, (deadline), &STAMP) +extern int skaclient_server_01x_init (char const *, unsigned int, char const *, unsigned int, tain_t const *, tain_t *) ; +#define skaclient_server_01x_init_g(before, beforelen, after, afterlen, deadline) skaclient_server_01x_init(before, beforelen, after, afterlen, (deadline), &STAMP) /* Client part: the rest of this file */ diff --git a/src/include/skalibs/unixmessage.h b/src/include/skalibs/unixmessage.h @@ -100,4 +100,20 @@ extern int unixmessage_handle (unixmessage_receiver_t *, unixmessage_handler_fun extern int unixmessage_timed_handle (unixmessage_receiver_t *, unixmessage_handler_func_t *, void *, tain_t const *, tain_t *) ; #define unixmessage_timed_handle_g(b, f, p, deadline) unixmessage_timed_handle(b, f, p, (deadline), &STAMP) + + /* Globals */ + +#define UNIXMESSAGE_RECEIVER_MAINBUFSIZE 4097 +#define UNIXMESSAGE_RECEIVER_AUXBUFSIZE 4097 + +extern unixmessage_receiver_t unixmessage_receiver_0_ ; +#define unixmessage_receiver_0 (&unixmessage_receiver_0_) +extern int unixmessage_receiver_0_init (void) ; + +extern unixmessage_sender_t unixmessage_sender_1_ ; +#define unixmessage_sender_1 (&unixmessage_sender_1_) + +extern unixmessage_sender_t unixmessage_sender_x_ ; +#define unixmessage_sender_x (&unixmessage_sender_x_) + #endif diff --git a/src/libunixonacid/skaclient_server_01x.c b/src/libunixonacid/skaclient_server_01x.c @@ -0,0 +1,21 @@ +/* ISC license. */ + +/* MT-unsafe */ + +#include <skalibs/tai.h> +#include <skalibs/unixmessage.h> +#include <skalibs/skaclient.h> + +int skaclient_server_01x_init (char const *before, unsigned int beforelen, char const *after, unsigned int afterlen, tain_t const *deadline, tain_t *stamp) +{ + return unixmessage_receiver_0_init() && skaclient_server_init( + unixmessage_receiver_0, + unixmessage_sender_1, + unixmessage_sender_x, + before, + beforelen, + after, + afterlen, + deadline, + stamp) ; +} diff --git a/src/libunixonacid/skaclient_server_init.c b/src/libunixonacid/skaclient_server_init.c @@ -4,12 +4,10 @@ #include <skalibs/tai.h> #include <skalibs/unixmessage.h> -int skaclient_server_init (unixmessage_receiver_t *in, char *mainbuf, unsigned int mainlen, char *auxbuf, unsigned int auxlen, unixmessage_sender_t *out, unixmessage_sender_t *asyncout, char const *before, unsigned int beforelen, char const *after, unsigned int afterlen, tain_t const *deadline, tain_t *stamp) +int skaclient_server_init (unixmessage_receiver_t *in, unixmessage_sender_t *out, unixmessage_sender_t *asyncout, char const *before, unsigned int beforelen, char const *after, unsigned int afterlen, tain_t const *deadline, tain_t *stamp) { unixmessage_t m ; - if (!unixmessage_receiver_init(in, 0, mainbuf, mainlen, auxbuf, auxlen)) return 0 ; - unixmessage_sender_init(out, 1) ; - if (unixmessage_timed_receive(in, &m, deadline, stamp) < 0) return 0 ; - if (!skaclient_server_ack(&m, out, asyncout, before, beforelen, after, afterlen)) return 0 ; - return unixmessage_sender_timed_flush(out, deadline, stamp) ; + return (unixmessage_timed_receive(in, &m, deadline, stamp) >= 0) + && skaclient_server_ack(&m, out, asyncout, before, beforelen, after, afterlen) + && unixmessage_sender_timed_flush(out, deadline, stamp) ; } diff --git a/src/libunixonacid/unixmessage_receiver_0.c b/src/libunixonacid/unixmessage_receiver_0.c @@ -0,0 +1,15 @@ +/* ISC license. */ + +/* MT-unsafe */ + +#include <skalibs/unixmessage.h> + +static char mainbuf[UNIXMESSAGE_RECEIVER_MAINBUFSIZE] ; +static char auxbuf[UNIXMESSAGE_RECEIVER_AUXBUFSIZE] ; + +unixmessage_receiver_t unixmessage_receiver_0_ = UNIXMESSAGE_RECEIVER_ZERO ; + +int unixmessage_receiver_0_init () +{ + return unixmessage_receiver_init(&unixmessage_receiver_0_, 0, mainbuf, UNIXMESSAGE_RECEIVER_MAINBUFSIZE, auxbuf, UNIXMESSAGE_RECEIVER_AUXBUFSIZE) ; +} diff --git a/src/libunixonacid/unixmessage_sender_1.c b/src/libunixonacid/unixmessage_sender_1.c @@ -0,0 +1,7 @@ +/* ISC license. */ + +/* MT-unsafe */ + +#include <skalibs/unixmessage.h> + +unixmessage_sender_t unixmessage_sender_1_ = UNIXMESSAGE_SENDER_INIT(1) ; diff --git a/src/libunixonacid/unixmessage_sender_x.c b/src/libunixonacid/unixmessage_sender_x.c @@ -0,0 +1,7 @@ +/* ISC license. */ + +/* MT-unsafe */ + +#include <skalibs/unixmessage.h> + +unixmessage_sender_t unixmessage_sender_x_ = UNIXMESSAGE_SENDER_ZERO ;