diff options
author | pjd <pjd@FreeBSD.org> | 2011-04-02 09:22:06 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2011-04-02 09:22:06 +0000 |
commit | 0a787e13ebdc9ffd37cc7980f2ba4f69d85ecb1b (patch) | |
tree | 21e2a55eb33536e616399c9126525b98548a01de /sbin/hastd/proto_common.c | |
parent | 02471b97edc56249d3ae5d7d2f28c35adba89ef7 (diff) | |
download | FreeBSD-src-0a787e13ebdc9ffd37cc7980f2ba4f69d85ecb1b.zip FreeBSD-src-0a787e13ebdc9ffd37cc7980f2ba4f69d85ecb1b.tar.gz |
Allow to disable sends or receives on a socket using shutdown(2) by
interpreting NULL 'data' argument passed to proto_common_send() or
proto_common_recv() as a will to do so.
MFC after: 1 month
Diffstat (limited to 'sbin/hastd/proto_common.c')
-rw-r--r-- | sbin/hastd/proto_common.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sbin/hastd/proto_common.c b/sbin/hastd/proto_common.c index 7e0d29c..91d2435 100644 --- a/sbin/hastd/proto_common.c +++ b/sbin/hastd/proto_common.c @@ -82,6 +82,17 @@ proto_common_send(int sock, const unsigned char *data, size_t size, int fd) size_t sendsize; PJDLOG_ASSERT(sock >= 0); + + if (data == NULL) { + /* The caller is just trying to decide about direction. */ + + PJDLOG_ASSERT(size == 0); + + if (shutdown(sock, SHUT_RD) == -1) + return (errno); + return (0); + } + PJDLOG_ASSERT(data != NULL); PJDLOG_ASSERT(size > 0); @@ -141,6 +152,17 @@ proto_common_recv(int sock, unsigned char *data, size_t size, int *fdp) ssize_t done; PJDLOG_ASSERT(sock >= 0); + + if (data == NULL) { + /* The caller is just trying to decide about direction. */ + + PJDLOG_ASSERT(size == 0); + + if (shutdown(sock, SHUT_WR) == -1) + return (errno); + return (0); + } + PJDLOG_ASSERT(data != NULL); PJDLOG_ASSERT(size > 0); |