From 00a4c6056dba93c98cac687f24d5122acc76ded0 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 9 Jan 2015 17:04:38 +0000 Subject: Add unixmessage_unput, for transaction cancellation --- package/deps.mak | 1 + src/include/skalibs/unixmessage.h | 4 ++++ src/libunixonacid/unixmessage_unput.c | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 src/libunixonacid/unixmessage_unput.c diff --git a/package/deps.mak b/package/deps.mak index e9c9165..0200100 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -764,5 +764,6 @@ src/libunixonacid/unixmessage_sender_x.o src/libunixonacid/unixmessage_sender_x. src/libunixonacid/unixmessage_sender_zero.o src/libunixonacid/unixmessage_sender_zero.lo: src/libunixonacid/unixmessage_sender_zero.c src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_timed_handle.o src/libunixonacid/unixmessage_timed_handle.lo: src/libunixonacid/unixmessage_timed_handle.c src/include/skalibs/functypes.h src/include/skalibs/tai.h src/include/skalibs/unix-timed.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_timed_receive.o src/libunixonacid/unixmessage_timed_receive.lo: src/libunixonacid/unixmessage_timed_receive.c src/include/skalibs/functypes.h src/include/skalibs/tai.h src/include/skalibs/unix-timed.h src/include/skalibs/unixmessage.h +src/libunixonacid/unixmessage_unput.o src/libunixonacid/unixmessage_unput.lo: src/libunixonacid/unixmessage_unput.c src/include/skalibs/diuint.h src/include/skalibs/djbunix.h src/include/skalibs/genalloc.h src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_v_zero.o src/libunixonacid/unixmessage_v_zero.lo: src/libunixonacid/unixmessage_v_zero.c src/include/skalibs/unixmessage.h src/libunixonacid/unixmessage_zero.o src/libunixonacid/unixmessage_zero.lo: src/libunixonacid/unixmessage_zero.c src/include/skalibs/unixmessage.h diff --git a/src/include/skalibs/unixmessage.h b/src/include/skalibs/unixmessage.h index 3252a50..5451a05 100644 --- a/src/include/skalibs/unixmessage.h +++ b/src/include/skalibs/unixmessage.h @@ -75,6 +75,10 @@ extern int unixmessage_put_and_close (unixmessage_sender_t *, unixmessage_t cons extern int unixmessage_putv_and_close (unixmessage_sender_t *, unixmessage_v_t const *, unsigned char const *) ; #define unixmessage_putv(b, m) unixmessage_putv_and_close(b, m, unixmessage_bits_closenone) +extern int unixmessage_unput_and_maybe_drop (unixmessage_sender_t *, int) ; +#define unixmessage_unput(b) unixmessage_unput_and_maybe_drop((b), 0) +#define unixmessage_unput_and_drop(b) unixmessage_unput_and_maybe_drop((b), 1) + extern unsigned char const *const unixmessage_bits_closenone ; extern unsigned char const *const unixmessage_bits_closeall ; diff --git a/src/libunixonacid/unixmessage_unput.c b/src/libunixonacid/unixmessage_unput.c new file mode 100644 index 0000000..48d46b5 --- /dev/null +++ b/src/libunixonacid/unixmessage_unput.c @@ -0,0 +1,23 @@ + /* ISC license. */ + +#include +#include +#include +#include + +int unixmessage_unput_and_maybe_drop (unixmessage_sender_t *b, int drop) +{ + diuint *start ; + unsigned int n = genalloc_len(diuint, &b->offsets) ; + if (!n) return 0 ; + start = genalloc_s(diuint, &b->offsets) + n - 1 ; + if (drop) + { + register int *fds = genalloc_s(int, &b->fds) + start->right ; + register unsigned int i = genalloc_len(int, &b->fds) - start->right ; + while (i--) fd_close(fds[i] < 0 ? -(fds[i]+1) : fds[i]) ; + } + b->data.len = start->left ; + genalloc_setlen(int, &b->fds, start->right) ; + return 1 ; +} -- cgit v1.2.3