about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2020-11-20 15:22:48 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2020-11-20 15:22:48 +0000
commitcc31550d01415181e70150ad3e9043d049b07a09 (patch)
tree8631f84ba6390798f72576552f2c1b869e64ff3b
parent155f489a29ecc7d7b9b66e435739e69f40653562 (diff)
downloadskalibs-cc31550d01415181e70150ad3e9043d049b07a09.tar.gz
skalibs-cc31550d01415181e70150ad3e9043d049b07a09.tar.xz
skalibs-cc31550d01415181e70150ad3e9043d049b07a09.zip
Add fd_shutdown()
-rw-r--r--doc/libstddjb/djbunix.html10
-rw-r--r--package/deps.mak3
-rw-r--r--src/include/skalibs/djbunix.h1
-rw-r--r--src/libstddjb/fd_shutdown.c14
4 files changed, 27 insertions, 1 deletions
diff --git a/doc/libstddjb/djbunix.html b/doc/libstddjb/djbunix.html
index 9a921de..e70fe4f 100644
--- a/doc/libstddjb/djbunix.html
+++ b/doc/libstddjb/djbunix.html
@@ -192,6 +192,16 @@ Returns 1 if it succeeds and 0 if it fails.
 </p>
 
 <p>
+<code> void fd_shutdown (int fd, int w) </code> <br />
+Shuts down socket <em>fd</em>, for reading if <em>w</em> is zero,
+and for writing otherwise. Does not return an error code; does
+not modify errno. This is just a call to
+<a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/shutdown.html">shutdown()</a>
+with errno saved, used essentially to isolate application code from
+<tt>sys/socket.h</tt> which is a portability nightmare.
+</p>
+
+<p>
 <code> int lock_ex (int fd) </code> <br />
 Gets an exclusive advisory lock on <em>fd</em>. <em>fd</em> must point to
 a regular file, open for writing. Blocks until the lock can be obtained.
diff --git a/package/deps.mak b/package/deps.mak
index 1f503d8..17be060 100644
--- a/package/deps.mak
+++ b/package/deps.mak
@@ -333,6 +333,7 @@ src/libstddjb/fd_read.o src/libstddjb/fd_read.lo: src/libstddjb/fd_read.c src/in
 src/libstddjb/fd_readv.o src/libstddjb/fd_readv.lo: src/libstddjb/fd_readv.c src/include/skalibs/allreadwrite.h
 src/libstddjb/fd_recv.o src/libstddjb/fd_recv.lo: src/libstddjb/fd_recv.c src/include/skalibs/allreadwrite.h
 src/libstddjb/fd_send.o src/libstddjb/fd_send.lo: src/libstddjb/fd_send.c src/include/skalibs/allreadwrite.h
+src/libstddjb/fd_shutdown.o src/libstddjb/fd_shutdown.lo: src/libstddjb/fd_shutdown.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h
 src/libstddjb/fd_sync.o src/libstddjb/fd_sync.lo: src/libstddjb/fd_sync.c src/include/skalibs/djbunix.h
 src/libstddjb/fd_write.o src/libstddjb/fd_write.lo: src/libstddjb/fd_write.c src/include/skalibs/allreadwrite.h
 src/libstddjb/fd_writev.o src/libstddjb/fd_writev.lo: src/libstddjb/fd_writev.c src/include/skalibs/allreadwrite.h
@@ -401,7 +402,7 @@ src/libstddjb/ip6_scanlist.o src/libstddjb/ip6_scanlist.lo: src/libstddjb/ip6_sc
 src/libstddjb/ipc_accept.o src/libstddjb/ipc_accept.lo: src/libstddjb/ipc_accept.c src/include/skalibs/bytestr.h src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/include/skalibs/webipc.h
 src/libstddjb/ipc_bind.o src/libstddjb/ipc_bind.lo: src/libstddjb/ipc_bind.c src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/webipc.h
 src/libstddjb/ipc_bind_reuse.o src/libstddjb/ipc_bind_reuse.lo: src/libstddjb/ipc_bind_reuse.c src/include/skalibs/webipc.h
-src/libstddjb/ipc_bind_reuse_lock.o src/libstddjb/ipc_bind_reuse_lock.lo: src/libstddjb/ipc_bind_reuse_lock.c src/include/skalibs/nonposix.h src/include/skalibs/webipc.h
+src/libstddjb/ipc_bind_reuse_lock.o src/libstddjb/ipc_bind_reuse_lock.lo: src/libstddjb/ipc_bind_reuse_lock.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/webipc.h
 src/libstddjb/ipc_connect.o src/libstddjb/ipc_connect.lo: src/libstddjb/ipc_connect.c src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/webipc.h
 src/libstddjb/ipc_connected.o src/libstddjb/ipc_connected.lo: src/libstddjb/ipc_connected.c src/include/skalibs/allreadwrite.h src/include/skalibs/nonposix.h src/include/skalibs/webipc.h
 src/libstddjb/ipc_dgram.o src/libstddjb/ipc_dgram.lo: src/libstddjb/ipc_dgram.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/webipc.h
diff --git a/src/include/skalibs/djbunix.h b/src/include/skalibs/djbunix.h
index 3c52f6a..03cc1af 100644
--- a/src/include/skalibs/djbunix.h
+++ b/src/include/skalibs/djbunix.h
@@ -34,6 +34,7 @@ extern int fd_cat (int, int) ;
 extern size_t fd_catn (int, int, size_t) ;
 extern int fd_ensure_open (int, int) ;
 #define fd_sanitize() (fd_ensure_open(0, 0) && fd_ensure_open(1, 1) && fd_ensure_open(2, 1))
+extern void fd_shutdown (int, int) ;
 extern int lock_ex (int) ;
 extern int lock_exnb (int) ;
 extern int lock_sh (int) ;
diff --git a/src/libstddjb/fd_shutdown.c b/src/libstddjb/fd_shutdown.c
new file mode 100644
index 0000000..52e00c7
--- /dev/null
+++ b/src/libstddjb/fd_shutdown.c
@@ -0,0 +1,14 @@
+/* ISC license. */
+
+#include <skalibs/nonposix.h>
+#include <errno.h>
+#include <sys/socket.h>
+
+#include <skalibs/djbunix.h>
+
+void fd_shutdown (int fd, int h)
+{
+  int e = errno ;
+  shutdown(fd, h ? SHUT_WR : SHUT_RD) ;
+  errno = e ;
+}