diff --git a/ChangeLog b/ChangeLog index 5b3ff92622..2be1bce169 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Fri Jul 17 22:37:22 2009 NAKAMURA Usaku + + * ext/socket/socket.c (socket_s_ip_address_list): drop inactive + adapters. + + * test/socket/test_{nonblock,addrinfo,socket}.rb: skip some tests on + Windows. + [ruby-core:23051] + Fri Jul 17 22:29:21 2009 NAKAMURA Usaku * ext/readline/readline.c (Init_readline): use rl_catch_sigwinch only diff --git a/ext/socket/socket.c b/ext/socket/socket.c index d041293a68..a2e14b32d2 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -1693,7 +1693,7 @@ socket_s_ip_address_list(VALUE self) DWORD dummy9; DWORD dummy10; DWORD IfType; - int dummy11; + int OperStatus; DWORD dummy12; DWORD dummy13[16]; void *dummy14; @@ -1733,12 +1733,22 @@ socket_s_ip_address_list(VALUE self) for (; adapters; adapters = adapters->Next) { ip_adapter_unicast_address_t *uni; ip_adapter_anycast_address_t *any; + if (adapters->OperStatus != 1) /* 1 means IfOperStatusUp */ + continue; for (uni = adapters->FirstUnicastAddress; uni; uni = uni->Next) { +#ifndef INET6 + if (uni->Address.lpSockaddr->sa_family == AF_INET) +#else if (IS_IP_FAMILY(uni->Address.lpSockaddr->sa_family)) +#endif rb_ary_push(list, sockaddr_obj(uni->Address.lpSockaddr)); } for (any = adapters->FirstAnycastAddress; any; any = any->Next) { +#ifndef INET6 + if (any->Address.lpSockaddr->sa_family == AF_INET) +#else if (IS_IP_FAMILY(any->Address.lpSockaddr->sa_family)) +#endif rb_ary_push(list, sockaddr_obj(any->Address.lpSockaddr)); } } diff --git a/test/socket/test_addrinfo.rb b/test/socket/test_addrinfo.rb index bb87381a3f..4c3babdfa8 100644 --- a/test/socket/test_addrinfo.rb +++ b/test/socket/test_addrinfo.rb @@ -317,6 +317,7 @@ class TestSocketAddrinfo < Test::Unit::TestCase ai = Addrinfo.tcp("0.0.0.0", 4649).family_addrinfo("127.0.0.1", 80) assert_equal(["127.0.0.1", 80], ai.ip_unpack) assert_equal(Socket::SOCK_STREAM, ai.socktype) + return unless Addrinfo.respond_to?(:unix) ai = Addrinfo.unix("/testdir/sock").family_addrinfo("/testdir/sock2") assert_equal("/testdir/sock2", ai.unix_path) assert_equal(Socket::SOCK_STREAM, ai.socktype) diff --git a/test/socket/test_nonblock.rb b/test/socket/test_nonblock.rb index e8e7fca95f..f29766886f 100644 --- a/test/socket/test_nonblock.rb +++ b/test/socket/test_nonblock.rb @@ -196,6 +196,8 @@ class TestSocketNonblock < Test::Unit::TestCase loop { c.sendmsg_nonblock("a" * 100000) } + rescue NotImplementedError + skip "sendmsg not implemented on this platform." rescue Errno::EWOULDBLOCK assert_kind_of(IO::WaitWritable, $!) end @@ -206,6 +208,8 @@ class TestSocketNonblock < Test::Unit::TestCase tcp_pair {|c, s| begin c.recvmsg_nonblock(4096) + rescue NotImplementedError + skip "sendmsg not implemented on this platform." rescue Errno::EWOULDBLOCK assert_kind_of(IO::WaitReadable, $!) end diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb index aaaa9c43c3..1ab2918fff 100644 --- a/test/socket/test_socket.rb +++ b/test/socket/test_socket.rb @@ -36,19 +36,22 @@ class TestSocket < Test::Unit::TestCase def test_initialize Socket.open(Socket::AF_INET, Socket::SOCK_STREAM, 0) {|s| + s.bind(Socket.sockaddr_in(0, "127.0.0.1")) addr = s.getsockname assert_nothing_raised { Socket.unpack_sockaddr_in(addr) } - assert_raise(ArgumentError) { Socket.unpack_sockaddr_un(addr) } + assert_raise(ArgumentError, NoMethodError) { Socket.unpack_sockaddr_un(addr) } } Socket.open("AF_INET", "SOCK_STREAM", 0) {|s| + s.bind(Socket.sockaddr_in(0, "127.0.0.1")) addr = s.getsockname assert_nothing_raised { Socket.unpack_sockaddr_in(addr) } - assert_raise(ArgumentError) { Socket.unpack_sockaddr_un(addr) } + assert_raise(ArgumentError, NoMethodError) { Socket.unpack_sockaddr_un(addr) } } Socket.open(:AF_INET, :SOCK_STREAM, 0) {|s| + s.bind(Socket.sockaddr_in(0, "127.0.0.1")) addr = s.getsockname assert_nothing_raised { Socket.unpack_sockaddr_in(addr) } - assert_raise(ArgumentError) { Socket.unpack_sockaddr_un(addr) } + assert_raise(ArgumentError, NoMethodError) { Socket.unpack_sockaddr_un(addr) } } end @@ -254,10 +257,11 @@ class TestSocket < Test::Unit::TestCase begin ip_addrs = Socket.ip_address_list rescue NotImplementedError - return + skip "Socket.ip_address_list not implemented" end Socket.udp_server_sockets(0) {|sockets| + skip "need sendmsg and recvmsg" unless sockets.respond_to?(:sendmsg) famlies = {} sockets.each {|s| famlies[s.local_address.afamily] = true } ip_addrs.reject! {|ai| !famlies[ai.afamily] }