diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2020-12-09 17:16:40 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2020-12-09 17:16:40 +0000 |
commit | e557bab0dcaf35f003fa755b74e4c80000e05e42 (patch) | |
tree | 3bc4d8aeb04117b324f1b9b182c923e259a657c7 /src/libstddjb | |
parent | 86312d159d55e99db5a5c82d9c50f31a1fe28199 (diff) | |
download | skalibs-e557bab0dcaf35f003fa755b74e4c80000e05e42.tar.xz |
Get rid of webipc.h and DJBUNIX_FLAG_*
Decent semantic header separation is hard. It's always
an ongoing process. Here socket.h always included webipc.h
for listen(), and webipc.h always included djbunix.h for
socket_internal() and socketpair_internal(). That's ugh.
Just move all the socket stuff into one socket header.
Of course, djbunix.h is still needed most of the time for
fd_close() and other operations on fds, but those are
generic anyway.
Also, O_CLOEXEC exists everywhere now, so we can use it as well
as O_NONBLOCK instead of redefining the flags in djbunix.h.
Diffstat (limited to 'src/libstddjb')
-rw-r--r-- | src/libstddjb/child_spawn1_socket.c | 2 | ||||
-rw-r--r-- | src/libstddjb/ipc_accept.c | 10 | ||||
-rw-r--r-- | src/libstddjb/ipc_bind.c | 3 | ||||
-rw-r--r-- | src/libstddjb/ipc_bind_reuse.c | 2 | ||||
-rw-r--r-- | src/libstddjb/ipc_bind_reuse_lock.c | 6 | ||||
-rw-r--r-- | src/libstddjb/ipc_connect.c | 3 | ||||
-rw-r--r-- | src/libstddjb/ipc_connected.c | 3 | ||||
-rw-r--r-- | src/libstddjb/ipc_dgram.c | 3 | ||||
-rw-r--r-- | src/libstddjb/ipc_listen.c | 2 | ||||
-rw-r--r-- | src/libstddjb/ipc_local.c | 3 | ||||
-rw-r--r-- | src/libstddjb/ipc_pair.c | 3 | ||||
-rw-r--r-- | src/libstddjb/ipc_recv.c | 5 | ||||
-rw-r--r-- | src/libstddjb/ipc_send.c | 3 | ||||
-rw-r--r-- | src/libstddjb/ipc_stream.c | 3 | ||||
-rw-r--r-- | src/libstddjb/ipc_timed_connect.c | 3 | ||||
-rw-r--r-- | src/libstddjb/pipe_internal.c | 10 | ||||
-rw-r--r-- | src/libstddjb/socket_accept4.c | 8 | ||||
-rw-r--r-- | src/libstddjb/socket_accept6.c | 8 | ||||
-rw-r--r-- | src/libstddjb/socket_internal.c | 9 | ||||
-rw-r--r-- | src/libstddjb/socket_tcp4.c | 1 | ||||
-rw-r--r-- | src/libstddjb/socketpair_internal.c | 9 |
21 files changed, 56 insertions, 43 deletions
diff --git a/src/libstddjb/child_spawn1_socket.c b/src/libstddjb/child_spawn1_socket.c index 7263ff6..0bb2da9 100644 --- a/src/libstddjb/child_spawn1_socket.c +++ b/src/libstddjb/child_spawn1_socket.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <skalibs/webipc.h> +#include <skalibs/socket.h> #include <skalibs/djbunix.h> #include "djbunix-internal.h" diff --git a/src/libstddjb/ipc_accept.c b/src/libstddjb/ipc_accept.c index b0b44c3..9d5d82c 100644 --- a/src/libstddjb/ipc_accept.c +++ b/src/libstddjb/ipc_accept.c @@ -6,9 +6,11 @@ #include <sys/un.h> #include <string.h> #include <errno.h> +#include <fcntl.h> + #include <skalibs/bytestr.h> #include <skalibs/djbunix.h> -#include <skalibs/webipc.h> +#include <skalibs/socket.h> int ipc_accept_internal (int s, char *p, size_t l, int *trunc, unsigned int options) { @@ -18,15 +20,15 @@ int ipc_accept_internal (int s, char *p, size_t l, int *trunc, unsigned int opti memset(&sa, 0, dummy) ; do #ifdef SKALIBS_HASACCEPT4 - fd = accept4(s, (struct sockaddr *)&sa, &dummy, ((options & DJBUNIX_FLAG_NB) ? SOCK_NONBLOCK : 0) | ((options & DJBUNIX_FLAG_COE) ? SOCK_CLOEXEC : 0)) ; + fd = accept4(s, (struct sockaddr *)&sa, &dummy, ((options & O_NONBLOCK) ? SOCK_NONBLOCK : 0) | ((options & O_CLOEXEC) ? SOCK_CLOEXEC : 0)) ; #else fd = accept(s, (struct sockaddr *)&sa, &dummy) ; #endif while ((fd == -1) && (errno == EINTR)) ; if (fd == -1) return -1 ; #ifndef SKALIBS_HASACCEPT4 - if ((((options & DJBUNIX_FLAG_NB) ? ndelay_on(fd) : ndelay_off(fd)) < 0) - || (((options & DJBUNIX_FLAG_COE) ? coe(fd) : uncoe(fd)) < 0)) + if ((((options & O_NONBLOCK) ? ndelay_on(fd) : ndelay_off(fd)) < 0) + || (((options & O_CLOEXEC) ? coe(fd) : uncoe(fd)) < 0)) { fd_close(fd) ; return -1 ; diff --git a/src/libstddjb/ipc_bind.c b/src/libstddjb/ipc_bind.c index d40a7ef..c26fb1d 100644 --- a/src/libstddjb/ipc_bind.c +++ b/src/libstddjb/ipc_bind.c @@ -1,13 +1,12 @@ /* ISC license. */ #include <skalibs/nonposix.h> - #include <sys/socket.h> #include <sys/un.h> #include <string.h> #include <errno.h> -#include <skalibs/webipc.h> +#include <skalibs/socket.h> #include <skalibs/posixishard.h> int ipc_bind (int s, char const *p) diff --git a/src/libstddjb/ipc_bind_reuse.c b/src/libstddjb/ipc_bind_reuse.c index ce5c7a4..193d10c 100644 --- a/src/libstddjb/ipc_bind_reuse.c +++ b/src/libstddjb/ipc_bind_reuse.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include <skalibs/webipc.h> +#include <skalibs/socket.h> int ipc_bind_reuse (int s, char const *p) { diff --git a/src/libstddjb/ipc_bind_reuse_lock.c b/src/libstddjb/ipc_bind_reuse_lock.c index b1bccfd..c872e44 100644 --- a/src/libstddjb/ipc_bind_reuse_lock.c +++ b/src/libstddjb/ipc_bind_reuse_lock.c @@ -8,7 +8,7 @@ #include <sys/socket.h> #include <skalibs/djbunix.h> -#include <skalibs/webipc.h> +#include <skalibs/socket.h> int ipc_bind_reuse_lock (int s, char const *p, int *fdlock) { @@ -24,8 +24,10 @@ int ipc_bind_reuse_lock (int s, char const *p, int *fdlock) r = fd_lock(fd, 1, 1) ; if (r < 0) return -1 ; if (!r) return (errno = EBUSY, -1) ; + r = errno ; setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof opt) ; - unlink(p) ; + errno = r ; + unlink_void(p) ; if (ipc_bind(s, p) < 0) return -1 ; *fdlock = fd ; return 0 ; diff --git a/src/libstddjb/ipc_connect.c b/src/libstddjb/ipc_connect.c index c00f683..7ccba09 100644 --- a/src/libstddjb/ipc_connect.c +++ b/src/libstddjb/ipc_connect.c @@ -1,13 +1,12 @@ /* ISC license. */ #include <skalibs/nonposix.h> - #include <errno.h> #include <sys/socket.h> #include <sys/un.h> #include <string.h> -#include <skalibs/webipc.h> +#include <skalibs/socket.h> #include <skalibs/posixishard.h> int ipc_connect (int s, char const *p) diff --git a/src/libstddjb/ipc_connected.c b/src/libstddjb/ipc_connected.c index a079fd5..310649b 100644 --- a/src/libstddjb/ipc_connected.c +++ b/src/libstddjb/ipc_connected.c @@ -3,8 +3,9 @@ #include <skalibs/nonposix.h> #include <sys/socket.h> #include <sys/un.h> + #include <skalibs/allreadwrite.h> -#include <skalibs/webipc.h> +#include <skalibs/socket.h> int ipc_connected (int s) { diff --git a/src/libstddjb/ipc_dgram.c b/src/libstddjb/ipc_dgram.c index ac61ee7..78ea032 100644 --- a/src/libstddjb/ipc_dgram.c +++ b/src/libstddjb/ipc_dgram.c @@ -2,8 +2,7 @@ #include <skalibs/nonposix.h> #include <sys/socket.h> -#include <skalibs/djbunix.h> -#include <skalibs/webipc.h> +#include <skalibs/socket.h> int ipc_datagram_internal (unsigned int flags) { diff --git a/src/libstddjb/ipc_listen.c b/src/libstddjb/ipc_listen.c index a96be58..141a2ea 100644 --- a/src/libstddjb/ipc_listen.c +++ b/src/libstddjb/ipc_listen.c @@ -2,7 +2,7 @@ #include <skalibs/nonposix.h> #include <sys/socket.h> -#include <skalibs/webipc.h> +#include <skalibs/socket.h> int ipc_listen (int s, int backlog) { diff --git a/src/libstddjb/ipc_local.c b/src/libstddjb/ipc_local.c index e617264..849d9ce 100644 --- a/src/libstddjb/ipc_local.c +++ b/src/libstddjb/ipc_local.c @@ -4,8 +4,9 @@ #include <sys/socket.h> #include <sys/un.h> #include <string.h> + #include <skalibs/bytestr.h> -#include <skalibs/webipc.h> +#include <skalibs/socket.h> int ipc_local (int s, char *p, size_t l, int *trunc) { diff --git a/src/libstddjb/ipc_pair.c b/src/libstddjb/ipc_pair.c index 6038d17..5400e63 100644 --- a/src/libstddjb/ipc_pair.c +++ b/src/libstddjb/ipc_pair.c @@ -2,8 +2,7 @@ #include <skalibs/nonposix.h> #include <sys/socket.h> -#include <skalibs/djbunix.h> -#include <skalibs/webipc.h> +#include <skalibs/socket.h> int ipc_pair_internal (int *sv, unsigned int flags) { diff --git a/src/libstddjb/ipc_recv.c b/src/libstddjb/ipc_recv.c index 4c235bb..407b3cc 100644 --- a/src/libstddjb/ipc_recv.c +++ b/src/libstddjb/ipc_recv.c @@ -1,13 +1,12 @@ /* ISC license. */ #include <skalibs/nonposix.h> - +#include <string.h> #include <errno.h> #include <sys/socket.h> #include <sys/un.h> -#include <string.h> -#include <skalibs/webipc.h> +#include <skalibs/socket.h> #include <skalibs/posixishard.h> ssize_t ipc_recv (int fd, char *s, size_t len, char *path) diff --git a/src/libstddjb/ipc_send.c b/src/libstddjb/ipc_send.c index 2615a16..b9cfe49 100644 --- a/src/libstddjb/ipc_send.c +++ b/src/libstddjb/ipc_send.c @@ -1,13 +1,12 @@ /* ISC license. */ #include <skalibs/nonposix.h> - #include <errno.h> #include <sys/socket.h> #include <sys/un.h> #include <string.h> -#include <skalibs/webipc.h> +#include <skalibs/socket.h> #include <skalibs/posixishard.h> ssize_t ipc_send (int fd, char const *s, size_t len, char const *path) diff --git a/src/libstddjb/ipc_stream.c b/src/libstddjb/ipc_stream.c index c2c6c1b..265236d 100644 --- a/src/libstddjb/ipc_stream.c +++ b/src/libstddjb/ipc_stream.c @@ -2,8 +2,7 @@ #include <skalibs/nonposix.h> #include <sys/socket.h> -#include <skalibs/djbunix.h> -#include <skalibs/webipc.h> +#include <skalibs/socket.h> int ipc_stream_internal (unsigned int flags) { diff --git a/src/libstddjb/ipc_timed_connect.c b/src/libstddjb/ipc_timed_connect.c index e08b32b..ff88018 100644 --- a/src/libstddjb/ipc_timed_connect.c +++ b/src/libstddjb/ipc_timed_connect.c @@ -1,9 +1,10 @@ /* ISC license. */ #include <errno.h> + #include <skalibs/error.h> #include <skalibs/iopause.h> -#include <skalibs/webipc.h> +#include <skalibs/socket.h> int ipc_timed_connect (int s, char const *path, tain_t const *deadline, tain_t *stamp) { diff --git a/src/libstddjb/pipe_internal.c b/src/libstddjb/pipe_internal.c index 598ab9c..dc7cfe6 100644 --- a/src/libstddjb/pipe_internal.c +++ b/src/libstddjb/pipe_internal.c @@ -6,26 +6,28 @@ #include <skalibs/nonposix.h> #include <unistd.h> -#include <fcntl.h> + #include <skalibs/djbunix.h> int pipe_internal (int *p, unsigned int flags) { - return pipe2(p, ((flags & DJBUNIX_FLAG_COE) ? O_CLOEXEC : 0) | ((flags & DJBUNIX_FLAG_NB) ? O_NONBLOCK : 0)) ; + return pipe2(p, flags) ; } #else #include <unistd.h> +#include <fcntl.h> + #include <skalibs/djbunix.h> int pipe_internal (int *p, unsigned int flags) { int pi[2] ; if (pipe(pi) < 0) return -1 ; - if (flags & DJBUNIX_FLAG_COE) + if (flags & O_CLOEXEC) if ((coe(pi[0]) < 0) || (coe(pi[1]) < 0)) goto err ; - if (flags & DJBUNIX_FLAG_NB) + if (flags & O_NONBLOCK) if ((ndelay_on(pi[0]) < 0) || (ndelay_on(pi[1]) < 0)) goto err ; p[0] = pi[0] ; p[1] = pi[1] ; return 0 ; diff --git a/src/libstddjb/socket_accept4.c b/src/libstddjb/socket_accept4.c index 40dff91..2016777 100644 --- a/src/libstddjb/socket_accept4.c +++ b/src/libstddjb/socket_accept4.c @@ -6,6 +6,8 @@ #include <netinet/in.h> #include <string.h> #include <errno.h> +#include <fcntl.h> + #include <skalibs/uint16.h> #include <skalibs/djbunix.h> #include <skalibs/socket.h> @@ -17,15 +19,15 @@ int socket_accept4_internal (int s, char *ip, uint16_t *port, unsigned int optio int fd ; do #ifdef SKALIBS_HASACCEPT4 - fd = accept4(s, (struct sockaddr *)&sa, &dummy, ((options & DJBUNIX_FLAG_NB) ? SOCK_NONBLOCK : 0) | ((options & DJBUNIX_FLAG_COE) ? SOCK_CLOEXEC : 0)) ; + fd = accept4(s, (struct sockaddr *)&sa, &dummy, ((options & O_NONBLOCK) ? SOCK_NONBLOCK : 0) | ((options & O_CLOEXEC) ? SOCK_CLOEXEC : 0)) ; #else fd = accept(s, (struct sockaddr *)&sa, &dummy) ; #endif while ((fd < 0) && (errno == EINTR)) ; if (fd < 0) return -1 ; #ifndef SKALIBS_HASACCEPT4 - if ((((options & DJBUNIX_FLAG_NB) ? ndelay_on(fd) : ndelay_off(fd)) < 0) - || (((options & DJBUNIX_FLAG_COE) ? coe(fd) : uncoe(fd)) < 0)) + if ((((options & O_NONBLOCK) ? ndelay_on(fd) : ndelay_off(fd)) < 0) + || (((options & O_CLOEXEC) ? coe(fd) : uncoe(fd)) < 0)) { fd_close(fd) ; return -1 ; diff --git a/src/libstddjb/socket_accept6.c b/src/libstddjb/socket_accept6.c index 5bd72b4..f5156ca 100644 --- a/src/libstddjb/socket_accept6.c +++ b/src/libstddjb/socket_accept6.c @@ -6,6 +6,8 @@ #include <netinet/in.h> #include <string.h> #include <errno.h> +#include <fcntl.h> + #include <skalibs/uint16.h> #include <skalibs/djbunix.h> #include <skalibs/ip46.h> @@ -20,15 +22,15 @@ int socket_accept6_internal (int s, char *ip6, uint16_t *port, unsigned int opti int fd ; do #ifdef SKALIBS_HASACCEPT4 - fd = accept4(s, (struct sockaddr *)&sa, &dummy, ((options & DJBUNIX_FLAG_NB) ? SOCK_NONBLOCK : 0) | ((options & DJBUNIX_FLAG_COE) ? SOCK_CLOEXEC : 0)) ; + fd = accept4(s, (struct sockaddr *)&sa, &dummy, ((options & O_NONBLOCK) ? SOCK_NONBLOCK : 0) | ((options & O_CLOEXEC) ? SOCK_CLOEXEC : 0)) ; #else fd = accept(s, (struct sockaddr *)&sa, &dummy) ; #endif while ((fd < 0) && (errno == EINTR)) ; if (fd < 0) return -1 ; #ifndef SKALIBS_HASACCEPT4 - if ((((options & DJBUNIX_FLAG_NB) ? ndelay_on(fd) : ndelay_off(fd)) < 0) - || (((options & DJBUNIX_FLAG_COE) ? coe(fd) : uncoe(fd)) < 0)) + if ((((options & O_NONBLOCK) ? ndelay_on(fd) : ndelay_off(fd)) < 0) + || (((options & O_CLOEXEC) ? coe(fd) : uncoe(fd)) < 0)) { fd_close(fd) ; return -1 ; diff --git a/src/libstddjb/socket_internal.c b/src/libstddjb/socket_internal.c index 848b156..852f323 100644 --- a/src/libstddjb/socket_internal.c +++ b/src/libstddjb/socket_internal.c @@ -3,13 +3,16 @@ #include <skalibs/sysdeps.h> #include <skalibs/nonposix.h> #include <sys/socket.h> +#include <fcntl.h> + #include <skalibs/djbunix.h> +#include <skalibs/socket.h> #ifdef SKALIBS_HASACCEPT4 int socket_internal (int domain, int type, int protocol, unsigned int flags) { - return socket(domain, type | ((flags & DJBUNIX_FLAG_NB) ? SOCK_NONBLOCK : 0) | ((flags & DJBUNIX_FLAG_COE) ? SOCK_CLOEXEC : 0), protocol) ; + return socket(domain, type | ((flags & O_NONBLOCK) ? SOCK_NONBLOCK : 0) | ((flags & O_CLOEXEC) ? SOCK_CLOEXEC : 0), protocol) ; } #else @@ -18,8 +21,8 @@ int socket_internal (int domain, int type, int protocol, unsigned int flags) { int s = socket(domain, type, protocol) ; if (s == -1) return -1 ; - if ((((flags & DJBUNIX_FLAG_NB) ? ndelay_on(s) : ndelay_off(s)) < 0) - || (((flags & DJBUNIX_FLAG_COE) ? coe(s) : uncoe(s)) < 0)) + if ((((flags & O_NONBLOCK) ? ndelay_on(s) : ndelay_off(s)) < 0) + || (((flags & O_CLOEXEC) ? coe(s) : uncoe(s)) < 0)) { fd_close(s) ; return -1 ; diff --git a/src/libstddjb/socket_tcp4.c b/src/libstddjb/socket_tcp4.c index 8eecb67..5705af2 100644 --- a/src/libstddjb/socket_tcp4.c +++ b/src/libstddjb/socket_tcp4.c @@ -3,6 +3,7 @@ #include <skalibs/nonposix.h> #include <sys/socket.h> #include <netinet/in.h> + #include <skalibs/socket.h> int socket_tcp4_internal (unsigned int flags) diff --git a/src/libstddjb/socketpair_internal.c b/src/libstddjb/socketpair_internal.c index a31228f..0cedce2 100644 --- a/src/libstddjb/socketpair_internal.c +++ b/src/libstddjb/socketpair_internal.c @@ -4,13 +4,16 @@ #include <skalibs/nonposix.h> #include <sys/socket.h> #include <errno.h> +#include <fcntl.h> + #include <skalibs/djbunix.h> +#include <skalibs/socket.h> #ifdef SKALIBS_HASACCEPT4 int socketpair_internal (int domain, int type, int protocol, unsigned int flags, int *sv) { - return socketpair(domain, type | ((flags & DJBUNIX_FLAG_NB) ? SOCK_NONBLOCK : 0) | ((flags & DJBUNIX_FLAG_COE) ? SOCK_CLOEXEC : 0), protocol, sv) ; + return socketpair(domain, type | ((flags & O_NONBLOCK) ? SOCK_NONBLOCK : 0) | ((flags & O_CLOEXEC) ? SOCK_CLOEXEC : 0), protocol, sv) ; } #else @@ -19,7 +22,7 @@ int socketpair_internal (int domain, int type, int protocol, unsigned int flags, { int fd[2] ; if (socketpair(domain, type, protocol, fd) < 0) return -1 ; - if (flags & DJBUNIX_FLAG_NB) + if (flags & O_NONBLOCK) { if (ndelay_on(fd[0]) < 0) goto err ; if (ndelay_on(fd[1]) < 0) goto err ; @@ -29,7 +32,7 @@ int socketpair_internal (int domain, int type, int protocol, unsigned int flags, if (ndelay_off(fd[0]) < 0) goto err ; if (ndelay_off(fd[1]) < 0) goto err ; } - if (flags & DJBUNIX_FLAG_COE) + if (flags & O_CLOEXEC) { if (coe(fd[0]) < 0) goto err ; if (coe(fd[1]) < 0) goto err ; |