[#7809] uninit bug in yaml/emitter.c — "Pat Eyler" <rubypate@...>
During our hacking night, we also looked at an UNINIT bug in yaml/emitter.c
[#7813] :!~ not a symbol — noreply@...
Bugs item #4344, was opened at 2006-05-03 17:41
[#7818] (security-related) patch to ALLOC macros to prevent integer overflow bugs — "Dominique Brezinski" <dominique.brezinski@...>
While fixing the integer overflow in rb_ary_fill(), it occurred to me
[#7833] segfault on Proc#call after setting a trace_func — Mauricio Fernandez <mfp@...>
$ cat bug2.rb
[#7843] Possible YAMl bug in 1.8.4 — Damphyr <damphyr@...>
OK, while parsing the td2 data from the ruby-lang website we stumbled on
Its probably a bug. I'm not familiar with the specifics, but Ruby
[#7858] Ruby threads working with native threads — "Francis Cianfrocca" <garbagecat10@...>
I recently wrote a network-event extension for Ruby ("eventmachine" in
[#7865] Strange interactions between Struct and 'pp' — noreply@...
Bugs item #4457, was opened at 2006-05-12 17:13
[#7872] Nonblocking socket-connect — "Francis Cianfrocca" <garbagecat10@...>
All, I needed a nonblocking socket connect for my asynchronous-event
In article <3a94cf510605140559l7baa0205le341dac4f47d424b@mail.gmail.com>,
How about introducing the method Socket#set_nonblocking, or alternatively
Hi,
Well, it's ok then. I'm comfortable adding in the nonblocking
Hi,
How about Socket#nbconnect and Socket#nbaccept?
On 5/15/06, Francis Cianfrocca <garbagecat10@gmail.com> wrote:
In article <1147709691.180288.28647.nullmailer@x31.priv.netlab.jp>,
[#7881] Segfault on x86_64 when built with -O0 in CFLAGS — noreply@...
Bugs item #4491, was opened at 2006-05-16 12:46
[#7882] reproducible bug in DRb on OSX — cremes.devlist@...
I've been tearing my hair out the last few days trying to track down
[#7909] SCRIPT_LINES__ issue when loading a file more than once — Mauricio Fernandez <mfp@...>
SCRIPT_LINES__ is an obscure feature very few people care about, but I happen
On Fri, May 19, 2006 at 06:46:05PM +0900, Mauricio Fernandez wrote:
Hi,
[#7923] Nonblocking accept — "Francis Cianfrocca" <garbagecat10@...>
Thanks to the Matz and colleagues for adding the *_nonblock functions. They
[#7928] set_trace_func: binding has wrong self value for return events — =?ISO-8859-15?Q?Florian_Gro=DF?= <florgro@...>
Moin.
Florian Growrote:
Re: Nonblocking accept
In article <3a94cf510605260529x658e20e1q7d9754266675c3d5@mail.gmail.com>,
"Francis Cianfrocca" <garbagecat10@gmail.com> writes:
> Thanks to the Matz and colleagues for adding the *_nonblock functions. They
> have been a huge help. I've already gotten some big performance improvements
> in the EventMachine event-processing library. I thought it was a little
> strange that accept_nonblock is not available for TCPServer (because it
> inherits from IO rather than Socket) but it wasn't hard to work around that.
> (Just create a Socket object and call bind and listen on it myself.) The
> nonblock functions seem to work well with files and unix-domain sockets. I
> haven't tested datagrams yet but will do so shortly.
Since accept is for connection oriented sockets, UDP doesn't need it.
Index: ext/socket/socket.c
===================================================================
RCS file: /src/ruby/ext/socket/socket.c,v
retrieving revision 1.164
diff -u -p -r1.164 socket.c
--- ext/socket/socket.c 25 May 2006 23:43:29 -0000 1.164
+++ ext/socket/socket.c 27 May 2006 01:52:19 -0000
@@ -1383,6 +1383,20 @@ tcp_svr_init(argc, argv, sock)
}
static VALUE
+s_accept_nonblock(VALUE klass, OpenFile *fptr, struct sockaddr *sockaddr, socklen_t *len)
+{
+ int fd2;
+
+ rb_secure(3);
+ rb_io_set_nonblock(fptr);
+ fd2 = accept(fptr->fd, (struct sockaddr*)sockaddr, len);
+ if (fd2 < 0) {
+ rb_sys_fail("accept(2)");
+ }
+ return init_sock(rb_obj_alloc(klass), fd2);
+}
+
+static VALUE
s_accept(klass, fd, sockaddr, len)
VALUE klass;
int fd;
@@ -1435,6 +1449,49 @@ tcp_accept(sock)
(struct sockaddr*)&from, &fromlen);
}
+/*
+ * call-seq:
+ * tcpserver.accept_nonblock => tcpsocket
+ *
+ * Accepts an incoming connection using accept(2) after
+ * O_NONBLOCK is set for the underlying file descriptor.
+ * It returns an accepted TCPSocket for the incoming connection.
+ *
+ * === Example
+ * require 'socket'
+ * serv = TCPServer.new(2202)
+ * begin
+ * sock = serv.accept_nonblock
+ * rescue Errno::EAGAIN, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR
+ * IO.select([serv])
+ * retry
+ * end
+ * # sock is an accepted socket.
+ *
+ * Refer to Socket#accept for the exceptions that may be thrown if the call
+ * to TCPServer#accept_nonblock fails.
+ *
+ * TCPServer#accept_nonblock may raise any error corresponding to accept(2) failure,
+ * including Errno::EAGAIN.
+ *
+ * === See
+ * * TCPServer#accept
+ * * Socket#accept
+ */
+static VALUE
+tcp_accept_nonblock(sock)
+ VALUE sock;
+{
+ OpenFile *fptr;
+ struct sockaddr_storage from;
+ socklen_t fromlen;
+
+ GetOpenFile(sock, fptr);
+ fromlen = sizeof(from);
+ return s_accept_nonblock(rb_cTCPSocket, fptr,
+ (struct sockaddr *)&from, &fromlen);
+}
+
static VALUE
tcp_sysaccept(sock)
VALUE sock;
@@ -1925,6 +1982,49 @@ unix_accept(sock)
(struct sockaddr*)&from, &fromlen);
}
+/*
+ * call-seq:
+ * unixserver.accept_nonblock => unixsocket
+ *
+ * Accepts an incoming connection using accept(2) after
+ * O_NONBLOCK is set for the underlying file descriptor.
+ * It returns an accepted UNIXSocket for the incoming connection.
+ *
+ * === Example
+ * require 'socket'
+ * serv = UNIXServer.new("/tmp/sock")
+ * begin
+ * sock = serv.accept_nonblock
+ * rescue Errno::EAGAIN, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR
+ * IO.select([serv])
+ * retry
+ * end
+ * # sock is an accepted socket.
+ *
+ * Refer to Socket#accept for the exceptions that may be thrown if the call
+ * to UNIXServer#accept_nonblock fails.
+ *
+ * UNIXServer#accept_nonblock may raise any error corresponding to accept(2) failure,
+ * including Errno::EAGAIN.
+ *
+ * === See
+ * * UNIXServer#accept
+ * * Socket#accept
+ */
+static VALUE
+unix_accept_nonblock(sock)
+ VALUE sock;
+{
+ OpenFile *fptr;
+ struct sockaddr_storage from;
+ socklen_t fromlen;
+
+ GetOpenFile(sock, fptr);
+ fromlen = sizeof(from);
+ return s_accept_nonblock(rb_cUNIXSocket, fptr,
+ (struct sockaddr *)&from, &fromlen);
+}
+
static VALUE
unix_sysaccept(sock)
VALUE sock;
@@ -2784,19 +2884,12 @@ sock_accept_nonblock(sock)
VALUE sock;
{
OpenFile *fptr;
- int fd2;
VALUE sock2;
char buf[1024];
socklen_t len = sizeof buf;
GetOpenFile(sock, fptr);
- rb_io_set_nonblock(fptr);
- fd2 = accept(fptr->fd, (struct sockaddr*)buf, &len);
- if (fd2 < 0) {
- rb_sys_fail("accept(2)");
- }
- sock2 = init_sock(rb_obj_alloc(rb_cSocket), fd2);
-
+ sock2 = s_accept_nonblock(rb_cSocket, fptr, (struct sockaddr *)buf, &len);
return rb_assoc_new(sock2, rb_str_new(buf, len));
}
@@ -3414,6 +3507,7 @@ Init_socket()
rb_cTCPServer = rb_define_class("TCPServer", rb_cTCPSocket);
rb_define_global_const("TCPserver", rb_cTCPServer);
rb_define_method(rb_cTCPServer, "accept", tcp_accept, 0);
+ rb_define_method(rb_cTCPServer, "accept_nonblock", tcp_accept_nonblock, 0);
rb_define_method(rb_cTCPServer, "sysaccept", tcp_sysaccept, 0);
rb_define_method(rb_cTCPServer, "initialize", tcp_svr_init, -1);
rb_define_method(rb_cTCPServer, "listen", sock_listen, 1);
@@ -3442,6 +3536,7 @@ Init_socket()
rb_define_global_const("UNIXserver", rb_cUNIXServer);
rb_define_method(rb_cUNIXServer, "initialize", unix_svr_init, 1);
rb_define_method(rb_cUNIXServer, "accept", unix_accept, 0);
+ rb_define_method(rb_cUNIXServer, "accept_nonblock", unix_accept_nonblock, 0);
rb_define_method(rb_cUNIXServer, "sysaccept", unix_sysaccept, 0);
rb_define_method(rb_cUNIXServer, "listen", sock_listen, 1);
#endif
--
Tanaka Akira