summaryrefslogtreecommitdiff
path: root/src/libunixonacid/unixmessage_unput.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-01-09 17:04:38 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-01-09 17:04:38 +0000
commit00a4c6056dba93c98cac687f24d5122acc76ded0 (patch)
tree39a94d2c570ddb02e3798c76ceea041c865031dd /src/libunixonacid/unixmessage_unput.c
parent978416c7e201d8261f9ecf512169f384261b1a9a (diff)
downloadskalibs-00a4c6056dba93c98cac687f24d5122acc76ded0.tar.xz
Add unixmessage_unput, for transaction cancellation
Diffstat (limited to 'src/libunixonacid/unixmessage_unput.c')
-rw-r--r--src/libunixonacid/unixmessage_unput.c23
1 files changed, 23 insertions, 0 deletions
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 <skalibs/genalloc.h>
+#include <skalibs/diuint.h>
+#include <skalibs/djbunix.h>
+#include <skalibs/unixmessage.h>
+
+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 ;
+}