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);
 
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to