summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-09 11:11:24 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-09 11:11:24 +0000
commit268d1a2244b0179848a10a2841b4c037db52d3bd (patch)
treee07df7172bab944345a549c23a463a98ef885755
parent98ddbafb265324e9f89b2546dc85d2b54dac4c43 (diff)
* ext/socket/lib/socket.rb (family_addrinfo): return the given
addrinfo object. Patch by Ippei Obayashi. [ruby-dev:45095] [Bug #5845] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--ext/socket/lib/socket.rb3
-rw-r--r--test/socket/test_addrinfo.rb18
3 files changed, 27 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 18485a0..9273e09 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Mon Jan 9 20:08:52 2012 Tanaka Akira <akr@fsij.org>
+
+ * ext/socket/lib/socket.rb (family_addrinfo): return the given
+ addrinfo object.
+ Patch by Ippei Obayashi. [ruby-dev:45095] [Bug #5845]
+
Mon Jan 9 19:40:20 2012 NAKAMURA Usaku <usa@ruby-lang.org>
* test/zlib/test_zlib.rb (TestZlibGzipWriter#test_writer_wrap): set
diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb
index e7ae0a4..3abbee8 100644
--- a/ext/socket/lib/socket.rb
+++ b/ext/socket/lib/socket.rb
@@ -16,6 +16,9 @@ class Addrinfo
raise ArgumentError, "no address specified"
elsif Addrinfo === args.first
raise ArgumentError, "too many arguments" if args.length != 1
+ addrinfo = args.first
+ raise ArgumentError, "Addrinfo type mismatch" if (self.pfamily != addrinfo.pfamily) || (self.socktype != addrinfo.socktype) || (self.protocol != addrinfo.protocol)
+ addrinfo
elsif self.ip?
raise ArgumentError, "IP address needs host and port but #{args.length} arguments given" if args.length != 2
host, port = args
diff --git a/test/socket/test_addrinfo.rb b/test/socket/test_addrinfo.rb
index c0aeba6..3240b9d 100644
--- a/test/socket/test_addrinfo.rb
+++ b/test/socket/test_addrinfo.rb
@@ -352,6 +352,24 @@ class TestSocketAddrinfo < Test::Unit::TestCase
# not test failure
end
}
+
+ TCPServer.open("0.0.0.0", 0) {|serv|
+ serv_ai = Addrinfo.new(serv.getsockname, :INET, :STREAM)
+ serv_ai = tcp_unspecified_to_loopback(serv_ai)
+ port = random_port
+ begin
+ serv_ai.connect_from(Addrinfo.tcp("0.0.0.0", port)) {|s1|
+ s2 = serv.accept
+ begin
+ assert_equal(port, s2.remote_address.ip_port)
+ ensure
+ s2.close
+ end
+ }
+ rescue *errors_addrinuse
+ # not test failure
+ end
+ }
end
def test_connect_to