summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2011-04-02 09:22:06 +0000
committerpjd <pjd@FreeBSD.org>2011-04-02 09:22:06 +0000
commit0a787e13ebdc9ffd37cc7980f2ba4f69d85ecb1b (patch)
tree21e2a55eb33536e616399c9126525b98548a01de /sbin
parent02471b97edc56249d3ae5d7d2f28c35adba89ef7 (diff)
downloadFreeBSD-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')
-rw-r--r--sbin/hastd/proto_common.c22
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);
OpenPOWER on IntegriCloud