[#28007] [Feature:trunk] optional reverse_lookup argument for IPSocket#{addr,peeraddr} and Socket.getaddrinfo — Nobuyoshi Nakada <nobu@...>
Hi,
Hi,
[#28015] RCR: RUBY_VERSION_INT — Roger Pack <rogerdpack2@...>
Situation:
Roger Pack:
[#28029] [Bug #2709] $VERBOSE, $DEBUG and Kernel#sprintf — Patrik Wenger <redmine@...>
Bug #2709: $VERBOSE, $DEBUG and Kernel#sprintf
[#28036] [Bug #2710] Kernel#load loads a relative path — Brian Ford <redmine@...>
Bug #2710: Kernel#load loads a relative path
[#28037] Floating Point Bug in 1.8.6-p398 — Austin Ziegler <halostatue@...>
Doing some quick testing with multiruby on something, I see that every
> Doing some quick testing with multiruby on something, I see that every
[#28072] [Bug #2715] Optimization to avoid spawning shell in Kernel#system call should check for failure conditions — Tomasz Wegrzanowski <redmine@...>
Bug #2715: Optimization to avoid spawning shell in Kernel#system call should check for failure conditions
[#28077] Re: [ruby-cvs:33755] Ruby:r26540 (trunk): * enum.c (enum_each_entry): new method #each_entry to pack values — "Akinori MUSHA" <knu@...>
At Tue, 2 Feb 2010 17:54:56 +0900 (JST),
[#28100] [Bug #2721] OpenSSL::Random.random_bytes(1) is very slow the first time on Windows — Greg Hazel <redmine@...>
Bug #2721: OpenSSL::Random.random_bytes(1) is very slow the first time on Windows
[#28103] [Bug #2722] gets on a large file takes a very very long time — Greg Hazel <redmine@...>
Bug #2722: gets on a large file takes a very very long time
Hi,
[#28113] [Bug #2723] $: length affects re-require time of already loaded files — Greg Hazel <redmine@...>
Bug #2723: $: length affects re-require time of already loaded files
[#28141] [Bug #2731] FileUtils.copy prints error message in $DEBUG mode when destination doesn't exist — Kornelius Kalnbach <redmine@...>
Bug #2731: FileUtils.copy prints error message in $DEBUG mode when destination doesn't exist
[#28147] [Bug #2737] StringConstant +"string literal" (unspaced) raises exception — Joe Lapp <redmine@...>
Bug #2737: StringConstant +"string literal" (unspaced) raises exception
[#28151] [Bug #2739] ruby 1.8.7 built with pthreads hangs under some circumstances — Joel Ebel <redmine@...>
Bug #2739: ruby 1.8.7 built with pthreads hangs under some circumstances
Issue #2739 has been updated by Lucas Nussbaum.
[#28154] [Bug #2740] Extend const_missing to pass in the nesting — Yehuda Katz <redmine@...>
Bug #2740: Extend const_missing to pass in the nesting
[#28204] [Bug #2756] Issues with Math and Complex behavior on 1.9 — Brian Ford <redmine@...>
Bug #2756: Issues with Math and Complex behavior on 1.9
[#28206] Is Math module a wrapper of libm? — Yusuke ENDOH <mame@...>
Hi matz --
Hi,
Hi,
Hi,
Hi,
Hi,
Hi
Hi!
Hi,
So here's a summary of the changes that Kenta and I propose, followed
Hi,
Hi,
Hi,
Hi,
On 2010/03/02 14:15, Marc-Andre Lafortune wrote:
[#28215] Removing Syck from ruby — Aaron Patterson <aaron@...>
Hello,
> I would like to remove Syck from ruby, and release it as a gem that I
On Thu, Feb 18, 2010 at 11:28:20PM +0900, Jon wrote:
[#28235] [Feature #2759] Regexp /g and /G options — Michael Fellinger <redmine@...>
Feature #2759: Regexp /g and /G options
Issue #2759 has been updated by caleb clausen.
(2010/03/04 14:53), caleb clausen wrote:
On 3/4/10, NARUSE, Yui <naruse@airemix.jp> wrote:
[#28237] [Bug #2760] unable to cross-compile win32.c — Roger Pack <redmine@...>
Bug #2760: unable to cross-compile win32.c
[#28238] weird behaviour of readline on OSX 10.6 — Andrew Eberbach <eberbach@...>
Hi
[#28273] [Feature #2772] Matrix: Calculating determinant using Bareiss algorithm [patch] — Marc-Andre Lafortune <redmine@...>
Feature #2772: Matrix: Calculating determinant using Bareiss algorithm [patch]
[#28281] [Bug:trunk] add explicit constraints for WONTFIX IO bug — Yusuke ENDOH <mame@...>
Hi, all
[#28300] [Bug #2781] crash when gc_mark()ing already free'd locals of cloned scope — "coderrr ." <redmine@...>
Bug #2781: crash when gc_mark()ing already free'd locals of cloned scope
[#28318] [Bug #2784] The formatting options hash passed to the to_yaml methods do nothing. — Anshul Khandelwal <redmine@...>
Bug #2784: The formatting options hash passed to the to_yaml methods do nothing.
[#28329] [ANN] Ruby 1.9.2dev has passed RubySpec! — Yusuke ENDOH <mame@...>
Hi,
Hi,
On Wed, Feb 24, 2010 at 4:41 PM, Yusuke ENDOH <mame@tsg.ne.jp> wrote:
Hi,
[#28355] [ANN] Toward rich diversity of Ruby development. — Urabe Shyouhei <shyouhei@...>
A short announcement: thanks to some helps of GitHub people, I now have
Hi,
Vladimir Sizikov wrote:
[#28365] Indentifying key MRI-on-Windows issues — Jon <jon.forums@...>
In an effort to begin summarizing key MRI-on-Windows open issues I'm starting this thread in hopes that those interested will respond with details on the key MRI issues they feel need resolution for Windows users.
> My key concern is http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-=
On Tue, Mar 16, 2010 at 10:30 AM, Roger Pack <rogerdpack2@gmail.com> wrote:
> JRuby does do encoding support, though it's not complete yet. I think
Hi Roger, Charles,
> > The snippets in
[#28366] [Bug #2823] IRB Crashes When Completing Method Names of BasicObjects — Run Paint Run Run <redmine@...>
Bug #2823: IRB Crashes When Completing Method Names of BasicObjects
[ruby-core:28007] [Feature:trunk] optional reverse_lookup argument for IPSocket#{addr,peeraddr} and Socket.getaddrinfo
Hi,
I propose adding an optional argument to enable/disable reverse
lookup.
Index: ext/socket/ipsocket.c
===================================================================
--- ext/socket/ipsocket.c (revision 26539)
+++ ext/socket/ipsocket.c (working copy)
@@ -130,7 +130,30 @@ rsock_init_inetsock(VALUE sock, VALUE re
}
+static ID id_numeric, id_hostname;
+
+int
+rsock_revlookup_flag(VALUE revlookup, int *norevlookup)
+{
+#define return_norevlookup(x) {*norevlookup = x; return 1;}
+ ID id;
+
+ switch (revlookup) {
+ case Qtrue: return_norevlookup(0);
+ case Qfalse: return_norevlookup(1);
+ case Qnil: break;
+ default:
+ Check_Type(revlookup, T_SYMBOL);
+ id = SYM2ID(revlookup);
+ if (id == id_numeric) return_norevlookup(1);
+ if (id == id_hostname) return_norevlookup(0);
+ rb_raise(rb_eArgError, "invalid reverse_lookup flag: :%s", rb_id2name(id));
+ }
+ return 0;
+#undef return_norevlookup
+}
+
/*
* call-seq:
- * ipsocket.addr => [address_family, port, hostname, numeric_address]
+ * ipsocket.addr([reverse_lookup]) => [address_family, port, hostname, numeric_address]
*
* Returns the local address as an array which contains
@@ -138,29 +161,38 @@ rsock_init_inetsock(VALUE sock, VALUE re
*
* hostname is obtained from numeric_address using reverse lookup.
- * If ipsocket.do_not_reverse_lookup is true,
+ * If +reverse_lookup+ is false, or it is nil and
+ * ipsocket.do_not_reverse_lookup is true,
* hostname is same as numeric_address.
+ * See Socket.getaddrinfo for possible values as +reverse_lookup+.
*
* TCPSocket.open("www.ruby-lang.org", 80) {|sock|
* p sock.addr #=> ["AF_INET", 49429, "hal", "192.168.0.128"]
+ * p sock.addr(true) #=> ["AF_INET", 49429, "hal", "192.168.0.128"]
+ * p sock.addr(false) #=> ["AF_INET", 49429, "192.168.0.128", "192.168.0.128"]
+ * p sock.addr(:hostname) #=> ["AF_INET", 49429, "hal", "192.168.0.128"]
+ * p sock.addr(:numeric) #=> ["AF_INET", 49429, "192.168.0.128", "192.168.0.128"]
* }
*
*/
static VALUE
-ip_addr(VALUE sock)
+ip_addr(int argc, VALUE *argv, VALUE sock)
{
rb_io_t *fptr;
struct sockaddr_storage addr;
socklen_t len = sizeof addr;
+ int norevlookup;
GetOpenFile(sock, fptr);
+ if (argc < 1 || !rsock_revlookup_flag(argv[0], &norevlookup))
+ norevlookup = fptr->mode & FMODE_NOREVLOOKUP;
if (getsockname(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
rb_sys_fail("getsockname(2)");
- return rsock_ipaddr((struct sockaddr*)&addr, fptr->mode & FMODE_NOREVLOOKUP);
+ return rsock_ipaddr((struct sockaddr*)&addr, norevlookup);
}
/*
* call-seq:
- * ipsocket.peeraddr => [address_family, port, hostname, numeric_address]
+ * ipsocket.peeraddr([reverse_lookup]) => [address_family, port, hostname, numeric_address]
*
* Returns the remote address as an array which contains
@@ -168,21 +200,34 @@ ip_addr(VALUE sock)
* It is defined for connection oriented socket such as TCPSocket.
*
+ * hostname is obtained from numeric_address using reverse lookup.
+ * If +reverse_lookup+ is false, or it is nil and
+ * ipsocket.do_not_reverse_lookup is true,
+ * hostname is same as numeric_address.
+ * See Socket.getaddrinfo for possible values as +reverse_lookup+.
+ *
* TCPSocket.open("www.ruby-lang.org", 80) {|sock|
* p sock.peeraddr #=> ["AF_INET", 80, "carbon.ruby-lang.org", "221.186.184.68"]
+ * p sock.peeraddr(true) #=> ["AF_INET", 80, "221.186.184.68", "221.186.184.68"]
+ * p sock.peeraddr(false) #=> ["AF_INET", 80, "221.186.184.68", "221.186.184.68"]
+ * p sock.peeraddr(:hostname) #=> ["AF_INET", 80, "carbon.ruby-lang.org", "221.186.184.68"]
+ * p sock.peeraddr(:numeric) #=> ["AF_INET", 80, "221.186.184.68", "221.186.184.68"]
* }
*
*/
static VALUE
-ip_peeraddr(VALUE sock)
+ip_peeraddr(int argc, VALUE *argv, VALUE sock)
{
rb_io_t *fptr;
struct sockaddr_storage addr;
socklen_t len = sizeof addr;
+ int norevlookup;
GetOpenFile(sock, fptr);
+ if (argc < 1 || !rsock_revlookup_flag(argv[0], &norevlookup))
+ norevlookup = fptr->mode & FMODE_NOREVLOOKUP;
if (getpeername(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
rb_sys_fail("getpeername(2)");
- return rsock_ipaddr((struct sockaddr*)&addr, fptr->mode & FMODE_NOREVLOOKUP);
+ return rsock_ipaddr((struct sockaddr*)&addr, norevlookup);
}
@@ -244,9 +289,11 @@ Init_ipsocket(void)
{
rb_cIPSocket = rb_define_class("IPSocket", rb_cBasicSocket);
- rb_define_method(rb_cIPSocket, "addr", ip_addr, 0);
- rb_define_method(rb_cIPSocket, "peeraddr", ip_peeraddr, 0);
+ rb_define_method(rb_cIPSocket, "addr", ip_addr, -1);
+ rb_define_method(rb_cIPSocket, "peeraddr", ip_peeraddr, -1);
rb_define_method(rb_cIPSocket, "recvfrom", ip_recvfrom, -1);
rb_define_singleton_method(rb_cIPSocket, "getaddress", ip_s_getaddress, 1);
rb_undef_method(rb_cIPSocket, "getpeereid");
+ id_numeric = rb_intern_const("numeric");
+ id_hostname = rb_intern_const("hostname");
}
Index: ext/socket/socket.c
===================================================================
--- ext/socket/socket.c (revision 26539)
+++ ext/socket/socket.c (working copy)
@@ -871,5 +871,5 @@ sock_gethostname(VALUE obj)
static VALUE
-make_addrinfo(struct addrinfo *res0)
+make_addrinfo(struct addrinfo *res0, int norevlookup)
{
VALUE base, ary;
@@ -881,5 +881,5 @@ make_addrinfo(struct addrinfo *res0)
base = rb_ary_new();
for (res = res0; res; res = res->ai_next) {
- ary = rsock_ipaddr(res->ai_addr, rsock_do_not_reverse_lookup);
+ ary = rsock_ipaddr(res->ai_addr, norevlookup);
if (res->ai_canonname) {
RARRAY_PTR(ary)[2] = rb_str_new2(res->ai_canonname);
@@ -956,5 +956,5 @@ sock_s_gethostbyaddr(int argc, VALUE *ar
t = rsock_family_arg(family);
}
-#ifdef INET6
+#ifdef AF_INET6
else if (RSTRING_LEN(addr) == 16) {
t = AF_INET6;
@@ -1070,5 +1070,5 @@ sock_s_getservbyport(int argc, VALUE *ar
/*
* call-seq:
- * Socket.getaddrinfo(nodename, servname[, family[, socktype[, protocol[, flags]]]]) => array
+ * Socket.getaddrinfo(nodename, servname[, family[, socktype[, protocol[, flags[, reverse_lookup]]]]]) => array
*
* Obtains address information for _nodename_:_servname_.
@@ -1091,12 +1091,19 @@ sock_s_getservbyport(int argc, VALUE *ar
* # ["AF_INET", 0, "localhost", "127.0.0.1", 2, 3, 0]] # PF_INET/SOCK_RAW/IPPROTO_IP
*
+ * _reverse_lookup_ directs the form of the third element, and should
+ * be true, false, nil or a Symbol.
+ *
+ * true, :hostname : returns hostname string using reverse lookup, which may take a time.
+ * false, :numeric : returns numeric host address, without reverse lookup.
+ * nil : obey to the current +do_not_reverse_lookup+ flag.
*/
static VALUE
sock_s_getaddrinfo(int argc, VALUE *argv)
{
- VALUE host, port, family, socktype, protocol, flags, ret;
+ VALUE host, port, family, socktype, protocol, flags, ret, revlookup;
struct addrinfo hints, *res;
+ int norevlookup;
- rb_scan_args(argc, argv, "24", &host, &port, &family, &socktype, &protocol, &flags);
+ rb_scan_args(argc, argv, "25", &host, &port, &family, &socktype, &protocol, &flags, &revlookup);
MEMZERO(&hints, struct addrinfo, 1);
@@ -1112,7 +1119,10 @@ sock_s_getaddrinfo(int argc, VALUE *argv
hints.ai_flags = NUM2INT(flags);
}
+ if (NIL_P(revlookup) || !rsock_revlookup_flag(revlookup, &norevlookup)) {
+ norevlookup = rsock_do_not_reverse_lookup;
+ }
res = rsock_getaddrinfo(host, port, &hints, 0);
- ret = make_addrinfo(res);
+ ret = make_addrinfo(res, norevlookup);
freeaddrinfo(res);
return ret;
--
Nobu Nakada