summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/skalibs/skamisc.h2
-rw-r--r--src/include/skalibs/unix-timed.h3
-rw-r--r--src/libstddjb/skagetln_loose.c15
-rw-r--r--src/libstddjb/skagetlnsep_loose.c15
-rw-r--r--src/libunixonacid/ipc_timed_send.c1
-rw-r--r--src/libunixonacid/ipc_timed_sendv.c43
6 files changed, 79 insertions, 0 deletions
diff --git a/src/include/skalibs/skamisc.h b/src/include/skalibs/skamisc.h
index 15f7f02..7e8ab3d 100644
--- a/src/include/skalibs/skamisc.h
+++ b/src/include/skalibs/skamisc.h
@@ -10,8 +10,10 @@
extern stralloc satmp ;
extern int skagetln (buffer *, stralloc *, char) ;
+extern int skagetln_loose (buffer *, stralloc *, char) ;
extern int skagetln_nofill (buffer *, stralloc *, char) ;
extern int skagetlnsep (buffer *, stralloc *, char const *, size_t) ;
+extern int skagetlnsep_loose (buffer *, stralloc *, char const *, size_t) ;
extern int skagetlnmaxsep (buffer *, stralloc *, size_t, char const *, size_t) ;
extern int getlnmax (buffer *, char *, size_t, size_t *, char) ;
extern int getlnmaxsep (buffer *, char *, size_t, size_t *, char const *, size_t) ;
diff --git a/src/include/skalibs/unix-timed.h b/src/include/skalibs/unix-timed.h
index 84b5465..86563d2 100644
--- a/src/include/skalibs/unix-timed.h
+++ b/src/include/skalibs/unix-timed.h
@@ -4,6 +4,7 @@
#define UNIX_TIMED_H
#include <sys/types.h>
+#include <sys/uio.h>
#include <skalibs/bufalloc.h>
#include <skalibs/buffer.h>
#include <skalibs/functypes.h>
@@ -36,6 +37,8 @@ extern int netstring_timed_get (buffer *, stralloc *, tain_t const *, tain_t *)
extern int ipc_timed_send (int, char const *, size_t, tain_t const *, tain_t *) ;
#define ipc_timed_send_g(fd, s, len, deadline) ipc_timed_send(fd, s, len, (deadline), &STAMP)
+extern int ipc_timed_sendv (int, struct iovec const *, unsigned int, tain_t const *, tain_t *) ;
+#define ipc_timed_sendv_g(fd, v, n, deadline) ipc_timed_sendv(fd, v, n, (deadline), &STAMP)
extern ssize_t ipc_timed_recv (int, char *, size_t, char *, tain_t const *, tain_t *) ;
#define ipc_timed_recv_g(fd, s, len, path, deadline) ipc_timed_recv(fd, s, len, path, (deadline), &STAMP)
diff --git a/src/libstddjb/skagetln_loose.c b/src/libstddjb/skagetln_loose.c
new file mode 100644
index 0000000..7fc5916
--- /dev/null
+++ b/src/libstddjb/skagetln_loose.c
@@ -0,0 +1,15 @@
+/* ISC license. */
+
+#include <errno.h>
+#include <skalibs/stralloc.h>
+#include <skalibs/skamisc.h>
+
+int skagetln_loose (buffer *b, stralloc *sa, char sep)
+{
+ int e = errno ;
+ int r = skagetln(b, sa, sep) ;
+ if (r >= 0) return r ;
+ if (errno != EPIPE) return -1 ;
+ if (!stralloc_0(sa)) return -1 ;
+ return (errno = e, 3) ;
+}
diff --git a/src/libstddjb/skagetlnsep_loose.c b/src/libstddjb/skagetlnsep_loose.c
new file mode 100644
index 0000000..ad0fd0a
--- /dev/null
+++ b/src/libstddjb/skagetlnsep_loose.c
@@ -0,0 +1,15 @@
+/* ISC license. */
+
+#include <errno.h>
+#include <skalibs/stralloc.h>
+#include <skalibs/skamisc.h>
+
+int skagetlnsep_loose (buffer *b, stralloc *sa, char const *sep, size_t seplen)
+{
+ int e = errno ;
+ int r = skagetlnsep(b, sa, sep, seplen) ;
+ if (r >= 0) return r ;
+ if (errno != EPIPE) return -1 ;
+ if (!stralloc_0(sa)) return -1 ;
+ return (errno = e, 3) ;
+}
diff --git a/src/libunixonacid/ipc_timed_send.c b/src/libunixonacid/ipc_timed_send.c
index 13f8501..eeae453 100644
--- a/src/libunixonacid/ipc_timed_send.c
+++ b/src/libunixonacid/ipc_timed_send.c
@@ -1,5 +1,6 @@
/* ISC license. */
+#include <skalibs/nonposix.h>
#include <sys/socket.h>
#include <errno.h>
#include <skalibs/error.h>
diff --git a/src/libunixonacid/ipc_timed_sendv.c b/src/libunixonacid/ipc_timed_sendv.c
new file mode 100644
index 0000000..220b2e3
--- /dev/null
+++ b/src/libunixonacid/ipc_timed_sendv.c
@@ -0,0 +1,43 @@
+/* ISC license. */
+
+#include <skalibs/nonposix.h>
+#include <sys/socket.h>
+#include <errno.h>
+#include <skalibs/error.h>
+#include <skalibs/iopause.h>
+#include <skalibs/siovec.h>
+#include <skalibs/unix-timed.h>
+
+ /* For MacOS, that still doesn't know what POSIX says */
+#ifndef MSG_NOSIGNAL
+#define MSG_NOSIGNAL 0
+#endif
+
+int ipc_timed_sendv (int fd, struct iovec const *v, unsigned int n, tain_t const *deadline, tain_t *stamp)
+{
+ struct msghdr hdr =
+ {
+ .msg_name = 0,
+ .msg_namelen = 0,
+ .msg_iov = (struct iovec *)v,
+ .msg_iovlen = n,
+ .msg_control = 0,
+ .msg_controllen = 0,
+ .msg_flags = 0
+ } ;
+ size_t len = siovec_len(v, n) ;
+ iopause_fd x = { .fd = fd, .events = IOPAUSE_WRITE, .revents = 0 } ;
+ for (;;)
+ {
+ int r = iopause_stamp(&x, 1, deadline, stamp) ;
+ if (r < 0) return 0 ;
+ else if (!r) return (errno = ETIMEDOUT, 0) ;
+ else if (x.revents & IOPAUSE_WRITE)
+ {
+ if (sendmsg(fd, &hdr, MSG_NOSIGNAL) == (ssize_t)len) break ;
+ if (!error_isagain(errno)) return 0 ;
+ }
+ else if (x.revents & IOPAUSE_EXCEPT) return (sendmsg(fd, &hdr, MSG_NOSIGNAL) == (ssize_t)len) ;
+ }
+ return 1 ;
+}