summaryrefslogtreecommitdiff
path: root/src/aio
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2014-11-21 04:53:17 +0100
committerMartin Sustrik <sustrik@250bpm.com>2014-11-21 04:53:17 +0100
commit79ca54e75f7d409b80cec1579ecbd76cfb28dd4b (patch)
tree389c599c0ba3af3b7d589f01086d455a79ab1710 /src/aio
parent3cae36468c91f5de65234caae07c888b869510b1 (diff)
downloadnanomsg-79ca54e75f7d409b80cec1579ecbd76cfb28dd4b.tar.gz
Fix tcpmux stuff on Solaris
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src/aio')
-rw-r--r--src/aio/usock_posix.inc38
1 files changed, 29 insertions, 9 deletions
diff --git a/src/aio/usock_posix.inc b/src/aio/usock_posix.inc
index c87f708..81b7efe 100644
--- a/src/aio/usock_posix.inc
+++ b/src/aio/usock_posix.inc
@@ -1056,7 +1056,9 @@ static int nn_usock_recv_raw (struct nn_usock *self, void *buf, size_t *len)
struct iovec iov;
struct msghdr hdr;
unsigned char ctrl [256];
+#if defined NN_HAVE_MSG_CONTROL
struct cmsghdr *cmsg;
+#endif
/* If batch buffer doesn't exist, allocate it. The point of delayed
deallocation to allow non-receiving sockets, such as TCP listening
@@ -1093,8 +1095,14 @@ static int nn_usock_recv_raw (struct nn_usock *self, void *buf, size_t *len)
memset (&hdr, 0, sizeof (hdr));
hdr.msg_iov = &iov;
hdr.msg_iovlen = 1;
+#if defined NN_HAVE_MSG_CONTROL
hdr.msg_control = ctrl;
hdr.msg_controllen = sizeof (ctrl);
+#else
+ *((int*) ctrl) = -1;
+ hdr.msg_accrights = ctrl;
+ hdr.msg_accrightslen = sizeof (int);
+#endif
nbytes = recvmsg (self->s, &hdr, 0);
/* Handle any possible errors. */
@@ -1117,23 +1125,35 @@ static int nn_usock_recv_raw (struct nn_usock *self, void *buf, size_t *len)
}
/* Extract the associated file descriptor, if any. */
+ if (nbytes > 0) {
#if defined NN_HAVE_MSG_CONTROL
- cmsg = CMSG_FIRSTHDR (&hdr);
- while (cmsg) {
- if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
+ cmsg = CMSG_FIRSTHDR (&hdr);
+ while (cmsg) {
+ if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
+ if (self->in.pfd) {
+ *self->in.pfd = *((int*) CMSG_DATA (cmsg));
+ self->in.pfd = NULL;
+ }
+ else {
+ nn_closefd (*((int*) CMSG_DATA (cmsg)));
+ }
+ break;
+ }
+ cmsg = CMSG_NXTHDR (&hdr, cmsg);
+ }
+#else
+ if (hdr.msg_accrightslen > 0) {
+ nn_assert (hdr.msg_accrightslen == sizeof (int));
if (self->in.pfd) {
- *self->in.pfd = *((int*) CMSG_DATA (cmsg));
+ *self->in.pfd = *((int*) hdr.msg_accrights);
self->in.pfd = NULL;
}
else {
- nn_closefd (*((int*) CMSG_DATA (cmsg)));
+ nn_closefd (*((int*) hdr.msg_accrights));
}
- break;
}
- cmsg = CMSG_NXTHDR (&hdr, cmsg);
- }
-#else
#endif
+ }
/* If the data were received directly into the place we can return
straight away. */