[#2320] Problems in mathn, rational, complex, matrix — Gavin Sinclair <gsinclair@...>
I received a message from Richard Graham mentioning a problem in the
[#2346] Patch for socket.c: control reverse lookup for every instance — Thomas Uehlinger <uehli@...>
Hi all
[#2357] Use the BasicSocket#do_not_reverse_lookup flag in Webrick — Thomas Uehlinger <uehli@...>
Hi
[#2367] Standard libraries — Dave Thomas <dave@...>
From ruby-dev summary:
Hi,
Hi,
By the way, this issue is about a matter of taste, so the debate is somewhat
Hi,
On Thu, Feb 12, 2004 at 02:58:22PM +0900, NAKAMURA, Hiroshi wrote:
On Thursday, February 12, 2004, 8:18:32 PM, Mauricio wrote:
On Thursday 12 February 2004 04:37, Gavin Sinclair wrote:
On Friday, February 13, 2004, 12:44:15 AM, Sean wrote:
(Dave Thomas: there's a question for you in the second paragraph; if you're
[#2397] PATCH: deprecate cgi-lib, getopts, importenv, parsearg from standard library — Gavin Sinclair <gsinclair@...>
Index: cgi-lib.rb
* Gavin Sinclair (gsinclair@soyabean.com.au) wrote:
On Thursday, February 12, 2004, 11:39:37 PM, E wrote:
Hi,
Hi,
[#2422] Re: [ruby-cvs] ruby: * lib/ftools.rb: documented — "U.Nakamura" <usa@...>
Hello,
[#2449] make install not getting through rdoc phase — "David A. Black" <dblack@...>
Hi --
[#2465] PATCH: OpenStruct#initialize to yield self — Gavin Sinclair <gsinclair@...>
This is a common approach I use to object initialization; I don't know
On Fri, 20 Feb 2004 02:42:00 +0900, Dave Thomas wrote:
> > As more general suggestion. Could 'new' yield the new object is a block
On Fri, 20 Feb 2004 08:24:31 +0900, Carlos wrote:
Hi,
Yukihiro Matsumoto wrote:
On Feb 20, 2004, at 4:33 PM, Joel VanderWerf wrote:
[#2494] rehash segfault — Nathaniel Talbott <nathaniel@...>
I don't have a lot of information on this bug at this point, but
Hi,
On Wed, Feb 25, 2004 at 03:30:54AM +0900, Yukihiro Matsumoto wrote:
[#2504] foldl and foldr — "Sean E. Russell" <ser@...>
Sorry if I'm opening old wounds; I have a hard time believing that nobody has
Patch for socket.c: control reverse lookup for every instance
Hi all While experimenting with Webrick I felt that it would be nice if I could control for every socket whether reverse lookup should be done or not (instead of using the global BasicSocket.do_not_reverse_lookup flag). So I created the attached patch for socket.c. Usage is now for example as follows: require 'socket' sock = TCPSocket.new(...) sock.do_not_reverse_lookup = true [use the socket...] What do you thing about that? -- Thomas Uehlinger
Attachments (1)
--- socket_old.c 2004-02-05 22:44:19.996780704 +0100
+++ socket.c 2004-02-05 22:52:38.644974656 +0100
@@ -64,8 +64,6 @@
#endif
#include "sockport.h"
-static int do_not_reverse_lookup = 0;
-
VALUE rb_cBasicSocket;
VALUE rb_cIPSocket;
VALUE rb_cTCPSocket;
@@ -392,7 +390,24 @@
return INT2FIX(n);
}
-static VALUE ipaddr _((struct sockaddr*));
+static VALUE
+bsock_do_not_reverse_lookup(obj)
+ VALUE obj;
+{
+ return rb_ivar_get(obj, rb_intern("@do_not_reverse_lookup"));
+}
+
+static VALUE
+bsock_do_not_reverse_lookup_set(obj, state)
+ VALUE obj;
+ VALUE state;
+{
+ rb_secure(4);
+ return rb_ivar_set(obj, rb_intern("@do_not_reverse_lookup"), state);
+}
+
+
+static VALUE ipaddr _((VALUE, struct sockaddr*));
#ifdef HAVE_SYS_UN_H
static VALUE unixaddr _((struct sockaddr_un*));
#endif
@@ -460,7 +475,7 @@
rb_raise(rb_eTypeError, "sockaddr size differs - should not happen");
}
#endif
- return rb_assoc_new(str, ipaddr((struct sockaddr*)buf));
+ return rb_assoc_new(str, ipaddr(sock, (struct sockaddr*)buf));
#ifdef HAVE_SYS_UN_H
case RECV_UNIX:
return rb_assoc_new(str, unixaddr((struct sockaddr_un*)buf));
@@ -481,21 +496,6 @@
return s_recvfrom(sock, argc, argv, RECV_RECV);
}
-static VALUE
-bsock_do_not_rev_lookup()
-{
- return do_not_reverse_lookup?Qtrue:Qfalse;
-}
-
-static VALUE
-bsock_do_not_rev_lookup_set(self, val)
- VALUE self, val;
-{
- rb_secure(4);
- do_not_reverse_lookup = RTEST(val);
- return val;
-}
-
static void
make_ipaddr0(addr, buf, len)
struct sockaddr *addr;
@@ -655,14 +655,16 @@
}
static VALUE
-ipaddr(sockaddr)
+ipaddr(obj, sockaddr)
+ VALUE obj;
struct sockaddr *sockaddr;
{
VALUE family, port, addr1, addr2;
VALUE ary;
int error;
char hbuf[1024], pbuf[1024];
-
+ int do_not_reverse_lookup = 0;
+
switch (sockaddr->sa_family) {
case AF_UNSPEC:
family = rb_str_new2("AF_UNSPEC");
@@ -689,6 +691,9 @@
family = rb_str_new2(pbuf);
break;
}
+
+ if (obj) do_not_reverse_lookup = RTEST(rb_ivar_get(obj, rb_intern("@do_not_reverse_lookup")));
+
if (!do_not_reverse_lookup) {
error = getnameinfo(sockaddr, SA_LEN(sockaddr), hbuf, sizeof(hbuf),
NULL, 0, 0);
@@ -1254,7 +1259,7 @@
if (getsockname(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0)
rb_sys_fail("getsockname(2)");
- return ipaddr((struct sockaddr*)&addr);
+ return ipaddr(sock, (struct sockaddr*)&addr);
}
static VALUE
@@ -1269,7 +1274,7 @@
if (getpeername(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0)
rb_sys_fail("getpeername(2)");
- return ipaddr((struct sockaddr*)&addr);
+ return ipaddr(sock, (struct sockaddr*)&addr);
}
static VALUE
@@ -1985,7 +1990,7 @@
}
base = rb_ary_new();
for (res = res0; res; res = res->ai_next) {
- ary = ipaddr(res->ai_addr);
+ ary = ipaddr((VALUE)0, res->ai_addr);
if (res->ai_canonname) {
RARRAY(ary)->ptr[2] = rb_str_new2(res->ai_canonname);
}
@@ -2385,10 +2390,6 @@
rb_cBasicSocket = rb_define_class("BasicSocket", rb_cIO);
rb_undef_method(rb_cBasicSocket, "initialize");
- rb_define_singleton_method(rb_cBasicSocket, "do_not_reverse_lookup",
- bsock_do_not_rev_lookup, 0);
- rb_define_singleton_method(rb_cBasicSocket, "do_not_reverse_lookup=",
- bsock_do_not_rev_lookup_set, 1);
rb_define_singleton_method(rb_cBasicSocket, "for_fd", bsock_s_for_fd, 1);
rb_define_method(rb_cBasicSocket, "close_read", bsock_close_read, 0);
@@ -2400,7 +2401,9 @@
rb_define_method(rb_cBasicSocket, "getpeername", bsock_getpeername, 0);
rb_define_method(rb_cBasicSocket, "send", bsock_send, -1);
rb_define_method(rb_cBasicSocket, "recv", bsock_recv, -1);
-
+ rb_define_method(rb_cBasicSocket, "do_not_reverse_lookup", bsock_do_not_reverse_lookup, 0);
+ rb_define_method(rb_cBasicSocket, "do_not_reverse_lookup=", bsock_do_not_reverse_lookup_set, 1);
+
rb_cIPSocket = rb_define_class("IPSocket", rb_cBasicSocket);
rb_define_global_const("IPsocket", rb_cIPSocket);
rb_define_method(rb_cIPSocket, "addr", ip_addr, 0);