From cc31550d01415181e70150ad3e9043d049b07a09 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 20 Nov 2020 15:22:48 +0000 Subject: Add fd_shutdown() --- doc/libstddjb/djbunix.html | 10 ++++++++++ package/deps.mak | 3 ++- src/include/skalibs/djbunix.h | 1 + src/libstddjb/fd_shutdown.c | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/libstddjb/fd_shutdown.c 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 @@ -191,6 +191,16 @@ file descriptors was closed, it now points to /dev/null. Returns 1 if it succeeds and 0 if it fails.

+

+ void fd_shutdown (int fd, int w)
+Shuts down socket fd, for reading if w is zero, +and for writing otherwise. Does not return an error code; does +not modify errno. This is just a call to +shutdown() +with errno saved, used essentially to isolate application code from +sys/socket.h which is a portability nightmare. +

+

int lock_ex (int fd)
Gets an exclusive advisory lock on fd. fd must point to 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 +#include +#include + +#include + +void fd_shutdown (int fd, int h) +{ + int e = errno ; + shutdown(fd, h ? SHUT_WR : SHUT_RD) ; + errno = e ; +} -- cgit v1.2.3