Project

General

Profile

Actions

Bug #5845

closed

Addrinfo#connect_from が Addrinfo オブジェクトを受け付けない

Added by ohai (Ippei Obayashi) over 12 years ago. Updated over 12 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.0.0dev (2012-01-04 trunk 34210) [x86_64-linux]
Backport:
[ruby-dev:45095]

Description

Addrinfo#connect_from (ext/socket/lib/socket.rb) の rdoc には

# Addrinfo object can be taken for the argument.

Addrinfo.tcp("www.ruby-lang.org", 80).connect_from(Addrinfo.tcp("0.0.0.0", 4649)) {|s|

s.print "GET / HTTP/1.0\r\nHost: www.ruby-lang.org\r\n\r\n"

puts s.read

}

とあり、 Addrinfo オブジェクトを受け付けるように書かれていますが、実際には
その内容は無視されてしまいます。以下のようなスクリプトで確認できます。
require 'socket'
Addrinfo.tcp("www.example.com", 80).connect_from(Addrinfo.tcp("0.0.0.0", 49021)) {|s|
p s.local_address.ip_port
s.close
}
原因は Addrinfo#family_addrinfo に Addrinfo オブジェクトを渡した時の返り値が適切でないことです。
添付したパッチでとりあえずは期待通りに動きます。

適当に作った問題再現用テストも添付します。


Files

addrinfo_family_addrinfo_fix.patch (722 Bytes) addrinfo_family_addrinfo_fix.patch ohai (Ippei Obayashi), 01/05/2012 06:35 PM
addrinfo_connect_from_test.patch (836 Bytes) addrinfo_connect_from_test.patch ohai (Ippei Obayashi), 01/05/2012 06:35 PM
Actions

Also available in: Atom PDF

Like0
Like0