ruby-changes:10406
From: akr <ko1@a...>
Date: Mon, 2 Feb 2009 14:56:10 +0900 (JST)
Subject: [ruby-changes:10406] Ruby:r21950 (trunk): * ext/socket/socket.c (sock_initialize): make 3rd argument, protocol,
akr 2009-02-02 14:55:56 +0900 (Mon, 02 Feb 2009) New Revision: 21950 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21950 Log: * ext/socket/socket.c (sock_initialize): make 3rd argument, protocol, optional. Modified files: trunk/ChangeLog trunk/ext/socket/socket.c trunk/test/socket/test_socket.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 21949) +++ ChangeLog (revision 21950) @@ -1,3 +1,8 @@ +Mon Feb 2 14:53:35 2009 Tanaka Akira <akr@f...> + + * ext/socket/socket.c (sock_initialize): make 3rd argument, protocol, + optional. + Mon Feb 2 14:22:56 2009 NAKAMURA Usaku <usa@r...> * ext/socket/constants.c (cmsg_type_arg): INET6 check. Index: ext/socket/socket.c =================================================================== --- ext/socket/socket.c (revision 21949) +++ ext/socket/socket.c (revision 21950) @@ -19,7 +19,7 @@ /* * call-seq: - * Socket.new(domain, socktype, protocol) => socket + * Socket.new(domain, socktype [, protocol]) => socket * * Creates a new socket object. * @@ -28,19 +28,25 @@ * _socktype_ should be a socket type such as: :STREAM, :DGRAM, :RAW, etc. * * _protocol_ should be a protocol defined in the domain. - * 0 is default protocol for the domain. + * This is optional. + * If it is not given, 0 is used internally. * - * Socket.new(:INET, :STREAM, 0) # TCP socket - * Socket.new(:INET, :DGRAM, 0) # UDP socket - * Socket.new(:UNIX, :STREAM, 0) # UNIX stream socket - * Socket.new(:UNIX, :DGRAM, 0) # UNIX datagram socket + * Socket.new(:INET, :STREAM) # TCP socket + * Socket.new(:INET, :DGRAM) # UDP socket + * Socket.new(:UNIX, :STREAM) # UNIX stream socket + * Socket.new(:UNIX, :DGRAM) # UNIX datagram socket */ static VALUE -sock_initialize(VALUE sock, VALUE domain, VALUE type, VALUE protocol) +sock_initialize(int argc, VALUE *argv, VALUE sock) { + VALUE domain, type, protocol; int fd; int d, t; + rb_scan_args(argc, argv, "21", &domain, &type, &protocol); + if (NIL_P(protocol)) + protocol = INT2FIX(0); + rb_secure(3); setup_domain_and_type(domain, &d, type, &t); fd = ruby_socket(d, t, NUM2INT(protocol)); @@ -1742,7 +1748,7 @@ Init_socket_init(); - rb_define_method(rb_cSocket, "initialize", sock_initialize, 3); + rb_define_method(rb_cSocket, "initialize", sock_initialize, -1); rb_define_method(rb_cSocket, "connect", sock_connect, 1); rb_define_method(rb_cSocket, "connect_nonblock", sock_connect_nonblock, 1); rb_define_method(rb_cSocket, "bind", sock_bind, 1); Index: test/socket/test_socket.rb =================================================================== --- test/socket/test_socket.rb (revision 21949) +++ test/socket/test_socket.rb (revision 21950) @@ -5,6 +5,11 @@ end class TestSocket < Test::Unit::TestCase + def test_socket_new + s = Socket.new(:INET, :STREAM) + assert_kind_of(Socket, s) + end + def test_unpack_sockaddr sockaddr_in = Socket.sockaddr_in(80, "") assert_raise(ArgumentError) { Socket.unpack_sockaddr_un(sockaddr_in) } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/