diff options
| author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-04 16:20:05 +0000 |
|---|---|---|
| committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-04 16:20:05 +0000 |
| commit | 10fb3a1a3d9a28e498cdd80d0a69028a8d72ba0d (patch) | |
| tree | bfe08bf5bef26724a0682bde799efc0bba18cab9 /ext/socket | |
| parent | bfc9c99715be13a8053067d8900b2219c10534e1 (diff) | |
| download | ruby-10fb3a1a3d9a28e498cdd80d0a69028a8d72ba0d.tar.gz ruby-10fb3a1a3d9a28e498cdd80d0a69028a8d72ba0d.tar.xz ruby-10fb3a1a3d9a28e498cdd80d0a69028a8d72ba0d.zip | |
* ext/socket/socket.c (sock_s_socketpair): make 3rd argument optional.
* ext/socket/unixsocket.c (unix_s_socketpair): follow the above
change.
* ext/socket/rubysocket.h (sock_s_socketpair): ditto.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@22047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
| -rw-r--r-- | ext/socket/rubysocket.h | 2 | ||||
| -rw-r--r-- | ext/socket/socket.c | 11 | ||||
| -rw-r--r-- | ext/socket/unixsocket.c | 7 |
3 files changed, 15 insertions, 5 deletions
diff --git a/ext/socket/rubysocket.h b/ext/socket/rubysocket.h index 53b69f3f7..020767799 100644 --- a/ext/socket/rubysocket.h +++ b/ext/socket/rubysocket.h @@ -212,7 +212,7 @@ VALUE unixaddr(struct sockaddr_un *sockaddr, socklen_t len); int ruby_socket(int domain, int type, int proto); VALUE init_sock(VALUE sock, int fd); -VALUE sock_s_socketpair(VALUE klass, VALUE domain, VALUE type, VALUE protocol); +VALUE sock_s_socketpair(int argc, VALUE *argv, VALUE klass); VALUE init_inetsock(VALUE sock, VALUE remote_host, VALUE remote_serv, VALUE local_host, VALUE local_serv, int type); VALUE init_unixsock(VALUE sock, VALUE path, int server); diff --git a/ext/socket/socket.c b/ext/socket/socket.c index db27a1154..a85128cd4 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -97,13 +97,18 @@ pair_yield(VALUE pair) * */ VALUE -sock_s_socketpair(VALUE klass, VALUE domain, VALUE type, VALUE protocol) +sock_s_socketpair(int argc, VALUE *argv, VALUE klass) { #if defined HAVE_SOCKETPAIR + VALUE domain, type, protocol; int d, t, p, sp[2]; int ret; VALUE s1, s2, r; + rb_scan_args(argc, argv, "21", &domain, &type, &protocol); + if (NIL_P(protocol)) + protocol = INT2FIX(0); + setup_domain_and_type(domain, &d, type, &t); p = NUM2INT(protocol); ret = socketpair(d, t, p, sp); @@ -1760,8 +1765,8 @@ Init_socket() rb_define_method(rb_cSocket, "recvfrom", sock_recvfrom, -1); rb_define_method(rb_cSocket, "recvfrom_nonblock", sock_recvfrom_nonblock, -1); - rb_define_singleton_method(rb_cSocket, "socketpair", sock_s_socketpair, 3); - rb_define_singleton_method(rb_cSocket, "pair", sock_s_socketpair, 3); + rb_define_singleton_method(rb_cSocket, "socketpair", sock_s_socketpair, -1); + rb_define_singleton_method(rb_cSocket, "pair", sock_s_socketpair, -1); rb_define_singleton_method(rb_cSocket, "gethostname", sock_gethostname, 0); rb_define_singleton_method(rb_cSocket, "gethostbyname", sock_s_gethostbyname, 1); rb_define_singleton_method(rb_cSocket, "gethostbyaddr", sock_s_gethostbyaddr, -1); diff --git a/ext/socket/unixsocket.c b/ext/socket/unixsocket.c index a09f2b927..84897ce51 100644 --- a/ext/socket/unixsocket.c +++ b/ext/socket/unixsocket.c @@ -463,6 +463,7 @@ unix_s_socketpair(int argc, VALUE *argv, VALUE klass) { VALUE domain, type, protocol; domain = INT2FIX(PF_UNIX); + VALUE args[3]; rb_scan_args(argc, argv, "02", &type, &protocol); if (argc == 0) @@ -470,7 +471,11 @@ unix_s_socketpair(int argc, VALUE *argv, VALUE klass) if (argc <= 1) protocol = INT2FIX(0); - return sock_s_socketpair(klass, domain, type, protocol); + args[0] = domain; + args[1] = type; + args[2] = protocol; + + return sock_s_socketpair(3, args, klass); } #endif |
