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
This commit is contained in:
Pawel Jakub Dawidek 2011-04-02 09:22:06 +00:00
parent 2a49afacd1
commit 3a0b818f59
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=220270

View File

@ -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);