commit f6d5fcfa0fa2a62f9583fa44dbee035c0adfcc88
parent e9fce4390ad8673239a51facd6bbd9ffb5eb7e68
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date: Fri, 22 Apr 2016 11:54:31 +0000
Fix closecb support wherever a unixmessage may get dropped; add closecb support to unixconnection
Diffstat:
13 files changed, 36 insertions(+), 19 deletions(-)
diff --git a/doc/index.html b/doc/index.html
@@ -60,7 +60,7 @@ with a standard C development environment </li>
<h3> Download </h3>
<ul>
- <li> The current released version of skalibs is <a href="skalibs-2.3.10.0.tar.gz">2.3.10.0</a>. </li>
+ <li> The current released version of skalibs is <a href="skalibs-2.3.11.0.tar.gz">2.3.11.0</a>. </li>
<li> Alternatively, you can checkout a copy of the
<a href="http://git.skarnet.org/cgi-bin/cgit.cgi/skalibs/">skalibs
"git repository</a>:
diff --git a/doc/license.html b/doc/license.html
@@ -74,7 +74,7 @@ color, or different text font. </li>
<p>
<em>I am aware that the previous restrictions sound completely
ridiculous while the official skalibs documentation is incomplete.
-As of 2.3.10.0, I'm not going to enforce those restrictions, but if you're
+As of 2.3.11.0, I'm not going to enforce those restrictions, but if you're
going to provide documentation for skalibs, don't keep it to yourself,
please send it to me instead. :-) </em>
</p>
diff --git a/doc/upgrade.html b/doc/upgrade.html
@@ -18,6 +18,12 @@
<h1> What has changed in skalibs </h1>
+<h2> in 2.3.11.0 </h2>
+
+<ul>
+ <li> More support for advanced fd callbacks in <tt>unixmessage_sender</tt> and <tt>unixconnection</tt>. </li>
+</ul>
+
<h2> in 2.3.10.0 </h2>
<ul>
diff --git a/package/deps.mak b/package/deps.mak
@@ -123,7 +123,7 @@ src/libdatastruct/avltreen_init.o src/libdatastruct/avltreen_init.lo: src/libdat
src/libdatastruct/avltreen_insert.o src/libdatastruct/avltreen_insert.lo: src/libdatastruct/avltreen_insert.c src/include/skalibs/avltreen.h
src/libdatastruct/avltreen_newnode.o src/libdatastruct/avltreen_newnode.lo: src/libdatastruct/avltreen_newnode.c src/include/skalibs/avlnode.h src/include/skalibs/avltreen.h src/include/skalibs/genset.h
src/libdatastruct/genset.o src/libdatastruct/genset.lo: src/libdatastruct/genset.c src/include/skalibs/genset.h
-src/libdatastruct/genset_iter.o src/libdatastruct/genset_iter.lo: src/libdatastruct/genset_iter.c src/include/skalibs/bitarray.h src/include/skalibs/functypes.h src/include/skalibs/genset.h
+src/libdatastruct/genset_iter_nocancel.o src/libdatastruct/genset_iter_nocancel.lo: src/libdatastruct/genset_iter_nocancel.c src/include/skalibs/bitarray.h src/include/skalibs/functypes.h src/include/skalibs/genset.h
src/libdatastruct/genset_iter_withcancel.o src/libdatastruct/genset_iter_withcancel.lo: src/libdatastruct/genset_iter_withcancel.c src/include/skalibs/functypes.h src/include/skalibs/genset.h
src/libdatastruct/gensetdyn_delete.o src/libdatastruct/gensetdyn_delete.lo: src/libdatastruct/gensetdyn_delete.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h
src/libdatastruct/gensetdyn_free.o src/libdatastruct/gensetdyn_free.lo: src/libdatastruct/gensetdyn_free.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/include/skalibs/stralloc.h
@@ -781,6 +781,7 @@ src/libunixonacid/timed_getln.o src/libunixonacid/timed_getln.lo: src/libunixona
src/libunixonacid/timed_getlnmax.o src/libunixonacid/timed_getlnmax.lo: src/libunixonacid/timed_getlnmax.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/functypes.h src/include/skalibs/skamisc.h src/include/skalibs/tai.h src/include/skalibs/unix-timed.h
src/libunixonacid/unixconnection_free.o src/libunixonacid/unixconnection_free.lo: src/libunixonacid/unixconnection_free.c src/include/skalibs/unixconnection.h src/include/skalibs/unixmessage.h
src/libunixonacid/unixconnection_init.o src/libunixonacid/unixconnection_init.lo: src/libunixonacid/unixconnection_init.c src/include/skalibs/unixconnection.h src/include/skalibs/unixmessage.h
+src/libunixonacid/unixconnection_init_withclosecb.o src/libunixonacid/unixconnection_init_withclosecb.lo: src/libunixonacid/unixconnection_init_withclosecb.c src/include/skalibs/unixconnection.h src/include/skalibs/unixmessage.h
src/libunixonacid/unixconnection_zero.o src/libunixonacid/unixconnection_zero.lo: src/libunixonacid/unixconnection_zero.c src/include/skalibs/unixconnection.h
src/libunixonacid/unixmessage_bits_closeall.o src/libunixonacid/unixmessage_bits_closeall.lo: src/libunixonacid/unixmessage_bits_closeall.c src/include/skalibs/bitarray.h src/include/skalibs/unixmessage.h
src/libunixonacid/unixmessage_bits_closenone.o src/libunixonacid/unixmessage_bits_closenone.lo: src/libunixonacid/unixmessage_bits_closenone.c src/include/skalibs/bitarray.h src/include/skalibs/unixmessage.h
diff --git a/package/info b/package/info
@@ -1,4 +1,4 @@
package=skalibs
-version=2.3.10.0
+version=2.3.11.0
category=prog
package_macro_name=SKALIBS
diff --git a/src/include/skalibs/unixconnection.h b/src/include/skalibs/unixconnection.h
@@ -17,6 +17,7 @@ struct unixconnection_s
extern unixconnection_t const unixconnection_zero ;
extern void unixconnection_init (unixconnection_t *, int, int) ;
+extern void unixconnection_init_withclosecb (unixconnection_t *, int, int, unixmessage_sender_closecb_func_t_ref, void *) ;
extern void unixconnection_free (unixconnection_t *) ;
#define unixconnection_flush(io) unixmessage_sender_flush(&(io)->out)
diff --git a/src/libdatastruct/genset_iter.c b/src/libdatastruct/genset_iter_nocancel.c
diff --git a/src/libunixonacid/unixconnection_init.c b/src/libunixonacid/unixconnection_init.c
@@ -5,6 +5,5 @@
void unixconnection_init (unixconnection_t *io, int fdin, int fdout)
{
- unixmessage_receiver_init(&io->in, fdin, io->mainbuf, UNIXMESSAGE_BUFSIZE, io->auxbuf, UNIXMESSAGE_AUXBUFSIZE) ;
- unixmessage_sender_init(&io->out, fdout) ;
+ unixconnection_init_withclosecb(io, fdin, fdout, &unixmessage_sender_closecb, 0) ;
}
diff --git a/src/libunixonacid/unixconnection_init_withclosecb.c b/src/libunixonacid/unixconnection_init_withclosecb.c
@@ -0,0 +1,10 @@
+ /* ISC license. */
+
+#include <skalibs/unixmessage.h>
+#include <skalibs/unixconnection.h>
+
+void unixconnection_init_withclosecb (unixconnection_t *io, int fdin, int fdout, unixmessage_sender_closecb_func_t_ref f, void *p)
+{
+ unixmessage_receiver_init(&io->in, fdin, io->mainbuf, UNIXMESSAGE_BUFSIZE, io->auxbuf, UNIXMESSAGE_AUXBUFSIZE) ;
+ unixmessage_sender_init_withclosecb(&io->out, fdout, f, p) ;
+}
diff --git a/src/libunixonacid/unixmessage_put.c b/src/libunixonacid/unixmessage_put.c
@@ -14,7 +14,7 @@
#include <skalibs/siovec.h>
#include <skalibs/unixmessage.h>
-static inline int copyfds (char *s, int const *fds, unsigned int n, unsigned char const *bits)
+static inline int copyfds (char *s, int const *fds, unsigned int n, unsigned char const *bits, unixmessage_sender_closecb_func_t_ref closecb, void *closecbdata)
{
register unsigned int i = 0 ;
for (; i < n ; i++)
@@ -33,13 +33,12 @@ static inline int copyfds (char *s, int const *fds, unsigned int n, unsigned cha
{
s -= sizeof(int) ;
byte_copy((char *)fd, sizeof(int), s) ;
- if (fd >= 0) fd_close(fd) ;
+ if (fd >= 0) (*closecb)(fd, closecbdata) ;
}
errno = e ;
return 0 ;
}
}
-#else
#endif
byte_copy(s, sizeof(int), (char const *)&fd) ;
s += sizeof(int) ;
@@ -56,7 +55,7 @@ static int reserve_and_copy (unixmessage_sender_t *b, unsigned int len, int cons
|| !genalloc_readyplus(int, &b->fds, nfds)
|| !stralloc_readyplus(&b->data, len))
return 0 ;
- if (!copyfds(b->fds.s + b->fds.len, fds, nfds, bits)) return 0 ;
+ if (!copyfds(b->fds.s + b->fds.len, fds, nfds, bits, b->closecb, b->closecbdata)) return 0 ;
genalloc_setlen(int, &b->fds, cur.right + nfds) ;
byte_copy(b->offsets.s + b->offsets.len, sizeof(diuint), (char const *)&cur) ;
b->offsets.len += sizeof(diuint) ;
diff --git a/src/libunixonacid/unixmessage_sender_flush.c b/src/libunixonacid/unixmessage_sender_flush.c
@@ -97,7 +97,7 @@ int unixmessage_sender_flush (unixmessage_sender_t *b)
while (r < 0 && errno == EINTR) ;
if (r <= 0) return 0 ;
#ifndef SKALIBS_HASANCILAUTOCLOSE
- if (nfds && b->closecb)
+ if (nfds)
{
register unsigned int i = 0 ;
for (; i < nfds ; i++)
diff --git a/src/libunixonacid/unixmessage_sender_free.c b/src/libunixonacid/unixmessage_sender_free.c
@@ -16,9 +16,9 @@ void unixmessage_sender_free (unixmessage_sender_t *b)
for (; i < n ; i++)
{
register int fd = genalloc_s(int, &b->fds)[i] ;
- if (fd < 0) fd_close(-(fd+1)) ;
+ if (fd < 0) (*b->closecb)(-(fd+1), b->closecbdata) ;
#ifdef SKALIBS_HASANCILAUTOCLOSE
- else fd_close(fd) ;
+ else (*b->closecb)(fd, b->closecbdata) ;
#endif
}
}
diff --git a/src/libunixonacid/unixmessage_unput.c b/src/libunixonacid/unixmessage_unput.c
@@ -9,14 +9,15 @@ int unixmessage_unput_and_maybe_drop (unixmessage_sender_t *b, int drop)
{
diuint *start ;
unsigned int n = genalloc_len(diuint, &b->offsets) ;
+ register int *fds ;
+ register unsigned int i ;
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]) ;
- }
+ fds = genalloc_s(int, &b->fds) + start->right ;
+ i = genalloc_len(int, &b->fds) - start->right ;
+ while (i--)
+ if (fds[i] < 0) (*b->closecb)(-(fds[i]+1), b->closecbdata) ;
+ else if (drop) fd_close(fds[i]) ;
b->data.len = start->left ;
genalloc_setlen(int, &b->fds, start->right) ;
genalloc_setlen(diuint, &b->offsets, n-1) ;