diff options
author | 2018-12-15 14:29:39 -0600 | |
---|---|---|
committer | 2018-12-15 14:29:39 -0600 | |
commit | 32da65542f1a4430a3ec7a73fa1ec716c8a05a47 (patch) | |
tree | 98ff62865ead8385fd8716c648c0eafefc938b59 | |
parent | 416240273bfd987cbddac7b6439d99c29f7b67ba (diff) | |
download | pseudo-32da65542f1a4430a3ec7a73fa1ec716c8a05a47.tar.gz pseudo-32da65542f1a4430a3ec7a73fa1ec716c8a05a47.tar.bz2 pseudo-32da65542f1a4430a3ec7a73fa1ec716c8a05a47.zip |
pseudo_ipc.c: eliminate some code duplication
Since msg->pathlen is set to len in the first branch, we can share the
final submit-and-check-for-success part of the two branches.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Signed-off-by: Seebs <seebs@seebs.net>
-rw-r--r-- | ChangeLog.txt | 1 | ||||
-rw-r--r-- | pseudo_ipc.c | 19 |
2 files changed, 9 insertions, 11 deletions
diff --git a/ChangeLog.txt b/ChangeLog.txt index 6664517..e6b1280 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,6 @@ 2018-12-15: * (seebs) Import IPC patch from Rasmus Villemoes. + * (seebs) Import (another) IPC patch from Rasmus Villemoes. 2018-11-29: * (seebs) add missing <stdint.h> to pseudo_db.c. Thanks to diff --git a/pseudo_ipc.c b/pseudo_ipc.c index 7786880..3571dad 100644 --- a/pseudo_ipc.c +++ b/pseudo_ipc.c @@ -113,7 +113,7 @@ do_send(int fd, struct iovec *iov, int iovlen) int pseudo_msg_send(int fd, pseudo_msg_t *msg, size_t len, const char *path) { struct iovec iov[2]; - int r; + int r, iovc; if (!msg) return 1; @@ -131,11 +131,7 @@ pseudo_msg_send(int fd, pseudo_msg_t *msg, size_t len, const char *path) { iov[0].iov_len = PSEUDO_HEADER_SIZE; iov[1].iov_base = (void*)path; iov[1].iov_len = len; - r = do_send(fd, iov, 2); - pseudo_debug(PDBGF_IPC | PDBGF_VERBOSE, "wrote %d bytes\n", r); - if (pipe_error || (r == -1 && (errno == EBADF || errno == EPIPE))) - return -1; - return ((size_t) r != PSEUDO_HEADER_SIZE + len); + iovc = 2; } else { pseudo_debug(PDBGF_IPC, "msg type %d (%s), result %d (%s), path %.*s, mode 0%o\n", msg->type, pseudo_op_name(msg->op), @@ -144,12 +140,13 @@ pseudo_msg_send(int fd, pseudo_msg_t *msg, size_t len, const char *path) { // display_msg_header(msg); iov[0].iov_base = msg; iov[0].iov_len = PSEUDO_HEADER_SIZE + msg->pathlen; - r = do_send(fd, iov, 1); - pseudo_debug(PDBGF_IPC | PDBGF_VERBOSE, "wrote %d bytes\n", r); - if (pipe_error || (r == -1 && (errno == EBADF || errno == EPIPE))) - return -1; - return ((size_t) r != PSEUDO_HEADER_SIZE + msg->pathlen); + iovc = 1; } + r = do_send(fd, iov, iovc); + pseudo_debug(PDBGF_IPC | PDBGF_VERBOSE, "wrote %d bytes\n", r); + if (pipe_error || (r == -1 && (errno == EBADF || errno == EPIPE))) + return -1; + return ((size_t) r != PSEUDO_HEADER_SIZE + msg->pathlen); } /* attempts to receive a message from fd |