diff options
| author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-02 05:55:56 +0000 |
|---|---|---|
| committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-02 05:55:56 +0000 |
| commit | 0e9e1351166fa28ddbab1831b8bb9a7f091066f6 (patch) | |
| tree | c45b832ee1cab77383028a2e0810d2edc6d99607 /ext/socket | |
| parent | 15eff4bd1131ea8193b66bf9538da877f51e8b5a (diff) | |
| download | ruby-0e9e1351166fa28ddbab1831b8bb9a7f091066f6.tar.gz ruby-0e9e1351166fa28ddbab1831b8bb9a7f091066f6.tar.xz ruby-0e9e1351166fa28ddbab1831b8bb9a7f091066f6.zip | |
* ext/socket/socket.c (sock_initialize): make 3rd argument, protocol,
optional.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@21950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
| -rw-r--r-- | ext/socket/socket.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c index 6ef0b3d4d..db27a1154 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -19,7 +19,7 @@ setup_domain_and_type(VALUE domain, int *dv, VALUE type, int *tv) /* * call-seq: - * Socket.new(domain, socktype, protocol) => socket + * Socket.new(domain, socktype [, protocol]) => socket * * Creates a new socket object. * @@ -28,19 +28,25 @@ setup_domain_and_type(VALUE domain, int *dv, VALUE type, int *tv) * _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_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); |
