[macruby-changes] [5104] MacRuby/trunk/ext/socket/socket.c
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jan 3 00:43:59 PST 2011
Revision: 5104
http://trac.macosforge.org/projects/ruby/changeset/5104
Author: watson1978 at gmail.com
Date: 2011-01-03 00:43:54 -0800 (Mon, 03 Jan 2011)
Log Message:
-----------
protocol will be optional argument with Socket.pair(domain, type, protocol).
Test Script:
{{{
require 'socket'
require 'test/unit/assertions.rb'
include Test::Unit::Assertions
assert_nothing_raised{ Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM) }
puts :ok
}}}
Modified Paths:
--------------
MacRuby/trunk/ext/socket/socket.c
Modified: MacRuby/trunk/ext/socket/socket.c
===================================================================
--- MacRuby/trunk/ext/socket/socket.c 2011-01-03 05:07:18 UTC (rev 5103)
+++ MacRuby/trunk/ext/socket/socket.c 2011-01-03 08:43:54 UTC (rev 5104)
@@ -2272,11 +2272,15 @@
}
static VALUE
-sock_s_socketpair(VALUE klass, SEL sel, VALUE domain, VALUE type, VALUE protocol)
+sock_s_socketpair(VALUE klass, SEL sel, int argc, VALUE *argv)
{
#if defined HAVE_SOCKETPAIR
+ VALUE domain, type, protocol;
int d, t, p, sp[2];
int ret;
+ 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);
@@ -2301,15 +2305,20 @@
unix_s_socketpair(VALUE klass, SEL sel, int argc, VALUE *argv)
{
VALUE domain, type, protocol;
+ VALUE args[3];
+
domain = INT2FIX(PF_UNIX);
-
rb_scan_args(argc, argv, "02", &type, &protocol);
if (argc == 0)
type = INT2FIX(SOCK_STREAM);
if (argc <= 1)
protocol = INT2FIX(0);
- return sock_s_socketpair(klass, 0, domain, type, protocol);
+ args[0] = domain;
+ args[1] = type;
+ args[2] = protocol;
+
+ return sock_s_socketpair(klass, 0, 3, args);
}
#endif
@@ -3630,8 +3639,8 @@
rb_objc_define_method(rb_cSocket, "recvfrom", sock_recvfrom, -1);
rb_objc_define_method(rb_cSocket, "recvfrom_nonblock", sock_recvfrom_nonblock, -1);
- rb_objc_define_method(*(VALUE *)rb_cSocket, "socketpair", sock_s_socketpair, 3);
- rb_objc_define_method(*(VALUE *)rb_cSocket, "pair", sock_s_socketpair, 3);
+ rb_objc_define_method(*(VALUE *)rb_cSocket, "socketpair", sock_s_socketpair, -1);
+ rb_objc_define_method(*(VALUE *)rb_cSocket, "pair", sock_s_socketpair, -1);
rb_objc_define_method(*(VALUE *)rb_cSocket, "gethostname", sock_gethostname, 0);
rb_objc_define_method(*(VALUE *)rb_cSocket, "gethostbyname", sock_s_gethostbyname, 1);
rb_objc_define_method(*(VALUE *)rb_cSocket, "gethostbyaddr", sock_s_gethostbyaddr, -1);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20110103/9164544f/attachment-0001.html>
More information about the macruby-changes
mailing list