[Feature:1.9] backlog option for TCPServer and UNIXServer


#1

e$B$J$+$@$G$9!#e(B

e$B0JA0$+$i$H$-$*$jMWK>$N$"$C$?$N$G!"e(B{TCP,UNIX}Server.newe$B$Ge(B
listen()e$B$9$ke(Bbackloge$B$N?t$r;XDj$G$-$k$h$&$K$7$F$_$^$7$?!#e(B

[ruby-dev:35379]e$B$,F~$k$H$b$&>/$74JC1$K=q$1$k$s$G$9$,!#e(B

Index: ext/socket/rubysocket.h

— ext/socket/rubysocket.h (revision 21650)
+++ ext/socket/rubysocket.h (working copy)
@@ -215,4 +215,10 @@ VALUE s_accept(VALUE klass, int fd, stru
VALUE s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr
*sockaddr, socklen_t *len);

+struct sock_svrinit_options {

  • int backlog;
    +};
    +int sock_svrinit_opt(VALUE arg, struct sock_svrinit_options *opt);
    +VALUE sock_svrinit(VALUE sock, const struct sock_svrinit_options *opt);

void Init_basicsocket(void);
void Init_ipsocket(void);
Index: ext/socket/unixserver.c

— ext/socket/unixserver.c (revision 21650)
+++ ext/socket/unixserver.c (working copy)
@@ -23,7 +23,13 @@
*/
static VALUE
-unix_svr_init(VALUE sock, VALUE path)
+unix_svr_init(int argc, VALUE *argv, VALUE sock)
{

  • return init_unixsock(sock, path, 1);
  • VALUE path;
  • struct sock_svrinit_options opt;
  • if (argc > 1 && sock_svrinit_opt(argv[argc-1], &opt)) --argc;
  • if (argc == 1) path = argv[0];
  • else rb_scan_args(argc, argv, “1”, &path);
  • return sock_svrinit(init_unixsock(sock, path, 1), &opt);
    }

@@ -140,5 +146,5 @@ Init_unixserver(void)
#ifdef HAVE_SYS_UN_H
rb_cUNIXServer = rb_define_class(“UNIXServer”, rb_cUNIXSocket);

  • rb_define_method(rb_cUNIXServer, “initialize”, unix_svr_init, 1);
  • 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);
    Index: ext/socket/tcpserver.c
    ===================================================================
    — ext/socket/tcpserver.c (revision 21650)
    +++ ext/socket/tcpserver.c (working copy)
    @@ -28,9 +28,12 @@ tcp_svr_init(int argc, VALUE *argv, VALU
    {
    VALUE arg1, arg2;

  • struct sock_svrinit_options opt;

  • if (argc > 1 && sock_svrinit_opt(argv[argc-1], &opt)) --argc;
    if (rb_scan_args(argc, argv, “11”, &arg1, &arg2) == 2)

  • return init_inetsock(sock, arg1, arg2, Qnil, Qnil, INET_SERVER);
  • sock = init_inetsock(sock, arg1, arg2, Qnil, Qnil, INET_SERVER);
    else
  • return init_inetsock(sock, Qnil, arg1, Qnil, Qnil, INET_SERVER);
  • sock = init_inetsock(sock, Qnil, arg1, Qnil, Qnil, INET_SERVER);
  • return sock_svrinit(sock, &opt);
    }

Index: ext/socket/ipsocket.c

— ext/socket/ipsocket.c (revision 21650)
+++ ext/socket/ipsocket.c (working copy)
@@ -101,7 +101,4 @@ init_inetsock_internal(struct inetsock_a
arg->fd = -1;

  • if (type == INET_SERVER)
  • listen(fd, 5);
  • /* create new instance */
    return init_sock(arg->sock, fd);
    Index: ext/socket/socket.c
    ===================================================================
    — ext/socket/socket.c (revision 21635)
    +++ ext/socket/socket.c (working copy)
    @@ -18,4 +18,33 @@ setup_domain_and_type(VALUE domain, int
    }

+int
+sock_svrinit_opt(VALUE arg, struct sock_svrinit_options *opt)
+{

  • opt->backlog = 5;
  • if (TYPE(arg) == T_HASH) {
  • VALUE x;
  • ID id_listen;
  • CONST_ID(id_listen, “listen”);
  • x = rb_hash_lookup(arg, ID2SYM(id_listen));
  • if (!NIL_P(x) && (opt->backlog = NUM2INT(x)) < 0) {
  •  rb_raise(rb_eArgError, "negative backlog length: %d", 
    

opt->backlog)

  • }
  • return Qtrue;
  • }
  • return Qfalse;
    +}

+VALUE
+sock_svrinit(VALUE sock, const struct sock_svrinit_options *opt)
+{

  • rb_io_t *fptr;
  • GetOpenFile(sock, fptr);
  • if (opt->backlog > 0 && listen(fptr->fd, opt->backlog)) {
  • rb_sys_fail(“listen”);
  • }
  • return sock;
    +}

/*

  • call-seq:
    Index: ext/socket/unixsocket.c
    ===================================================================
    — ext/socket/unixsocket.c (revision 21650)
    +++ ext/socket/unixsocket.c (working copy)
    @@ -66,6 +66,4 @@ init_unixsock(VALUE sock, VALUE path, in
    }
  • if (server) listen(fd, 5);
  • init_sock(sock, fd);
    if (server) {

#2

In article removed_email_address@domain.invalid,
Nobuyoshi N. removed_email_address@domain.invalid writes:

e$B0JA0$+$i$H$-$*$jMWK>$N$"$C$?$N$G!"e(B{TCP,UNIX}Server.newe$B$Ge(B
listen()e$B$9$ke(Bbackloge$B$N?t$r;XDj$G$-$k$h$&$K$7$F$_$^$7$?!#e(B

e$B$=$NMWK>$C$F!“5!G=E*$J$b$N$+!”=q$-J}$NOC$+!"$I$C$A$G$7$g$&$+e(B?

{TCPServer,UNIXServer}#listen e$B$H$$$&%a%=%C%I$,$"$j$^$9$,!"$3e(B
e$B$l$r;H$&$N$KHf$Y$F!"$I$&$$$&0c$$$,K>$^$l$F$$$k$N$G$7$g$&$+!#e(B


#3

e$B$J$+$@$G$9!#e(B

At Mon, 19 Jan 2009 10:06:10 +0900,
Tanaka A. wrote in [ruby-dev:37785]:

e$B0JA0$+$i$H$-$*$jMWK>$N$"$C$?$N$G!"e(B{TCP,UNIX}Server.newe$B$Ge(B
listen()e$B$9$ke(Bbackloge$B$N?t$r;XDj$G$-$k$h$&$K$7$F$_$^$7$?!#e(B

e$B$=$NMWK>$C$F!“5!G=E*$J$b$N$+!”=q$-J}$NOC$+!"$I$C$A$G$7$g$&$+e(B?

e$B5!G=E*$JOC$@$C$?$H;W$$$^$9!#e(B

{TCPServer,UNIXServer}#listen e$B$H$$$&%a%=%C%I$,$"$j$^$9$,!"$3e(B
e$B$l$r;H$&$N$KHf$Y$F!"$I$&$$$&0c$$$,K>$^$l$F$$$k$N$G$7$g$&$+!#e(B

e$B$?$7$+!“0lEYe(Blisten()e$B$r<B9T$7$F$7$^$&$H:FEY@_Dj$7$J$*$9$3$H$O$G$-e(B
e$B$J$$4D6-$,$”$k$H$+!"$@$C$?$h$&$J!#$&$m3P$($J$N$G$$$D=P$F$-$?OC$Je(B
e$B$N$+3NG’$G$-$^$;$s$,!#e(B


#4

In article removed_email_address@domain.invalid,
Nobuyoshi N. removed_email_address@domain.invalid writes:

e$B$?$7$+!“0lEYe(Blisten()e$B$r<B9T$7$F$7$^$&$H:FEY@_Dj$7$J$*$9$3$H$O$G$-e(B
e$B$J$$4D6-$,$”$k$H$+!"$@$C$?$h$&$J!#$&$m3P$($J$N$G$$$D=P$F$-$?OC$Je(B
e$B$N$+3NG’$G$-$^$;$s$,!#e(B

e$B6qBNE*$K$O$I$N4D6-$G$=$&$J$k$N$+6=L#$,$"$j$^$9!#$I$J$?$+8fB8e(B
e$B$8$G$7$?$i65$($F$/$@$5$$!#e(B

e$B$J$*!"<j85$G$9$0$K;n$;$?e(B GNU/Linux e$B$He(B FreeBSD e$B$G$O!"e(B
2e$B2se(B listen e$B$9$k$H!“8e$N@_Dj$,@8$-$F$$$k$h$&$G!”:F@_Dj$G$-$ke(B
e$B$h$&$G$9!#e(B


#5

In message removed_email_address@domain.invalid
on Mon, 19 Jan 2009 20:26:42 +0900,
Tanaka A. removed_email_address@domain.invalid wrote:

e$B$J$*!"<j85$G$9$0$K;n$;$?e(B GNU/Linux e$B$He(B FreeBSD e$B$G$O!“e(B
2e$B2se(B listen e$B$9$k$H!“8e$N@_Dj$,@8$-$F$$$k$h$&$G!”:F@_Dj$G$-$ke(B
e$B$h$&$G$9!#e(B
e$B%m!<%I!&%”%Y%l!<%8$,>e$,$C$?$H$-$Ne(BSMTPe$B$N@\B3$r5qH]$K!“e(Bsendmaile$B$,e(B
listen(2)e$B$N%P%C%/%m%0$r%<%m$K$9$k!”$H$$$C$?$3$H$r$7$F$$$?$H5-21$7e(B
e$B$F$$$^$9!#e(B

Berkelye$BM3Mh$N%=%1%C%H!&%$%s%?!<%U%’%$%9$rCi<B$K<BAu$7$F$$$ke(B(or
e$B$G$-$Fe(B
e$B$$$ke(B)e$B$b$N$K$D$$$F$OF0:n$9$k$O$:$G$9!#e(B