Commit 0d05a226 authored by Tomoyuki Sahara's avatar Tomoyuki Sahara

don't call undefined method. fixes #15.

parent 7b17158f
...@@ -63,9 +63,9 @@ class Addrinfo ...@@ -63,9 +63,9 @@ class Addrinfo
def inspect def inspect
if ipv4? or ipv6? if ipv4? or ipv6?
if @protocol == Socket::IPPROTO_TCP if @protocol == Socket::IPPROTO_TCP or (@socktype == Socket::SOCK_STREAM and @protocol == 0)
proto = 'TCP' proto = 'TCP'
elsif @protocol == Socket::IPPROTO_UDP elsif @protocol == Socket::IPPROTO_UDP or (@socktype == Socket::SOCK_DGRAM and @protocol == 0)
proto = 'UDP' proto = 'UDP'
else else
proto = '???' proto = '???'
...@@ -439,7 +439,8 @@ class Socket ...@@ -439,7 +439,8 @@ class Socket
def recvfrom(maxlen, flags=0) def recvfrom(maxlen, flags=0)
msg, sa = _recvfrom(maxlen, flags) msg, sa = _recvfrom(maxlen, flags)
[ msg, _ai_to_array(Addrinfo.new(sa)) ] socktype = self.getsockopt(Socket::SOL_SOCKET, Socket::SO_TYPE).int
[ msg, Addrinfo.new(sa, Socket::PF_UNSPEC, socktype) ]
end end
def recvfrom_nonblock(*args) def recvfrom_nonblock(*args)
......
...@@ -15,3 +15,20 @@ assert('Socket::getaddrinfo') do ...@@ -15,3 +15,20 @@ assert('Socket::getaddrinfo') do
assert_equal Socket::SOCK_DGRAM, a[5] assert_equal Socket::SOCK_DGRAM, a[5]
assert_equal Socket::IPPROTO_UDP, a[6] assert_equal Socket::IPPROTO_UDP, a[6]
end end
assert('Socket#recvfrom') do
begin
sstr = "abcdefg"
s = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0)
c = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0)
s.bind(Socket.sockaddr_in(0, "127.0.0.1"))
c.send sstr, 0, s.getsockname
rstr, ai = s.recvfrom sstr.size
assert_equal sstr, rstr
assert_true "127.0.0.1", ai.ip_address
ensure
s.close rescue nil
c.close rescue nil
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment