summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/index.html2
-rw-r--r--doc/license.html2
-rw-r--r--doc/upgrade.html6
-rw-r--r--package/deps.mak4
-rw-r--r--package/info2
-rw-r--r--src/include/skalibs/unixmessage.h10
-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
10 files changed, 51 insertions, 15 deletions
diff --git a/doc/index.html b/doc/index.html
index 3606019..c9f4126 100644
--- 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.9.0.tar.gz">2.3.9.0</a>. </li>
+ <li> The current released version of skalibs is <a href="skalibs-2.3.10.0.tar.gz">2.3.10.0</a>. </li>
<li> Alternatively, you can checkout a copy of the skalibs git repository:
<pre> git clone git://git.skarnet.org/skalibs </pre> </li>
</ul>
diff --git a/doc/license.html b/doc/license.html
index 55522d4..149b0c3 100644
--- 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.9.0, I'm not going to enforce those restrictions, but if you're
+As of 2.3.10.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
index d67960f..e51e247 100644
--- a/doc/upgrade.html
+++ b/doc/upgrade.html
@@ -18,6 +18,12 @@
<h1> What has changed in skalibs </h1>
+<h2> in 2.3.10.0 </h2>
+
+<ul>
+ <li> Support for advanced fd callbacks in <tt>unixmessage_sender</tt>. </li>
+</ul>
+
<h2> in 2.3.9.0 </h2>
<ul>
diff --git a/package/deps.mak b/package/deps.mak
index afa6823..46225b1 100644
--- a/package/deps.mak
+++ b/package/deps.mak
@@ -792,10 +792,12 @@ src/libunixonacid/unixmessage_receiver_0.o src/libunixonacid/unixmessage_receive
src/libunixonacid/unixmessage_receiver_free.o src/libunixonacid/unixmessage_receiver_free.lo: src/libunixonacid/unixmessage_receiver_free.c src/include/skalibs/cbuffer.h src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/include/skalibs/unixmessage.h
src/libunixonacid/unixmessage_receiver_init.o src/libunixonacid/unixmessage_receiver_init.lo: src/libunixonacid/unixmessage_receiver_init.c src/include/skalibs/cbuffer.h src/include/skalibs/stralloc.h src/include/skalibs/unixmessage.h
src/libunixonacid/unixmessage_sender_1.o src/libunixonacid/unixmessage_sender_1.lo: src/libunixonacid/unixmessage_sender_1.c src/include/skalibs/unixmessage.h
+src/libunixonacid/unixmessage_sender_closecb.o src/libunixonacid/unixmessage_sender_closecb.lo: src/libunixonacid/unixmessage_sender_closecb.c src/include/skalibs/djbunix.h src/include/skalibs/unixmessage.h
src/libunixonacid/unixmessage_sender_flush.o src/libunixonacid/unixmessage_sender_flush.lo: src/libunixonacid/unixmessage_sender_flush.c src/include/skalibs/allreadwrite.h src/include/skalibs/bytestr.h src/include/skalibs/diuint.h src/include/skalibs/djbunix.h src/include/skalibs/genalloc.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/include/skalibs/uint16.h src/include/skalibs/uint32.h src/include/skalibs/unixmessage.h
src/libunixonacid/unixmessage_sender_free.o src/libunixonacid/unixmessage_sender_free.lo: src/libunixonacid/unixmessage_sender_free.c src/include/skalibs/diuint.h src/include/skalibs/djbunix.h src/include/skalibs/genalloc.h src/include/skalibs/stralloc.h src/include/skalibs/sysdeps.h src/include/skalibs/unixmessage.h
src/libunixonacid/unixmessage_sender_getfd.o src/libunixonacid/unixmessage_sender_getfd.lo: src/libunixonacid/unixmessage_sender_getfd.c src/include/skalibs/unixmessage.h
-src/libunixonacid/unixmessage_sender_init.o src/libunixonacid/unixmessage_sender_init.lo: src/libunixonacid/unixmessage_sender_init.c src/include/skalibs/genalloc.h src/include/skalibs/stralloc.h src/include/skalibs/unixmessage.h
+src/libunixonacid/unixmessage_sender_init.o src/libunixonacid/unixmessage_sender_init.lo: src/libunixonacid/unixmessage_sender_init.c src/include/skalibs/unixmessage.h
+src/libunixonacid/unixmessage_sender_init_withclosecb.o src/libunixonacid/unixmessage_sender_init_withclosecb.lo: src/libunixonacid/unixmessage_sender_init_withclosecb.c src/include/skalibs/genalloc.h src/include/skalibs/stralloc.h src/include/skalibs/unixmessage.h
src/libunixonacid/unixmessage_sender_timed_flush.o src/libunixonacid/unixmessage_sender_timed_flush.lo: src/libunixonacid/unixmessage_sender_timed_flush.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_sender_x.o src/libunixonacid/unixmessage_sender_x.lo: src/libunixonacid/unixmessage_sender_x.c src/include/skalibs/unixmessage.h
src/libunixonacid/unixmessage_sender_zero.o src/libunixonacid/unixmessage_sender_zero.lo: src/libunixonacid/unixmessage_sender_zero.c src/include/skalibs/unixmessage.h
diff --git a/package/info b/package/info
index ef65fdc..3165fcf 100644
--- a/package/info
+++ b/package/info
@@ -1,4 +1,4 @@
package=skalibs
-version=2.3.9.0
+version=2.3.10.0
category=prog
package_macro_name=SKALIBS
diff --git a/src/include/skalibs/unixmessage.h b/src/include/skalibs/unixmessage.h
index 51d48bc..f971a65 100644
--- a/src/include/skalibs/unixmessage.h
+++ b/src/include/skalibs/unixmessage.h
@@ -49,6 +49,9 @@ extern unixmessage_v_t const unixmessage_v_zero ;
/* Sender */
+typedef void unixmessage_sender_closecb_func_t (int, void *) ;
+typedef unixmessage_sender_closecb_func_t *unixmessage_sender_closecb_func_t_ref ;
+
typedef struct unixmessage_sender_s unixmessage_sender_t, *unixmessage_sender_t_ref ;
struct unixmessage_sender_s
{
@@ -58,12 +61,17 @@ struct unixmessage_sender_s
genalloc offsets ; /* diuint */
unsigned int head ;
unsigned int shorty ;
+ unixmessage_sender_closecb_func_t_ref closecb ;
+ void *closecbdata ;
} ;
#define UNIXMESSAGE_SENDER_ZERO UNIXMESSAGE_SENDER_INIT(-1)
-#define UNIXMESSAGE_SENDER_INIT(s) { .fd = (s), .data = STRALLOC_ZERO, .fds = GENALLOC_ZERO, .offsets = GENALLOC_ZERO, .head = 0, .shorty = 0 }
+#define UNIXMESSAGE_SENDER_INIT(s) UNIXMESSAGE_SENDER_INIT_WITHCLOSECB((s), &unixmessage_sender_closecb, 0)
+#define UNIXMESSAGE_SENDER_INIT_WITHCLOSECB(s, f, p) { .fd = (s), .data = STRALLOC_ZERO, .fds = GENALLOC_ZERO, .offsets = GENALLOC_ZERO, .head = 0, .shorty = 0, .closecb = (f), .closecbdata = (p) }
extern unixmessage_sender_t const unixmessage_sender_zero ;
+extern unixmessage_sender_closecb_func_t unixmessage_sender_closecb ;
extern void unixmessage_sender_init (unixmessage_sender_t *, int) ;
+extern void unixmessage_sender_init_withclosecb (unixmessage_sender_t *, int, unixmessage_sender_closecb_func_t_ref, void *) ;
extern void unixmessage_sender_free (unixmessage_sender_t *) ;
#define unixmessage_sender_fd(b) ((b)->fd)
extern int unixmessage_sender_getfd (unixmessage_sender_t const *) gccattr_pure ;
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 ;
+}