Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 2 Apr 2011 09:22:06 +0000 (UTC)
From:      Pawel Jakub Dawidek <pjd@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r220270 - head/sbin/hastd
Message-ID:  <201104020922.p329M6hF076872@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pjd
Date: Sat Apr  2 09:22:06 2011
New Revision: 220270
URL: http://svn.freebsd.org/changeset/base/220270

Log:
  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

Modified:
  head/sbin/hastd/proto_common.c

Modified: head/sbin/hastd/proto_common.c
==============================================================================
--- head/sbin/hastd/proto_common.c	Sat Apr  2 08:45:13 2011	(r220269)
+++ head/sbin/hastd/proto_common.c	Sat Apr  2 09:22:06 2011	(r220270)
@@ -82,6 +82,17 @@ proto_common_send(int sock, const unsign
 	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 cha
 	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);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201104020922.p329M6hF076872>