mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/socket/extconf.rb: refine the recvmsg test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0283c3d0bb
commit
29f354df63
2 changed files with 42 additions and 12 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Sun Jul 24 20:29:53 2011 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* ext/socket/extconf.rb: refine the recvmsg test.
|
||||||
|
|
||||||
Sun Jul 24 20:02:31 2011 Tanaka Akira <akr@fsij.org>
|
Sun Jul 24 20:02:31 2011 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* ext/socket/extconf.rb: fix the recvmsg test.
|
* ext/socket/extconf.rb: fix the recvmsg test.
|
||||||
|
|
|
@ -124,9 +124,9 @@ if have_func("sendmsg") | have_func("recvmsg")
|
||||||
have_struct_member('struct msghdr', 'msg_accrights', ['sys/types.h', 'sys/socket.h'])
|
have_struct_member('struct msghdr', 'msg_accrights', ['sys/types.h', 'sys/socket.h'])
|
||||||
end
|
end
|
||||||
|
|
||||||
if checking_for("recvmsg() with MSG_PEEK allocate file descriptors") {try_run(<<EOF)}
|
if checking_for("recvmsg() with MSG_PEEK allocate file descriptors") {try_run(cpp_include(headers) + <<'EOF')}
|
||||||
#{cpp_include(headers)}
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -136,7 +136,7 @@ if checking_for("recvmsg() with MSG_PEEK allocate file descriptors") {try_run(<<
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int sv[2];
|
int ps[2], sv[2];
|
||||||
int ret;
|
int ret;
|
||||||
ssize_t ss;
|
ssize_t ss;
|
||||||
int s_fd, r_fd;
|
int s_fd, r_fd;
|
||||||
|
@ -149,7 +149,10 @@ int main(int argc, char *argv[])
|
||||||
char s_buf[1], r_buf[1];
|
char s_buf[1], r_buf[1];
|
||||||
struct stat s_statbuf, r_statbuf;
|
struct stat s_statbuf, r_statbuf;
|
||||||
|
|
||||||
s_fd = 0; /* stdin */
|
ret = pipe(ps);
|
||||||
|
if (ret == -1) { perror("pipe"); exit(EXIT_FAILURE); }
|
||||||
|
|
||||||
|
s_fd = ps[0];
|
||||||
|
|
||||||
ret = socketpair(AF_UNIX, SOCK_DGRAM, 0, sv);
|
ret = socketpair(AF_UNIX, SOCK_DGRAM, 0, sv);
|
||||||
if (ret == -1) { perror("socketpair"); exit(EXIT_FAILURE); }
|
if (ret == -1) { perror("socketpair"); exit(EXIT_FAILURE); }
|
||||||
|
@ -193,25 +196,48 @@ int main(int argc, char *argv[])
|
||||||
ss = recvmsg(sv[1], &r_msg, MSG_PEEK);
|
ss = recvmsg(sv[1], &r_msg, MSG_PEEK);
|
||||||
if (ss == -1) { perror("recvmsg"); exit(EXIT_FAILURE); }
|
if (ss == -1) { perror("recvmsg"); exit(EXIT_FAILURE); }
|
||||||
|
|
||||||
if (ss != 1) { exit(EXIT_FAILURE); }
|
if (ss != 1) {
|
||||||
if (r_buf[0] != 'a') { exit(EXIT_FAILURE); }
|
fprintf(stderr, "unexpected return value from recvmsg: %ld\n", (long)ss);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (r_buf[0] != 'a') {
|
||||||
|
fprintf(stderr, "unexpected return data from recvmsg: 0x%02x\n", r_buf[0]);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
if (r_msg.msg_controllen < CMSG_LEN(sizeof(int))) exit(EXIT_FAILURE);
|
if (r_msg.msg_controllen < CMSG_LEN(sizeof(int))) {
|
||||||
if (r_cmsg.hdr.cmsg_len < CMSG_LEN(sizeof(int))) exit(EXIT_FAILURE);
|
fprintf(stderr, "unexpected: r_msg.msg_controllen < CMSG_LEN(sizeof(int)) not hold: %ld\n",
|
||||||
|
(long)r_msg.msg_controllen);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (r_cmsg.hdr.cmsg_len < CMSG_LEN(sizeof(int))) {
|
||||||
|
fprintf(stderr, "unexpected: r_cmsg.hdr.cmsg_len < CMSG_LEN(sizeof(int)) not hold: %ld\n",
|
||||||
|
(long)r_cmsg.hdr.cmsg_len);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
memcpy((char *)&r_fd, CMSG_DATA(&r_cmsg.hdr), sizeof(int));
|
memcpy((char *)&r_fd, CMSG_DATA(&r_cmsg.hdr), sizeof(int));
|
||||||
|
|
||||||
if (r_fd < 0) exit(EXIT_FAILURE);
|
if (r_fd < 0) {
|
||||||
|
fprintf(stderr, "negative r_fd: %d\n", r_fd);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
if (r_fd == s_fd) exit(EXIT_FAILURE);
|
if (r_fd == s_fd) {
|
||||||
|
fprintf(stderr, "r_fd and s_fd is same: %d\n", r_fd);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
ret = fstat(s_fd, &s_statbuf);
|
ret = fstat(s_fd, &s_statbuf);
|
||||||
if (ret == -1) { exit(EXIT_FAILURE); }
|
if (ret == -1) { perror("fstat(s_fd)"); exit(EXIT_FAILURE); }
|
||||||
|
|
||||||
ret = fstat(r_fd, &r_statbuf);
|
ret = fstat(r_fd, &r_statbuf);
|
||||||
if (ret == -1) { exit(EXIT_FAILURE); }
|
if (ret == -1) { perror("fstat(r_fd)"); exit(EXIT_FAILURE); }
|
||||||
|
|
||||||
if (s_statbuf.st_dev != r_statbuf.st_dev ||
|
if (s_statbuf.st_dev != r_statbuf.st_dev ||
|
||||||
s_statbuf.st_ino != r_statbuf.st_ino) {
|
s_statbuf.st_ino != r_statbuf.st_ino) {
|
||||||
|
fprintf(stderr, "dev/ino doesn't match: s_fd:%ld/%ld r_fd:%ld/%ld\n",
|
||||||
|
(long)s_statbuf.st_dev, (long)s_statbuf.st_ino,
|
||||||
|
(long)r_statbuf.st_dev, (long)r_statbuf.st_ino);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue