summaryrefslogtreecommitdiff
path: root/ext/socket/socket.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-05-23 05:35:32 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-05-23 05:35:32 +0000
commit6e87a54aecec13d500f90ed4a19ffebc6883794b (patch)
tree8dad6991e36a9eb9ad560c31b6e16ea9edb2a682 /ext/socket/socket.c
parent730d8f1d326a62d86e41faa0482f9a3c329832cb (diff)
* ruby.c (proc_options): removed "-*-" support for #! line.
* io.c (rb_io_s_sysopen): new method to get a raw file descriptor. [new] * ext/socket/socket.c (tcp_sysaccept): new method to return an accepted socket fd (integer). [new] * ext/socket/socket.c (unix_sysaccept,sock_sysaccept): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/socket.c')
-rw-r--r--ext/socket/socket.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 8373ce300b0..f4b59f4adb4 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -1134,6 +1134,7 @@ s_accept(klass, fd, sockaddr, len)
}
rb_sys_fail(0);
}
+ if (!klass) return INT2NUM(fd2);
return init_sock(rb_obj_alloc(klass), fd2);
}
@@ -1151,6 +1152,19 @@ tcp_accept(sock)
(struct sockaddr*)&from, &fromlen);
}
+static VALUE
+tcp_sysaccept(sock)
+ VALUE sock;
+{
+ OpenFile *fptr;
+ struct sockaddr_storage from;
+ socklen_t fromlen;
+
+ GetOpenFile(sock, fptr);
+ fromlen = sizeof(from);
+ return s_accept(0, fileno(fptr->f), (struct sockaddr*)&from, &fromlen);
+}
+
#ifdef HAVE_SYS_UN_H
static VALUE
init_unixsock(sock, path, server)
@@ -1575,6 +1589,19 @@ unix_accept(sock)
}
static VALUE
+unix_sysaccept(sock)
+ VALUE sock;
+{
+ OpenFile *fptr;
+ struct sockaddr_un from;
+ socklen_t fromlen;
+
+ GetOpenFile(sock, fptr);
+ fromlen = sizeof(struct sockaddr_un);
+ return s_accept(0, fileno(fptr->f), (struct sockaddr*)&from, &fromlen);
+}
+
+static VALUE
unixaddr(sockaddr)
struct sockaddr_un *sockaddr;
{
@@ -1836,6 +1863,21 @@ sock_accept(sock)
return rb_assoc_new(sock2, rb_tainted_str_new(buf, len));
}
+static VALUE
+sock_sysaccept(sock)
+ VALUE sock;
+{
+ OpenFile *fptr;
+ VALUE sock2;
+ char buf[1024];
+ socklen_t len = sizeof buf;
+
+ GetOpenFile(sock, fptr);
+ sock2 = s_accept(0,fileno(fptr->f),(struct sockaddr*)buf,&len);
+
+ return rb_assoc_new(sock2, rb_tainted_str_new(buf, len));
+}
+
#ifdef HAVE_GETHOSTNAME
static VALUE
sock_gethostname(obj)
@@ -2322,6 +2364,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, "sysaccept", tcp_sysaccept, 0);
rb_define_method(rb_cTCPServer, "initialize", tcp_svr_init, -1);
rb_define_method(rb_cTCPServer, "listen", sock_listen, 1);
@@ -2349,6 +2392,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, "sysaccept", unix_sysaccept, 0);
rb_define_method(rb_cUNIXServer, "listen", sock_listen, 1);
#endif
@@ -2359,6 +2403,7 @@ Init_socket()
rb_define_method(rb_cSocket, "bind", sock_bind, 1);
rb_define_method(rb_cSocket, "listen", sock_listen, 1);
rb_define_method(rb_cSocket, "accept", sock_accept, 0);
+ rb_define_method(rb_cSocket, "sysaccept", sock_sysaccept, 0);
rb_define_method(rb_cSocket, "recvfrom", sock_recvfrom, -1);