summaryrefslogtreecommitdiff
path: root/src/libunixonacid
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2016-02-02 23:33:34 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2016-02-02 23:33:34 +0000
commitc2e99ad0fbca5f669c76f188cff7e74681a3e683 (patch)
treeb2384eba2d369f199a7e54977f1fc2618961c88a /src/libunixonacid
parent6129e14bc76488f121c4557eb477886dd9dd2926 (diff)
downloadskalibs-c2e99ad0fbca5f669c76f188cff7e74681a3e683.tar.xz
Tentative re-commit of the closecb feature
Diffstat (limited to 'src/libunixonacid')
-rw-r--r--src/libunixonacid/unixmessage_sender_closecb.c10
-rw-r--r--src/libunixonacid/unixmessage_sender_flush.c4
-rw-r--r--src/libunixonacid/unixmessage_sender_init.c9
-rw-r--r--src/libunixonacid/unixmessage_sender_init_withclosecb.c17
4 files changed, 30 insertions, 10 deletions
diff --git a/src/libunixonacid/unixmessage_sender_closecb.c b/src/libunixonacid/unixmessage_sender_closecb.c
new file mode 100644
index 0000000..1234ff5
--- /dev/null
+++ b/src/libunixonacid/unixmessage_sender_closecb.c
@@ -0,0 +1,10 @@
+/* ISC license. */
+
+#include <skalibs/djbunix.h>
+#include <skalibs/unixmessage.h>
+
+void unixmessage_sender_closecb (int fd, void *p)
+{
+ fd_close(fd) ;
+ (void)p ;
+}
diff --git a/src/libunixonacid/unixmessage_sender_flush.c b/src/libunixonacid/unixmessage_sender_flush.c
index 75412fb..6559083 100644
--- a/src/libunixonacid/unixmessage_sender_flush.c
+++ b/src/libunixonacid/unixmessage_sender_flush.c
@@ -97,13 +97,13 @@ int unixmessage_sender_flush (unixmessage_sender_t *b)
while (r < 0 && errno == EINTR) ;
if (r <= 0) return 0 ;
#ifndef SKALIBS_HASANCILAUTOCLOSE
- if (nfds)
+ if (nfds && b->closecb)
{
register unsigned int i = 0 ;
for (; i < nfds ; i++)
{
register int fd = genalloc_s(int, &b->fds)[offsets[b->head].right + i] ;
- if (fd < 0) fd_close(-(fd+1)) ;
+ if (fd < 0) (*b->closecb)(-(fd+1), b->closecbdata) ;
}
}
#endif
diff --git a/src/libunixonacid/unixmessage_sender_init.c b/src/libunixonacid/unixmessage_sender_init.c
index d986f29..71a8b3b 100644
--- a/src/libunixonacid/unixmessage_sender_init.c
+++ b/src/libunixonacid/unixmessage_sender_init.c
@@ -1,15 +1,8 @@
/* ISC license. */
-#include <skalibs/stralloc.h>
-#include <skalibs/genalloc.h>
#include <skalibs/unixmessage.h>
void unixmessage_sender_init (unixmessage_sender_t *b, int fd)
{
- b->fd = fd ;
- b->data = stralloc_zero ;
- b->fds = genalloc_zero ;
- b->offsets = genalloc_zero ;
- b->head = 0 ;
- b->shorty = 0 ;
+ unixmessage_sender_init_withclosecb(b, fd, &unixmessage_sender_closecb, 0) ;
}
diff --git a/src/libunixonacid/unixmessage_sender_init_withclosecb.c b/src/libunixonacid/unixmessage_sender_init_withclosecb.c
new file mode 100644
index 0000000..7d82a8e
--- /dev/null
+++ b/src/libunixonacid/unixmessage_sender_init_withclosecb.c
@@ -0,0 +1,17 @@
+/* ISC license. */
+
+#include <skalibs/stralloc.h>
+#include <skalibs/genalloc.h>
+#include <skalibs/unixmessage.h>
+
+void unixmessage_sender_init_withclosecb (unixmessage_sender_t *b, int fd, unixmessage_sender_closecb_func_t_ref f, void *p)
+{
+ b->fd = fd ;
+ b->data = stralloc_zero ;
+ b->fds = genalloc_zero ;
+ b->offsets = genalloc_zero ;
+ b->head = 0 ;
+ b->shorty = 0 ;
+ b->closecb = f ;
+ b->closecbdata = p ;
+}