summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-04-25 10:55:01 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-04-25 10:55:01 +0000
commite3b9378f38e0ddc038b7a3032c115eebf9bec75a (patch)
tree8ccacff810cebdc0eaa7547201094983528102ce /ext
parentfb853dc2c2a932bb8b5a62b1e430d101b39733f0 (diff)
downloadruby-e3b9378f38e0ddc038b7a3032c115eebf9bec75a.tar.gz
* ext/socket/socket.c (unix_send_io, unix_recv_io): use CMSG_DATA to
align file descriptor appropriately. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12217 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/socket/socket.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 02690e0dcc..5591ad46a9 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -1910,7 +1910,7 @@ unix_send_io(VALUE sock, VALUE val)
#if FD_PASSING_BY_MSG_CONTROL
struct {
struct cmsghdr hdr;
- int fd;
+ char pad[8+sizeof(int)+8];
} cmsg;
#endif
@@ -1940,12 +1940,12 @@ unix_send_io(VALUE sock, VALUE val)
#if FD_PASSING_BY_MSG_CONTROL
msg.msg_control = (caddr_t)&cmsg;
- msg.msg_controllen = CMSG_SPACE(sizeof(int));
+ msg.msg_controllen = CMSG_LEN(sizeof(int));
msg.msg_flags = 0;
cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(int));
cmsg.hdr.cmsg_level = SOL_SOCKET;
cmsg.hdr.cmsg_type = SCM_RIGHTS;
- cmsg.fd = fd;
+ *(int *)CMSG_DATA(&cmsg.hdr) = fd;
#else
msg.msg_accrights = (caddr_t)&fd;
msg.msg_accrightslen = sizeof(fd);
@@ -1975,7 +1975,7 @@ unix_recv_io(int argc, VALUE *argv, VALUE sock)
#if FD_PASSING_BY_MSG_CONTROL
struct {
struct cmsghdr hdr;
- int fd;
+ char pad[8+sizeof(int)+8];
} cmsg;
#endif
@@ -2004,7 +2004,7 @@ unix_recv_io(int argc, VALUE *argv, VALUE sock)
cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(int));
cmsg.hdr.cmsg_level = SOL_SOCKET;
cmsg.hdr.cmsg_type = SCM_RIGHTS;
- cmsg.fd = -1;
+ *(int *)CMSG_DATA(&cmsg.hdr) = -1;
#else
msg.msg_accrights = (caddr_t)&fd;
msg.msg_accrightslen = sizeof(fd);
@@ -2017,22 +2017,22 @@ unix_recv_io(int argc, VALUE *argv, VALUE sock)
#if FD_PASSING_BY_MSG_CONTROL
if (msg.msg_controllen != CMSG_SPACE(sizeof(int))) {
rb_raise(rb_eSocket,
- "file descriptor was not passed (msg_controllen : %d != %d)",
+ "file descriptor was not passed (msg_controllen=%d, %d expected)",
msg.msg_controllen, CMSG_SPACE(sizeof(int)));
}
- if (cmsg.hdr.cmsg_len != CMSG_SPACE(0) + sizeof(int)) {
+ if (cmsg.hdr.cmsg_len != CMSG_LEN(sizeof(int))) {
rb_raise(rb_eSocket,
- "file descriptor was not passed (cmsg_len : %d != %d)",
- cmsg.hdr.cmsg_len, CMSG_SPACE(0) + sizeof(int));
+ "file descriptor was not passed (cmsg_len=%d, %d expected)",
+ cmsg.hdr.cmsg_len, CMSG_LEN(sizeof(int)));
}
if (cmsg.hdr.cmsg_level != SOL_SOCKET) {
rb_raise(rb_eSocket,
- "file descriptor was not passed (cmsg_level : %d != %d)",
+ "file descriptor was not passed (cmsg_level=%d, %d expected)",
cmsg.hdr.cmsg_level, SOL_SOCKET);
}
if (cmsg.hdr.cmsg_type != SCM_RIGHTS) {
rb_raise(rb_eSocket,
- "file descriptor was not passed (cmsg_type : %d != %d)",
+ "file descriptor was not passed (cmsg_type=%d, %d expected)",
cmsg.hdr.cmsg_type, SCM_RIGHTS);
}
#else
@@ -2044,7 +2044,7 @@ unix_recv_io(int argc, VALUE *argv, VALUE sock)
#endif
#if FD_PASSING_BY_MSG_CONTROL
- fd = cmsg.fd;
+ fd = *(int *)CMSG_DATA(&cmsg.hdr);
#endif
if (klass == Qnil)