aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPawel Jakub Dawidek <pjd@FreeBSD.org>2013-12-15 22:58:09 +0000
committerPawel Jakub Dawidek <pjd@FreeBSD.org>2013-12-15 22:58:09 +0000
commit518eeaeeca43dd69fd4e9cd2ca10dc5788535a6c (patch)
tree667109fec4abeb318fdf15525f4363f4641ef591 /lib
parent396b29c74e54981f16df7b5f069c4833779c4461 (diff)
downloadsrc-518eeaeeca43dd69fd4e9cd2ca10dc5788535a6c.tar.gz
src-518eeaeeca43dd69fd4e9cd2ca10dc5788535a6c.zip
MFp4 @1189139:
Get rid of the msg_peek() function, which has a problem. If there was less data in the socket buffer than requested by the caller, the function would busy loop, as select(2) will always return immediately. We can just receive nvlhdr now, because some time ago we splitted receive of data from the receive of descriptors. MFC after: 1 week
Notes
Notes: svn path=/head/; revision=259430
Diffstat (limited to 'lib')
-rw-r--r--lib/libnv/msgio.c24
-rw-r--r--lib/libnv/msgio.h2
-rw-r--r--lib/libnv/nvlist.c8
3 files changed, 5 insertions, 29 deletions
diff --git a/lib/libnv/msgio.c b/lib/libnv/msgio.c
index a37d1cd0bcf5..0a0bd7ff4d88 100644
--- a/lib/libnv/msgio.c
+++ b/lib/libnv/msgio.c
@@ -113,30 +113,6 @@ fd_wait(int fd, bool doread)
NULL, NULL);
}
-int
-msg_peek(int sock, void *buf, size_t size)
-{
- ssize_t done;
-
- PJDLOG_ASSERT(sock >= 0);
- PJDLOG_ASSERT(size > 0);
-
- do {
- fd_wait(sock, true);
- done = recv(sock, buf, size, MSG_PEEK | MSG_WAITALL);
- if (done == -1) {
- if (errno == EAGAIN || errno == EINTR)
- continue;
- return (-1);
- } else if (done == 0) {
- errno = ENOTCONN;
- return (-1);
- }
- } while (done != (ssize_t)size);
-
- return (0);
-}
-
static int
msg_recv(int sock, struct msghdr *msg)
{
diff --git a/lib/libnv/msgio.h b/lib/libnv/msgio.h
index c6de92de10d7..fd5e462af0d0 100644
--- a/lib/libnv/msgio.h
+++ b/lib/libnv/msgio.h
@@ -38,8 +38,6 @@ struct cmsgcred;
struct iovec;
struct msghdr;
-int msg_peek(int sock, void *buf, size_t size);
-
int cred_send(int sock);
int cred_recv(int sock, struct cmsgcred *cred);
diff --git a/lib/libnv/nvlist.c b/lib/libnv/nvlist.c
index 323b2c8d6307..299d60e8a0f2 100644
--- a/lib/libnv/nvlist.c
+++ b/lib/libnv/nvlist.c
@@ -724,11 +724,11 @@ nvlist_recv(int sock)
{
struct nvlist_header nvlhdr;
nvlist_t *nvl, *ret;
+ unsigned char *buf;
size_t nfds, size;
- void *buf;
int serrno, *fds;
- if (msg_peek(sock, &nvlhdr, sizeof(nvlhdr)) == -1)
+ if (buf_recv(sock, &nvlhdr, sizeof(nvlhdr)) == -1)
return (NULL);
if (!nvlist_check_header(&nvlhdr))
@@ -741,10 +741,12 @@ nvlist_recv(int sock)
if (buf == NULL)
return (NULL);
+ memcpy(buf, &nvlhdr, sizeof(nvlhdr));
+
ret = NULL;
fds = NULL;
- if (buf_recv(sock, buf, size) == -1)
+ if (buf_recv(sock, buf + sizeof(nvlhdr), size - sizeof(nvlhdr)) == -1)
goto out;
if (nfds > 0) {