c->in.request_completed = c->in.request_read - 1;
}
- while(c->in.pending_replies &&
+ while(c->in.pending_replies &&
c->in.pending_replies->workaround != WORKAROUND_EXTERNAL_SOCKET_OWNER &&
- XCB_SEQUENCE_COMPARE (c->in.pending_replies->last_request, <=, c->in.request_completed))
+ XCB_SEQUENCE_COMPARE (c->in.pending_replies->last_request, <=, c->in.request_completed))
{
pending_reply *oldpend = c->in.pending_replies;
c->in.pending_replies = oldpend->next;
FD_ZERO(&fds);
FD_SET(fd, &fds);
- /* Initializing errno here makes sure that for Win32 this loop will execute only once */
- errno = 0;
- do {
- ret = select(fd + 1, &fds, 0, 0, 0);
- } while (ret == -1 && errno == EINTR);
+ /* Initializing errno here makes sure that for Win32 this loop will execute only once */
+ errno = 0;
+ do {
+ ret = select(fd + 1, &fds, 0, 0, 0);
+ } while (ret == -1 && errno == EINTR);
#endif /* USE_POLL */
}
if(ret <= 0)
pthread_mutex_unlock(&c->iolock);
return NULL;
}
-
+
se->extension = ext_reply->major_opcode;
se->eid = eid;
.iov_base = c->in.queue + c->in.queue_len,
.iov_len = sizeof(c->in.queue) - c->in.queue_len,
};
- struct {
- struct cmsghdr cmsghdr;
- int fd[XCB_MAX_PASS_FD];
- } fds;
+ union {
+ struct cmsghdr cmsghdr;
+ char buf[CMSG_SPACE(XCB_MAX_PASS_FD * sizeof(int))];
+ } cmsgbuf;
struct msghdr msg = {
.msg_name = NULL,
.msg_namelen = 0,
.msg_iov = &iov,
.msg_iovlen = 1,
- .msg_control = &fds,
- .msg_controllen = sizeof (struct cmsghdr) + sizeof(int) * (XCB_MAX_PASS_FD - c->in.in_fd.nfd),
+ .msg_control = cmsgbuf.buf,
+ .msg_controllen = CMSG_SPACE(sizeof(int) * (XCB_MAX_PASS_FD - c->in.in_fd.nfd)),
};
n = recvmsg(c->fd, &msg, 0);
#endif
if(n > 0) {
#if HAVE_SENDMSG
- if (msg.msg_controllen > sizeof (struct cmsghdr))
- {
- if (fds.cmsghdr.cmsg_level == SOL_SOCKET &&
- fds.cmsghdr.cmsg_type == SCM_RIGHTS)
- {
- int nfd = (msg.msg_controllen - sizeof (struct cmsghdr)) / sizeof (int);
- memmove(&c->in.in_fd.fd[c->in.in_fd.nfd],
- fds.fd,
- nfd);
- c->in.in_fd.nfd += nfd;
+ struct cmsghdr *hdr;
+
+ if (msg.msg_controllen >= sizeof (struct cmsghdr)) {
+ for (hdr = CMSG_FIRSTHDR(&msg); hdr; hdr = CMSG_NXTHDR(&msg, hdr)) {
+ if (hdr->cmsg_level == SOL_SOCKET && hdr->cmsg_type == SCM_RIGHTS) {
+ int nfd = (hdr->cmsg_len - CMSG_LEN(0)) / sizeof (int);
+ memcpy(&c->in.in_fd.fd[c->in.in_fd.nfd], CMSG_DATA(hdr), nfd * sizeof (int));
+ c->in.in_fd.nfd += nfd;
+ }
}
}
#endif