diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-12-22 14:46:04 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-12-22 14:46:04 +0000 |
commit | 3c1ff1523587881324fc540fece06412c29c66de (patch) | |
tree | ecd5431551ebe81793a33297b86f26d90e12047a /src/include | |
parent | f3c9c3c70187967a670f1c059f5461dce745d92e (diff) | |
download | skalibs-3c1ff1523587881324fc540fece06412c29c66de.tar.xz |
Add textclient, fix some textmessage issues
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/skalibs/djbunix.h | 2 | ||||
-rw-r--r-- | src/include/skalibs/textclient.h | 112 | ||||
-rw-r--r-- | src/include/skalibs/textmessage.h | 11 | ||||
-rw-r--r-- | src/include/skalibs/unixonacid.h | 1 |
4 files changed, 121 insertions, 5 deletions
diff --git a/src/include/skalibs/djbunix.h b/src/include/skalibs/djbunix.h index b095c82..00d8f00 100644 --- a/src/include/skalibs/djbunix.h +++ b/src/include/skalibs/djbunix.h @@ -190,6 +190,8 @@ extern pid_t child_spawn2 (char const *, char const *const *, char const *const * if n>=2, parent reads on even and writes on odd. */ +#define SKALIBS_CHILD_SPAWN_FDS_ENVVAR "SKALIBS_CHILD_SPAWN_FDS" + extern pid_t child_spawn (char const *, char const *const *, char const *const *, int *, unsigned int) ; #endif diff --git a/src/include/skalibs/textclient.h b/src/include/skalibs/textclient.h new file mode 100644 index 0000000..17d4fff --- /dev/null +++ b/src/include/skalibs/textclient.h @@ -0,0 +1,112 @@ +/* ISC license. */ + +#ifndef SKALIBS_TEXTCLIENT_H +#define SKALIBS_TEXTCLIENT_H + +#include <sys/types.h> +#include <sys/uio.h> +#include <stdint.h> +#include <skalibs/allreadwrite.h> +#include <skalibs/tai.h> +#include <skalibs/textmessage.h> + + + /* + This is a simpler, smaller version of skaclient for basic cases: + - no fd-passing + - no asyncout + - no kolbak: client calls are always synchronous + - fixed-size buffers included in the client structure + */ + +#define TEXTCLIENT_BUFSIZE 4096 +#define TEXTCLIENT_OPTION_WAITPID 0x00000001U + + + /* Server-side functions */ + +extern int textclient_server_init (textmessage_receiver_t *, textmessage_sender_t *, textmessage_sender_t *, char const *, size_t, char const *, size_t, tain_t const *, tain_t *) ; +extern int textclient_server_init_frompipe (textmessage_receiver_t *, textmessage_sender_t *, textmessage_sender_t *, char const *, size_t, char const *, size_t, tain_t const *, tain_t *) ; +extern int textclient_server_init_fromsocket (textmessage_receiver_t *, textmessage_sender_t *, textmessage_sender_t *, char const *, size_t, char const *, size_t, tain_t const *, tain_t *) ; +#define textclient_server_init_g(in, syncout, asyncout, before, beforelen, after, afterlen, deadline) textclient_server_init(in, syncout, asyncout, before, beforelen, after, afterlen, (deadline), &STAMP) +#define textclient_server_init_frompipe_g(in, syncout, asyncout, before, beforelen, after, afterlen, deadline) textclient_server_init_frompipe(in, syncout, asyncout, before, beforelen, after, afterlen, (deadline), &STAMP) +#define textclient_server_init_fromsocket_g(in, syncout, asyncout, before, beforelen, after, afterlen, deadline) textclient_server_init_fromsocket(in, syncout, asyncout, before, beforelen, after, afterlen, (deadline), &STAMP) +#define textclient_server_01x_init(before, beforelen, after, afterlen, deadline, stamp) textclient_server_init(textmessage_receiver_0, textmessage_sender_1, textmessage_sender_x, before, beforelen, after, afterlen, deadline, stamp) +#define textclient_server_01x_init_frompipe(before, beforelen, after, afterlen, deadline, stamp) textclient_server_init_frompipe(textmessage_receiver_0, textmessage_sender_1, textmessage_sender_x, before, beforelen, after, afterlen, deadline, stamp) +#define textclient_server_01x_init_fromsocket(before, beforelen, after, afterlen, deadline, stamp) textclient_server_init_fromsocket(textmessage_receiver_0, textmessage_sender_1, textmessage_sender_x, before, beforelen, after, afterlen, deadline, stamp) +#define textclient_server_01x_init_g(before, beforelen, after, afterlen, deadline) textclient_server_01x_init(before, beforelen, after, afterlen, (deadline), &STAMP) +#define textclient_server_01x_init_frompipe_g(before, beforelen, after, afterlen, deadline) textclient_server_01x_init_frompipe(before, beforelen, after, afterlen, (deadline), &STAMP) +#define textclient_server_01x_init_fromsocket_g(before, beforelen, after, afterlen, deadline) textclient_server_01x_init_fromsocket(before, beforelen, after, afterlen, (deadline), &STAMP) + + + /* User structure */ + +typedef struct textclient_s textclient_t, *textclient_t_ref ; +struct textclient_s +{ + textmessage_sender_t syncout ; + textmessage_receiver_t syncin ; + textmessage_receiver_t asyncin ; + pid_t pid ; + uint32_t options ; + char syncbuf[TEXTCLIENT_BUFSIZE] ; + char asyncbuf[TEXTCLIENT_BUFSIZE] ; +} ; +#define TEXTCLIENT_ZERO { .syncout = TEXTMESSAGE_SENDER_ZERO, .syncin = TEXTMESSAGE_RECEIVER_ZERO, .asyncin = TEXTMESSAGE_RECEIVER_ZERO, .pid = 0, .options = 0 } +extern textclient_t const textclient_zero ; + + + /* Starting and ending */ + +extern void textclient_end (textclient_t *) ; + +extern int textclient_start (textclient_t *, char const *, uint32_t, char const *, size_t, char const *, size_t, tain_t const *, tain_t *) ; +extern int textclient_startf (textclient_t *, char const *const *, char const *const *, uint32_t, char const *, size_t, char const *, size_t, tain_t const *, tain_t *) ; + +#define textclient_start_g(a, path, options, before, beforelen, after, afterlen, deadline) textclient_start(a, path, options, before, beforelen, after, afterlen, (deadline), &STAMP) +#define textclient_startf_g(a, argv, envp, options, before, beforelen, after, afterlen, deadline) textclient_startf_b(a, argv, envp, options, before, beforelen, after, afterlen, (deadline), &STAMP) + + + /* Writing */ + +#define textclient_put(a, s, len) textmessage_sender_put(&(a)->syncout, s, len) +#define textclient_putv(a, v, n) textmessage_sender_putv(&(a)->syncout, v, n) +#define textclient_flush(a) textmessage_sender_flush(&(a)->syncout) +#define textclient_timed_flush(a, deadline, stamp) textmessage_sender_timed_flush(&(a)->syncout, deadline, stamp) +#define textclient_timed_flush_g(a, deadline) textclient_timed_flush(a, (deadline), &STAMP) +#define textclient_send(a, s, len) textmessage_send(&(a)->syncout, s, len) +#define textclient_sendv(a, v, n) textmessage_sendv(&(a)->syncout, v, n) +#define textclient_timed_send(a, s, len, deadline, stamp) textmessage_timed_send(&(a)->syncout, s, len, deadline, stamp) +#define textclient_timed_sendv(a, v, n, deadline, stamp) textmessage_timed_sendv(&(a)->syncout, v, n, deadline, stamp) +#define textclient_timed_send_g(a, s, len, deadline) textclient_timed_send(a, s, len, (deadline), &STAMP) +#define textclient_timed_sendv_g(a, v, n, deadline) textclient_timed_sendv(a, v, n, (deadline), &STAMP) + + + /* Sync reading */ + +#define textclient_get(a, v) textmessage_receive(&(a)->syncin, v) +#define textclient_timed_get(a, v, deadline, stamp) (sanitize_read(textmessage_timed_receive(&(a)->syncin, v, deadline, stamp)) > 0) +#define textclient_timed_get_g(a, v, deadline) textclient_timed_get(a, v, (deadline), &STAMP) + + + /* Sync writing+reading */ + +#define textclient_exchange(a, s, len, ans, deadline, stamp) (textclient_timed_send(a, s, len, deadline, stamp) && textclient_timed_get(a, ans, deadline, stamp)) +#define textclient_exchangev(a, v, n, ans, deadline, stamp) (textclient_timed_sendv(a, v, n, deadline, stamp) && textclient_timed_get(a, ans, deadline, stamp)) +#define textclient_exchange_g(a, s, len, ans, deadline) textclient_exchange(a, s, len, ans, (deadline), &STAMP) +#define textclient_exchangev_g(a, v, n, ans, deadline) textclient_exchangev(a, v, n, ans, (deadline), &STAMP) + +extern int textclient_command (textclient_t *, char const *, size_t, tain_t const *, tain_t *) ; +extern int textclient_commandv (textclient_t *, struct iovec const *, unsigned int, tain_t const *, tain_t *) ; +#define textclient_command_g(a, s, len, deadline) textclient_command(a, s, len, (deadline), &STAMP) +#define textclient_commandv_g(a, v, n, deadline) textclient_commandv(a, v, n, (deadline), &STAMP) + + + /* Async reading */ + +#define textclient_fd(a) textmessage_receiver_fd(&(a)->asyncin) +#define textclient_update(a, f, p) textmessage_handle(&(a)->asyncin, f, p) +#define textclient_timed_update(a, f, p, deadline, stamp) textmessage_timed_handle(&(a)->asyncin, f, p, deadline, stamp) +#define textclient_timed_update_g(a, f, p, deadline) textclient_timed_update(a, f, p, (deadline), &STAMP) + +#endif diff --git a/src/include/skalibs/textmessage.h b/src/include/skalibs/textmessage.h index 9904534..fd393a9 100644 --- a/src/include/skalibs/textmessage.h +++ b/src/include/skalibs/textmessage.h @@ -13,6 +13,7 @@ #include <skalibs/tai.h> #define TEXTMESSAGE_MAXREADS 128 +#define TEXTMESSAGE_MAXLEN 0x01000000U /* Sender */ @@ -36,13 +37,13 @@ extern int textmessage_put (textmessage_sender_t *, char const *, size_t) ; extern int textmessage_putv (textmessage_sender_t *, struct iovec const *, unsigned int) ; extern int textmessage_sender_flush (textmessage_sender_t *) ; -extern int unixmessage_sender_timed_flush (textmessage_sender_t *, tain_t const *, tain_t *) ; +extern int textmessage_sender_timed_flush (textmessage_sender_t *, tain_t const *, tain_t *) ; #define textmessage_sender_timed_flush_g(ts, deadline) textmessage_sender_timed_flush(ts, (deadline), &STAMP) #define textmessage_send(ts, s, len) (textmessage_put(ts, s, len) && textmessage_sender_flush(ts)) #define textmessage_sendv(ts, v, n) (textmessage_putv(ts, v, n) && textmessage_sender_flush(ts)) -#define textmessage_timed_send(ts, s, len, deadline, stamp) (textmessage_put(ts, s, len) && texxtmessage_sender_timed_flush(ts, deadline, stamp)) -#define textmessage_timed_sendv(ts, v, n, deadline, stamp) (textmessage_putv(ts, v, n) && texxtmessage_sender_timed_flush(ts, deadline, stamp)) +#define textmessage_timed_send(ts, s, len, deadline, stamp) (textmessage_put(ts, s, len) && textmessage_sender_timed_flush(ts, deadline, stamp)) +#define textmessage_timed_sendv(ts, v, n, deadline, stamp) (textmessage_putv(ts, v, n) && textmessage_sender_timed_flush(ts, deadline, stamp)) #define textmessage_timed_send_g(ts, s, len, deadline) textmessage_timed_send(ts, s, len, (deadline), &STAMP) #define textmessage_timed_sendv_g(ts, v, n, deadline) textmessage_timed_sendv(ts, v, n, (deadline), &STAMP) @@ -71,14 +72,14 @@ extern int textmessage_receiver_hasmsginbuf (textmessage_receiver_t const *) gcc extern int textmessage_receive (textmessage_receiver_t *, struct iovec *) ; extern int textmessage_timed_receive (textmessage_receiver_t *, struct iovec *, tain_t const *, tain_t *) ; -#define textmessage_timed_receive_g(tr, s, max, deadline) textmessage_timed_receive(tr, s, max, (deadline), &STAMP) +#define textmessage_timed_receive_g(tr, v, deadline) textmessage_timed_receive(tr, v, (deadline), &STAMP) typedef int textmessage_handler_func_t (struct iovec const *, void *) ; typedef textmessage_handler_func_t *textmessage_handler_func_t_ref ; extern int textmessage_handle (textmessage_receiver_t *, textmessage_handler_func_t_ref, void *) ; extern int textmessage_timed_handle (textmessage_receiver_t *, textmessage_handler_func_t_ref, void *, tain_t const *, tain_t *) ; -#define textmessage_timed_handle_g(tr, f, p, deadline) unixmessage_timed_handle(tr, f, p, (deadline), &STAMP) +#define textmessage_timed_handle_g(tr, f, p, deadline) textmessage_timed_handle(tr, f, p, (deadline), &STAMP) diff --git a/src/include/skalibs/unixonacid.h b/src/include/skalibs/unixonacid.h index 43bd695..7132f1c 100644 --- a/src/include/skalibs/unixonacid.h +++ b/src/include/skalibs/unixonacid.h @@ -6,6 +6,7 @@ #include <skalibs/unix-transactional.h> #include <skalibs/unix-timed.h> #include <skalibs/textmessage.h> +#include <skalibs/textclient.h> #include <skalibs/unixmessage.h> #include <skalibs/unixconnection.h> #include <skalibs/kolbak.h> |