Solaris compatibility for io_passfd and io_receivefd (untested, but at

least it compiles)
master
leitner 21 years ago
parent 499ca6a307
commit 72382af11a

@ -4,6 +4,7 @@
add io_appendfile, io_readwritefile
support ip6.arpa in addition to ip6.int in dns_name (adds one
parameter to dns_name6_domain and two constants in dns.h)
Solaris compatibility for io_passfd and io_receivefd
0.19.2:
for some reason, a botched dependency slipped in the the Makefile

@ -14,22 +14,29 @@ union fdmsg {
int io_passfd(int64 sock,int64 fd) {
struct msghdr msg = {0};
struct cmsghdr *cmsg;
struct iovec iov;
#ifdef CMSG_LEN
struct cmsghdr *cmsg;
char buf[CMSG_SPACE(sizeof(int))];
#endif
iov.iov_len=1;
iov.iov_base="x";
msg.msg_control = buf;
msg.msg_controllen = sizeof buf;
msg.msg_iov=&iov;
msg.msg_iovlen=1;
msg.msg_name=0;
msg.msg_namelen=0;
#ifdef CMSG_LEN
msg.msg_control = buf;
msg.msg_controllen = sizeof(buf);
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
*((int*)CMSG_DATA(cmsg))=fd;
msg.msg_controllen = cmsg->cmsg_len;
*((int*)CMSG_DATA(cmsg))=fd;
#else
msg.msg_accrights = (char*)&fd;
msg.msg_accrightslen = sizeof(fd);
#endif
return sendmsg(sock,&msg,0)>=0?0:-1;
}

@ -13,26 +13,38 @@ union fdmsg {
int64 io_receivefd(int64 sock) {
struct iovec iov;
struct msghdr msg;
#ifdef CMSG_LEN
union fdmsg cmsg;
struct cmsghdr* h;
#else
int fd;
#endif
char x[100];
char name[100];
iov.iov_base=x;
iov.iov_len=100;
msg.msg_name=name;
msg.msg_namelen=100;
#ifdef CMSG_LEN
msg.msg_control=cmsg.buf;
msg.msg_controllen=sizeof(union fdmsg);
#else
msg.msg_accrights=(char*)&fd;
msg.msg_accrightslen=sizeof(fd);
#endif
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
#ifdef CMSG_LEN
msg.msg_flags=0;
h=CMSG_FIRSTHDR(&msg);
h->cmsg_len=CMSG_LEN(sizeof(int));
h->cmsg_level=SOL_SOCKET;
h->cmsg_type=SCM_RIGHTS;
*((int*)CMSG_DATA(h))=-1;
#endif
if (recvmsg(sock,&msg,0)==-1)
return -1;
#ifdef CMSG_FIRSTHDR
h=CMSG_FIRSTHDR(&msg);
if (!h || h->cmsg_len!=CMSG_LEN(sizeof(int)) || h->cmsg_level!=SOL_SOCKET || h->cmsg_type!=SCM_RIGHTS) {
#ifdef EPROTO
@ -43,4 +55,8 @@ int64 io_receivefd(int64 sock) {
return -1;
}
return *((int*)CMSG_DATA(h));
#else
if (msg.msg_accrightslen != sizeof(fd)) return -1;
return fd;
#endif
}

Loading…
Cancel
Save