Be more flexible in the protocol value returned by getaddrinfo()

* Only Solaris 2.10 i386 and Windows seem to return 0 it and other
  Solaris seem to fill the value.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2018-08-18 19:37:29 +00:00
Родитель 08bca6b611
Коммит 4dc1c725f8
1 изменённых файлов: 22 добавлений и 26 удалений

Просмотреть файл

@ -219,45 +219,43 @@ describe 'Socket.getaddrinfo' do
array[6].should be_an_instance_of(Fixnum) array[6].should be_an_instance_of(Fixnum)
end end
ipproto_tcp = Socket::IPPROTO_TCP
platform_is :windows do
ipproto_tcp = 0
end
it 'accepts a Fixnum as the socket type' do it 'accepts a Fixnum as the socket type' do
Socket.getaddrinfo(nil, 'ftp', :INET, Socket::SOCK_STREAM)[0].should == [ *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, Socket::SOCK_STREAM)[0]
array.should == [
'AF_INET', 'AF_INET',
21, 21,
'127.0.0.1', '127.0.0.1',
'127.0.0.1', '127.0.0.1',
Socket::AF_INET, Socket::AF_INET,
Socket::SOCK_STREAM, Socket::SOCK_STREAM,
ipproto_tcp
] ]
[0, Socket::IPPROTO_TCP].should include(proto)
end end
it 'accepts a Symbol as the socket type' do it 'accepts a Symbol as the socket type' do
Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM)[0].should == [ *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM)[0]
array.should == [
'AF_INET', 'AF_INET',
21, 21,
'127.0.0.1', '127.0.0.1',
'127.0.0.1', '127.0.0.1',
Socket::AF_INET, Socket::AF_INET,
Socket::SOCK_STREAM, Socket::SOCK_STREAM,
ipproto_tcp
] ]
[0, Socket::IPPROTO_TCP].should include(proto)
end end
it 'accepts a String as the socket type' do it 'accepts a String as the socket type' do
Socket.getaddrinfo(nil, 'ftp', :INET, 'STREAM')[0].should == [ *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, 'STREAM')[0]
array.should == [
'AF_INET', 'AF_INET',
21, 21,
'127.0.0.1', '127.0.0.1',
'127.0.0.1', '127.0.0.1',
Socket::AF_INET, Socket::AF_INET,
Socket::SOCK_STREAM, Socket::SOCK_STREAM,
ipproto_tcp
] ]
[0, Socket::IPPROTO_TCP].should include(proto)
end end
it 'accepts an object responding to #to_str as the socket type' do it 'accepts an object responding to #to_str as the socket type' do
@ -265,46 +263,45 @@ describe 'Socket.getaddrinfo' do
dummy.stub!(:to_str).and_return('STREAM') dummy.stub!(:to_str).and_return('STREAM')
Socket.getaddrinfo(nil, 'ftp', :INET, dummy)[0].should == [ *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, dummy)[0]
array.should == [
'AF_INET', 'AF_INET',
21, 21,
'127.0.0.1', '127.0.0.1',
'127.0.0.1', '127.0.0.1',
Socket::AF_INET, Socket::AF_INET,
Socket::SOCK_STREAM, Socket::SOCK_STREAM,
ipproto_tcp
] ]
[0, Socket::IPPROTO_TCP].should include(proto)
end end
platform_is_not :windows do platform_is_not :windows do
it 'accepts a Fixnum as the protocol family' do it 'accepts a Fixnum as the protocol family' do
addr = Socket.getaddrinfo(nil, 'discard', :INET, :DGRAM, Socket::IPPROTO_UDP) *array, proto = Socket.getaddrinfo(nil, 'discard', :INET, :DGRAM, Socket::IPPROTO_UDP)[0]
array.should == [
addr[0].should == [
'AF_INET', 'AF_INET',
9, 9,
'127.0.0.1', '127.0.0.1',
'127.0.0.1', '127.0.0.1',
Socket::AF_INET, Socket::AF_INET,
Socket::SOCK_DGRAM, Socket::SOCK_DGRAM,
Socket::IPPROTO_UDP
] ]
[0, Socket::IPPROTO_UDP].should include(proto)
end end
end end
it 'accepts a Fixnum as the flags' do it 'accepts a Fixnum as the flags' do
addr = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM, *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM,
Socket::IPPROTO_TCP, Socket::AI_PASSIVE) Socket::IPPROTO_TCP, Socket::AI_PASSIVE)[0]
array.should == [
addr[0].should == [
'AF_INET', 'AF_INET',
21, 21,
'0.0.0.0', '0.0.0.0',
'0.0.0.0', '0.0.0.0',
Socket::AF_INET, Socket::AF_INET,
Socket::SOCK_STREAM, Socket::SOCK_STREAM,
Socket::IPPROTO_TCP
] ]
[0, Socket::IPPROTO_TCP].should include(proto)
end end
it 'performs a reverse lookup when the reverse_lookup argument is true' do it 'performs a reverse lookup when the reverse_lookup argument is true' do
@ -334,18 +331,17 @@ describe 'Socket.getaddrinfo' do
end end
it 'performs a reverse lookup when the reverse_lookup argument is :numeric' do it 'performs a reverse lookup when the reverse_lookup argument is :numeric' do
addr = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM, *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM,
Socket::IPPROTO_TCP, 0, :numeric)[0] Socket::IPPROTO_TCP, 0, :numeric)[0]
array.should == [
addr.should == [
'AF_INET', 'AF_INET',
21, 21,
'127.0.0.1', '127.0.0.1',
'127.0.0.1', '127.0.0.1',
Socket::AF_INET, Socket::AF_INET,
Socket::SOCK_STREAM, Socket::SOCK_STREAM,
Socket::IPPROTO_TCP
] ]
[0, Socket::IPPROTO_TCP].should include(proto)
end end
end end