Forum: Ruby-dev [Ruby 1.9 - Feature #4788][Open] resolv.rb refactoring

C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 Makoto Kishimoto (Guest)
on 2011-05-27 10:02
(Received via mailing list)
Issue #4788 has been reported by Makoto Kishimoto.

----------------------------------------
Feature #4788: resolv.rb refactoring
http://redmine.ruby-lang.org/issues/4788

Author: Makoto Kishimoto
Status: Open
Priority: Normal
Assignee:
Category: lib
Target version: 1.9.3


このようなモンキーパッチが(私のコードではありませんが)
https://github.com/ioquatix/rubydns/blob/master/li...
#3835 ( [ruby-core:32407] )の結果、動かなくなっていたのでパッチを検討していたわけですが、
結論としてresolv.rbに以下のようなリファクタリングを施すのがいいのではないかと考えました。
パッチを添付します。

----

diff --git a/lib/resolv.rb b/lib/resolv.rb
index 1e18893..e9c2432 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -491,6 +491,12 @@ class Resolv
     # #getresource for argument details.

     def each_resource(name, typeclass, &proc)
+      each_resource_(name, typeclass) {|reply, reply_name|
+        extract_resources(reply, reply_name, typeclass, &proc)
+      }
+    end
+
+    def each_resource_(name, typeclass)
       lazy_initialize
       requester = make_udp_requester
       senders = {}
@@ -517,7 +523,7 @@ class Resolv
               # response will not fit in an untruncated UDP packet.
               redo
             else
-              extract_resources(reply, reply_name, typeclass, &proc)
+              yield(reply, reply_name)
             end
             return
           when RCode::NXDomain
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 Makoto Kishimoto (Guest)
on 2011-05-29 23:51
(Received via mailing list)
Issue #4788 has been updated by Makoto Kishimoto.


とりあえず思いつかなかったのでパッチでは each_resource_ という名前にしてしまいましたが、fetch_resource
という名前でどうでしょうか。
----------------------------------------
Feature #4788: resolv.rb refactoring
http://redmine.ruby-lang.org/issues/4788

Author: Makoto Kishimoto
Status: Open
Priority: Normal
Assignee:
Category: lib
Target version: 1.9.3


このようなモンキーパッチが(私のコードではありませんが)
https://github.com/ioquatix/rubydns/blob/master/li...
#3835 ( [ruby-core:32407] )の結果、動かなくなっていたのでパッチを検討していたわけですが、
結論としてresolv.rbに以下のようなリファクタリングを施すのがいいのではないかと考えました。
パッチを添付します。

----

diff --git a/lib/resolv.rb b/lib/resolv.rb
index 1e18893..e9c2432 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -491,6 +491,12 @@ class Resolv
     # #getresource for argument details.

     def each_resource(name, typeclass, &proc)
+      each_resource_(name, typeclass) {|reply, reply_name|
+        extract_resources(reply, reply_name, typeclass, &proc)
+      }
+    end
+
+    def each_resource_(name, typeclass)
       lazy_initialize
       requester = make_udp_requester
       senders = {}
@@ -517,7 +523,7 @@ class Resolv
               # response will not fit in an untruncated UDP packet.
               redo
             else
-              extract_resources(reply, reply_name, typeclass, &proc)
+              yield(reply, reply_name)
             end
             return
           when RCode::NXDomain
6c06915d9aa00cd5c7d4acfb27cdd4e9?d=identicon&s=25 Hiroshi Nakamura (Guest)
on 2011-06-27 23:24
(Received via mailing list)
Issue #4788 has been updated by Hiroshi Nakamura.

Assignee set to Akira Tanaka


----------------------------------------
Feature #4788: resolv.rb refactoring
http://redmine.ruby-lang.org/issues/4788

Author: Makoto Kishimoto
Status: Open
Priority: Normal
Assignee: Akira Tanaka
Category: lib
Target version: 1.9.3


このようなモンキーパッチが(私のコードではありませんが)
https://github.com/ioquatix/rubydns/blob/master/li...
#3835 ( [ruby-core:32407] )の結果、動かなくなっていたのでパッチを検討していたわけですが、
結論としてresolv.rbに以下のようなリファクタリングを施すのがいいのではないかと考えました。
パッチを添付します。

----

diff --git a/lib/resolv.rb b/lib/resolv.rb
index 1e18893..e9c2432 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -491,6 +491,12 @@ class Resolv
     # #getresource for argument details.

     def each_resource(name, typeclass, &proc)
+      each_resource_(name, typeclass) {|reply, reply_name|
+        extract_resources(reply, reply_name, typeclass, &proc)
+      }
+    end
+
+    def each_resource_(name, typeclass)
       lazy_initialize
       requester = make_udp_requester
       senders = {}
@@ -517,7 +523,7 @@ class Resolv
               # response will not fit in an untruncated UDP packet.
               redo
             else
-              extract_resources(reply, reply_name, typeclass, &proc)
+              yield(reply, reply_name)
             end
             return
           when RCode::NXDomain
14d8f99bef950daabe2ae0c5a3968241?d=identicon&s=25 Samuel Williams (Guest)
on 2011-07-09 17:21
(Received via mailing list)
Issue #4788 has been updated by Samuel Williams.


I have a  vested interest in this patch since I am the developer of
RubyDNS. This update will allow RubyDNS to hook into resolve.rb more
efficiently. Right now, I have to duplicate code in resolve.rb to get
the right behaviour.

Also, I originally suggested then name fetch_resource and thus I support
Makoto Kishimoto's proposal about this change.

Lets work to get this updated so that I can add good support for RubyDNS
and Ruby 1.9.

Thanks.
----------------------------------------
Feature #4788: resolv.rb refactoring
http://redmine.ruby-lang.org/issues/4788

Author: Makoto Kishimoto
Status: Open
Priority: Normal
Assignee: Akira Tanaka
Category: lib
Target version: 1.9.3


このようなモンキーパッチが(私のコードではありませんが)
https://github.com/ioquatix/rubydns/blob/master/li...
#3835 ( [ruby-core:32407] )の結果、動かなくなっていたのでパッチを検討していたわけですが、
結論としてresolv.rbに以下のようなリファクタリングを施すのがいいのではないかと考えました。
パッチを添付します。

----

diff --git a/lib/resolv.rb b/lib/resolv.rb
index 1e18893..e9c2432 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -491,6 +491,12 @@ class Resolv
     # #getresource for argument details.

     def each_resource(name, typeclass, &proc)
+      each_resource_(name, typeclass) {|reply, reply_name|
+        extract_resources(reply, reply_name, typeclass, &proc)
+      }
+    end
+
+    def each_resource_(name, typeclass)
       lazy_initialize
       requester = make_udp_requester
       senders = {}
@@ -517,7 +523,7 @@ class Resolv
               # response will not fit in an untruncated UDP packet.
               redo
             else
-              extract_resources(reply, reply_name, typeclass, &proc)
+              yield(reply, reply_name)
             end
             return
           when RCode::NXDomain
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 Makoto Kishimoto (Guest)
on 2011-07-14 08:46
(Received via mailing list)
Issue #4788 has been updated by Makoto Kishimoto.

File resolv_rb_patch.txt added


----------------------------------------
Feature #4788: resolv.rb refactoring
http://redmine.ruby-lang.org/issues/4788

Author: Makoto Kishimoto
Status: Open
Priority: Normal
Assignee: Akira Tanaka
Category: lib
Target version: 1.9.x


このようなモンキーパッチが(私のコードではありませんが)
https://github.com/ioquatix/rubydns/blob/master/li...
#3835 ( [ruby-core:32407] )の結果、動かなくなっていたのでパッチを検討していたわけですが、
結論としてresolv.rbに以下のようなリファクタリングを施すのがいいのではないかと考えました。
パッチを添付します。

----

diff --git a/lib/resolv.rb b/lib/resolv.rb
index 1e18893..e9c2432 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -491,6 +491,12 @@ class Resolv
     # #getresource for argument details.

     def each_resource(name, typeclass, &proc)
+      each_resource_(name, typeclass) {|reply, reply_name|
+        extract_resources(reply, reply_name, typeclass, &proc)
+      }
+    end
+
+    def each_resource_(name, typeclass)
       lazy_initialize
       requester = make_udp_requester
       senders = {}
@@ -517,7 +523,7 @@ class Resolv
               # response will not fit in an untruncated UDP packet.
               redo
             else
-              extract_resources(reply, reply_name, typeclass, &proc)
+              yield(reply, reply_name)
             end
             return
           when RCode::NXDomain
B11f10c4cd9d53970e7be20caa43f940?d=identicon&s=25 Tanaka Akira (Guest)
on 2011-08-02 15:40
(Received via mailing list)
2011/5/27 Makoto Kishimoto <redmine@ruby-lang.org>:
>
> $B$3$N$h$&$J%b%s%-!<%Q%C%A$,!J;d$N%3!<%I$G$O$"$j$^$;$s$,!K(B
> https://github.com/ioquatix/rubydns/blob/master/li...
> #3835 $B!J(B [ruby-core:32407]
$B!K$N7k2L!"F0$+$J$/$J$C$F$$$?$N$G%Q%C%A$r8!F$$7$F$$$?$o$1$G$9$,!"(B
>
$B7kO@$H$7$F(Bresolv.rb$B$K0J2<$N$h$&$J%j%U%!%/%?%j%s%0$r;\$9$N$,$$$$$N$G$O$J$$$+$H9M$($^$7$?!#(B

$B$J$<$=$&$9$k$N$,$$$$$N$+=q$$$F$$$J$$$N$G$J$s$H$b8@$$Fq$$$b$N$,$"$j$^$9!#(B

$B%b%s%-!<%Q%C%A$,$&$^$/$$$+$J$$$+$i!"$H$$$&M}M3$O<u$1F~$lFq$$$G$9!#(B

$B8e$GD4$Y$k$O$a$K$J$C$?$H$-$N$?$a$K!"(B
$BJQ99$9$k$H$-$K$O0U?^$r$I$3$+$K;D$7$F$*$-$?$$$H;W$&$N$G$9$,!"(B
$B>e5-$O$=$N5-=R$H$7$F==J,$J$b$N$H$O;W$($^$;$s!#(B
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 Makoto Kishimoto (Guest)
on 2011-08-03 03:54
(Received via mailing list)
Issue #4788 has been updated by Makoto Kishimoto.


元の問題は、lib/resolv.rb が、TCP へのフォールバックに対応して、その際に
make_requester --> make_udp_requester という名前の変更があったために、
(公開インターフェースではない)それに依存していたコードが動かなくなった、
というものです。

しかし、make_requester のような内部の非常に低いレイヤにあるメソッドに
rubydns ライブラリのコードが依存していた理由は、DNS#each_resource
メソッド中に、個々のリソースを取得するコードが一体不可分に含まれてしまって
いるため、DNS プロキシのようなものを作る場合、each_resource メソッド中の
リソース取得部分のコードの duplicate が、このようなライブラリの実装において
不可避であったためです。

パッチで示したように、リソース取得部分を切り離し、また、一種のコールバックで
ある extract_resources を、現状のハードコーディング状態から抽象化する
リファクタリングによって、ライブラリ側でのコード duplicate が必要なくなります。

パッチで追加される fetch_resource メソッドのユースケースとして、
ライブラリ側のコードがどうなるかというパッチを示します。

--- resolv.rb.orig  2011-05-27 18:15:59.000000000 +0900
+++ resolv.rb  2011-08-03 10:38:43.000000000 +0900
@@ -24,6 +24,13 @@
     # This allows such responses to be passed upstream with little or
no
     # modification/reinterpretation.
     def query(name, typeclass)
+      if respond_to?(:fetch_resource) then
+        fetch_resource(name, typeclass) do |reply, reply_name|
+          return reply, reply_name
+        end
+        return
+      end
+
       lazy_initialize
       requester = make_requester
       senders = {}
----------------------------------------
Feature #4788: resolv.rb refactoring
http://redmine.ruby-lang.org/issues/4788

Author: Makoto Kishimoto
Status: Open
Priority: Normal
Assignee: Akira Tanaka
Category: lib
Target version: 1.9.x


このようなモンキーパッチが(私のコードではありませんが)
https://github.com/ioquatix/rubydns/blob/master/li...
#3835 ( [ruby-core:32407] )の結果、動かなくなっていたのでパッチを検討していたわけですが、
結論としてresolv.rbに以下のようなリファクタリングを施すのがいいのではないかと考えました。
パッチを添付します。

----

diff --git a/lib/resolv.rb b/lib/resolv.rb
index 1e18893..e9c2432 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -491,6 +491,12 @@ class Resolv
     # #getresource for argument details.

     def each_resource(name, typeclass, &proc)
+      each_resource_(name, typeclass) {|reply, reply_name|
+        extract_resources(reply, reply_name, typeclass, &proc)
+      }
+    end
+
+    def each_resource_(name, typeclass)
       lazy_initialize
       requester = make_udp_requester
       senders = {}
@@ -517,7 +523,7 @@ class Resolv
               # response will not fit in an untruncated UDP packet.
               redo
             else
-              extract_resources(reply, reply_name, typeclass, &proc)
+              yield(reply, reply_name)
             end
             return
           when RCode::NXDomain
14d8f99bef950daabe2ae0c5a3968241?d=identicon&s=25 Samuel Williams (Guest)
on 2011-10-21 04:05
(Received via mailing list)
Issue #4788 has been updated by Samuel Williams.


It would be nice to get some movement on this - I'm getting bug reports
from people trying to use 1.9.x and RubyDNS.

Kind regards,
Samuel
----------------------------------------
Feature #4788: resolv.rb refactoring
http://redmine.ruby-lang.org/issues/4788

Author: Makoto Kishimoto
Status: Open
Priority: Normal
Assignee: Akira Tanaka
Category: lib
Target version: 1.9.x


このようなモンキーパッチが(私のコードではありませんが)
https://github.com/ioquatix/rubydns/blob/master/li...
#3835 ( [ruby-core:32407] )の結果、動かなくなっていたのでパッチを検討していたわけですが、
結論としてresolv.rbに以下のようなリファクタリングを施すのがいいのではないかと考えました。
パッチを添付します。

----

diff --git a/lib/resolv.rb b/lib/resolv.rb
index 1e18893..e9c2432 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -491,6 +491,12 @@ class Resolv
     # #getresource for argument details.

     def each_resource(name, typeclass, &proc)
+      each_resource_(name, typeclass) {|reply, reply_name|
+        extract_resources(reply, reply_name, typeclass, &proc)
+      }
+    end
+
+    def each_resource_(name, typeclass)
       lazy_initialize
       requester = make_udp_requester
       senders = {}
@@ -517,7 +523,7 @@ class Resolv
               # response will not fit in an untruncated UDP packet.
               redo
             else
-              extract_resources(reply, reply_name, typeclass, &proc)
+              yield(reply, reply_name)
             end
             return
           when RCode::NXDomain
14d8f99bef950daabe2ae0c5a3968241?d=identicon&s=25 ioquatix (Samuel Williams) (Guest)
on 2012-03-28 12:39
(Received via mailing list)
Issue #4788 has been updated by ioquatix (Samuel Williams).


Hi, still having users with problems and no consistent way to solve it.
Merging this patch would be a great addition. Let me know if you require
any further support or have any questions.
----------------------------------------
Feature #4788: resolv.rb refactoring
https://bugs.ruby-lang.org/issues/4788#change-25301

Author: metanest (Makoto Kishimoto)
Status: Assigned
Priority: Normal
Assignee: akr (Akira Tanaka)
Category: lib
Target version: 2.0.0


このようなモンキーパッチが(私のコードではありませんが)
https://github.com/ioquatix/rubydns/blob/master/li...
#3835 ( [ruby-core:32407] )の結果、動かなくなっていたのでパッチを検討していたわけですが、
結論としてresolv.rbに以下のようなリファクタリングを施すのがいいのではないかと考えました。
パッチを添付します。

----

diff --git a/lib/resolv.rb b/lib/resolv.rb
index 1e18893..e9c2432 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -491,6 +491,12 @@ class Resolv
     # #getresource for argument details.

     def each_resource(name, typeclass, &proc)
+      each_resource_(name, typeclass) {|reply, reply_name|
+        extract_resources(reply, reply_name, typeclass, &proc)
+      }
+    end
+
+    def each_resource_(name, typeclass)
       lazy_initialize
       requester = make_udp_requester
       senders = {}
@@ -517,7 +523,7 @@ class Resolv
               # response will not fit in an untruncated UDP packet.
               redo
             else
-              extract_resources(reply, reply_name, typeclass, &proc)
+              yield(reply, reply_name)
             end
             return
           when RCode::NXDomain
14d8f99bef950daabe2ae0c5a3968241?d=identicon&s=25 ioquatix (Samuel Williams) (Guest)
on 2012-03-29 03:51
(Received via mailing list)
Issue #4788 has been updated by ioquatix (Samuel Williams).


Here is a translation into English for the most recent message from
Makoto:

The original problem is that 'lib/resolv.rb' had a fallback to TCP which
was broken. There was a patch (#3835) which renamed ‘make_requester' to
'make_udp_requester’. This is not a public interface so the code which
depended on it stopped working.

However, the reason why RubyDNS depended on such a method is because the
high level interface performs breaks the response up into individual
records but we are actually interested in the response in its entirety.
This is specifically a problem when creating a DNS proxy where you want
to forward requests with minimal changes. Duplicating the code for
each_resource was unavoidable in the implementation of RubyDNS.

As in the patch provided by Makoto, code duplication can be reduced by
removing the direct connection between each_resource and fetch_resource,
and providing a block to be executed per successful response.

A second patch shows how RubyDNS can be simplified once the proposed
change is applied.

----------------------------------------
Feature #4788: resolv.rb refactoring
https://bugs.ruby-lang.org/issues/4788#change-25344

Author: metanest (Makoto Kishimoto)
Status: Assigned
Priority: Normal
Assignee: akr (Akira Tanaka)
Category: lib
Target version: 2.0.0


このようなモンキーパッチが(私のコードではありませんが)
https://github.com/ioquatix/rubydns/blob/master/li...
#3835 ( [ruby-core:32407] )の結果、動かなくなっていたのでパッチを検討していたわけですが、
結論としてresolv.rbに以下のようなリファクタリングを施すのがいいのではないかと考えました。
パッチを添付します。

----

diff --git a/lib/resolv.rb b/lib/resolv.rb
index 1e18893..e9c2432 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -491,6 +491,12 @@ class Resolv
     # #getresource for argument details.

     def each_resource(name, typeclass, &proc)
+      each_resource_(name, typeclass) {|reply, reply_name|
+        extract_resources(reply, reply_name, typeclass, &proc)
+      }
+    end
+
+    def each_resource_(name, typeclass)
       lazy_initialize
       requester = make_udp_requester
       senders = {}
@@ -517,7 +523,7 @@ class Resolv
               # response will not fit in an untruncated UDP packet.
               redo
             else
-              extract_resources(reply, reply_name, typeclass, &proc)
+              yield(reply, reply_name)
             end
             return
           when RCode::NXDomain
14d8f99bef950daabe2ae0c5a3968241?d=identicon&s=25 ioquatix (Samuel Williams) (Guest)
on 2012-06-11 13:56
(Received via mailing list)
Issue #4788 has been updated by ioquatix (Samuel Williams).


Hi, still waiting for some progress on this issue. Lots of people are
bugging me about it.
----------------------------------------
Feature #4788: resolv.rb refactoring
https://bugs.ruby-lang.org/issues/4788#change-27163

Author: metanest (Makoto Kishimoto)
Status: Assigned
Priority: Normal
Assignee: akr (Akira Tanaka)
Category: lib
Target version: 2.0.0


このようなモンキーパッチが(私のコードではありませんが)
https://github.com/ioquatix/rubydns/blob/master/li...
#3835 ( [ruby-core:32407] )の結果、動かなくなっていたのでパッチを検討していたわけですが、
結論としてresolv.rbに以下のようなリファクタリングを施すのがいいのではないかと考えました。
パッチを添付します。

----

diff --git a/lib/resolv.rb b/lib/resolv.rb
index 1e18893..e9c2432 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -491,6 +491,12 @@ class Resolv
     # #getresource for argument details.

     def each_resource(name, typeclass, &proc)
+      each_resource_(name, typeclass) {|reply, reply_name|
+        extract_resources(reply, reply_name, typeclass, &proc)
+      }
+    end
+
+    def each_resource_(name, typeclass)
       lazy_initialize
       requester = make_udp_requester
       senders = {}
@@ -517,7 +523,7 @@ class Resolv
               # response will not fit in an untruncated UDP packet.
               redo
             else
-              extract_resources(reply, reply_name, typeclass, &proc)
+              yield(reply, reply_name)
             end
             return
           when RCode::NXDomain
14d8f99bef950daabe2ae0c5a3968241?d=identicon&s=25 ioquatix (Samuel Williams) (Guest)
on 2012-07-16 15:42
(Received via mailing list)
Issue #4788 has been updated by ioquatix (Samuel Williams).


*Bump*
----------------------------------------
Feature #4788: resolv.rb refactoring
https://bugs.ruby-lang.org/issues/4788#change-28147

Author: metanest (Makoto Kishimoto)
Status: Assigned
Priority: Normal
Assignee: akr (Akira Tanaka)
Category: lib
Target version: 2.0.0


このようなモンキーパッチが(私のコードではありませんが)
https://github.com/ioquatix/rubydns/blob/master/li...
#3835 ( [ruby-core:32407] )の結果、動かなくなっていたのでパッチを検討していたわけですが、
結論としてresolv.rbに以下のようなリファクタリングを施すのがいいのではないかと考えました。
パッチを添付します。

----

diff --git a/lib/resolv.rb b/lib/resolv.rb
index 1e18893..e9c2432 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -491,6 +491,12 @@ class Resolv
     # #getresource for argument details.

     def each_resource(name, typeclass, &proc)
+      each_resource_(name, typeclass) {|reply, reply_name|
+        extract_resources(reply, reply_name, typeclass, &proc)
+      }
+    end
+
+    def each_resource_(name, typeclass)
       lazy_initialize
       requester = make_udp_requester
       senders = {}
@@ -517,7 +523,7 @@ class Resolv
               # response will not fit in an untruncated UDP packet.
               redo
             else
-              extract_resources(reply, reply_name, typeclass, &proc)
+              yield(reply, reply_name)
             end
             return
           when RCode::NXDomain
9d2f78236e45a335301ba1195026105d?d=identicon&s=25 shyouhei (Shyouhei Urabe) (Guest)
on 2012-07-17 01:57
(Received via mailing list)
Issue #4788 has been updated by shyouhei (Shyouhei Urabe).


@ioquatix isn't the only one who's interested in it (read: me too).
----------------------------------------
Feature #4788: resolv.rb refactoring
https://bugs.ruby-lang.org/issues/4788#change-28163

Author: metanest (Makoto Kishimoto)
Status: Assigned
Priority: Normal
Assignee: akr (Akira Tanaka)
Category: lib
Target version: 2.0.0


このようなモンキーパッチが(私のコードではありませんが)
https://github.com/ioquatix/rubydns/blob/master/li...
#3835 ( [ruby-core:32407] )の結果、動かなくなっていたのでパッチを検討していたわけですが、
結論としてresolv.rbに以下のようなリファクタリングを施すのがいいのではないかと考えました。
パッチを添付します。

----

diff --git a/lib/resolv.rb b/lib/resolv.rb
index 1e18893..e9c2432 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -491,6 +491,12 @@ class Resolv
     # #getresource for argument details.

     def each_resource(name, typeclass, &proc)
+      each_resource_(name, typeclass) {|reply, reply_name|
+        extract_resources(reply, reply_name, typeclass, &proc)
+      }
+    end
+
+    def each_resource_(name, typeclass)
       lazy_initialize
       requester = make_udp_requester
       senders = {}
@@ -517,7 +523,7 @@ class Resolv
               # response will not fit in an untruncated UDP packet.
               redo
             else
-              extract_resources(reply, reply_name, typeclass, &proc)
+              yield(reply, reply_name)
             end
             return
           when RCode::NXDomain
B11f10c4cd9d53970e7be20caa43f940?d=identicon&s=25 akr (Akira Tanaka) (Guest)
on 2012-10-28 15:13
(Received via mailing list)
Issue #4788 has been updated by akr (Akira Tanaka).

Target version changed from 2.0.0 to next minor


----------------------------------------
Feature #4788: resolv.rb refactoring
https://bugs.ruby-lang.org/issues/4788#change-31888

Author: metanest (Makoto Kishimoto)
Status: Assigned
Priority: Normal
Assignee: akr (Akira Tanaka)
Category: lib
Target version: next minor


このようなモンキーパッチが(私のコードではありませんが)
https://github.com/ioquatix/rubydns/blob/master/li...
#3835 ( [ruby-core:32407] )の結果、動かなくなっていたのでパッチを検討していたわけですが、
結論としてresolv.rbに以下のようなリファクタリングを施すのがいいのではないかと考えました。
パッチを添付します。

----

diff --git a/lib/resolv.rb b/lib/resolv.rb
index 1e18893..e9c2432 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -491,6 +491,12 @@ class Resolv
     # #getresource for argument details.

     def each_resource(name, typeclass, &proc)
+      each_resource_(name, typeclass) {|reply, reply_name|
+        extract_resources(reply, reply_name, typeclass, &proc)
+      }
+    end
+
+    def each_resource_(name, typeclass)
       lazy_initialize
       requester = make_udp_requester
       senders = {}
@@ -517,7 +523,7 @@ class Resolv
               # response will not fit in an untruncated UDP packet.
               redo
             else
-              extract_resources(reply, reply_name, typeclass, &proc)
+              yield(reply, reply_name)
             end
             return
           when RCode::NXDomain
14d8f99bef950daabe2ae0c5a3968241?d=identicon&s=25 unknown (Guest)
on 2014-05-10 01:20
(Received via mailing list)
Issue #4788 has been updated by Samuel Williams.


I'm happy to se this has been completed. I just thought I'd mention that
I reimplemented the DNS resolver in RubyDNS using EventMachine as I
couldn't wait for this bug fix. The new EventMachine resolver is
asynchronous which makes it useful in the event driven server, such as
the one in RubyDNS. Thanks for everyone's effort getting this bug
resolved.

----------------------------------------
Feature #4788: resolv.rb refactoring
https://bugs.ruby-lang.org/issues/4788#change-46647

* Author: Makoto Kishimoto
* Status: Closed
* Priority: Normal
* Assignee: Akira Tanaka
* Category: lib
* Target version: next minor
----------------------------------------
このようなモンキーパッチが(私のコードではありませんが)
https://github.com/ioquatix/rubydns/blob/master/li...
#3835 ( [ruby-core:32407] )の結果、動かなくなっていたのでパッチを検討していたわけですが、
結論としてresolv.rbに以下のようなリファクタリングを施すのがいいのではないかと考えました。
パッチを添付します。

----

diff --git a/lib/resolv.rb b/lib/resolv.rb
index 1e18893..e9c2432 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -491,6 +491,12 @@ class Resolv
     # #getresource for argument details.

     def each_resource(name, typeclass, &proc)
+      each_resource_(name, typeclass) {|reply, reply_name|
+        extract_resources(reply, reply_name, typeclass, &proc)
+      }
+    end
+
+    def each_resource_(name, typeclass)
       lazy_initialize
       requester = make_udp_requester
       senders = {}
@@ -517,7 +523,7 @@ class Resolv
               # response will not fit in an untruncated UDP packet.
               redo
             else
-              extract_resources(reply, reply_name, typeclass, &proc)
+              yield(reply, reply_name)
             end
             return
           when RCode::NXDomain


---Files--------------------------------
resolv_rb_patch.txt (823 Bytes)
resolv_rb_patch.txt (823 Bytes)
This topic is locked and can not be replied to.