diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-08 14:20:47 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-08 14:20:47 +0000 |
commit | 80618e75aa6a304e11105932f0120ff66ead261c (patch) | |
tree | 96823f2773fc11295fcbca80e5ad76e4c10c1aa2 /ext/socket | |
parent | 2f31ea3c86b3966405fab773381e5dc7fd7d8c0f (diff) | |
download | ruby-80618e75aa6a304e11105932f0120ff66ead261c.tar.gz |
* ext/socket/socket.c (bsock_shutdown): accept symbol/string as how.
(shutdown_how_arg): new function.
* ext/socket/mkconstants.rb: generate shutdown_how_to_int.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r-- | ext/socket/mkconstants.rb | 1 | ||||
-rw-r--r-- | ext/socket/socket.c | 15 |
2 files changed, 12 insertions, 4 deletions
diff --git a/ext/socket/mkconstants.rb b/ext/socket/mkconstants.rb index 08e97018b0..20df7b598d 100644 --- a/ext/socket/mkconstants.rb +++ b/ext/socket/mkconstants.rb @@ -219,6 +219,7 @@ init_constants(VALUE mConst) <%= gen_name_to_int_func("ipv6_optname_to_int", /\AIPV6_/, "IPV6_", "IPPROTO_IPV6") %> <%= gen_name_to_int_func("tcp_optname_to_int", /\ATCP_/, "TCP_") %> <%= gen_name_to_int_func("udp_optname_to_int", /\AUDP_/, "UDP_") %> +<%= gen_name_to_int_func("shutdown_how_to_int", /\ASHUT_/, "SHUT_") %> <%= INTERN_DEFS.map {|decl, gen_hash, func| func }.join("\n") %> diff --git a/ext/socket/socket.c b/ext/socket/socket.c index 8fec480844..825d230bfc 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -375,6 +375,13 @@ optname_arg(int level, VALUE optname) } } +static int +shutdown_how_arg(VALUE how) +{ + /* convert SHUT_RD, SHUT_WR, SHUT_RDWR. */ + return constant_arg(how, shutdown_how_to_int, "unknown shutdown argument"); +} + static VALUE init_sock(VALUE sock, int fd) { @@ -415,11 +422,11 @@ bsock_shutdown(int argc, VALUE *argv, VALUE sock) } rb_scan_args(argc, argv, "01", &howto); if (howto == Qnil) - how = 2; + how = SHUT_RDWR; else { - how = NUM2INT(howto); - if (how < 0 || 2 < how) { - rb_raise(rb_eArgError, "`how' should be either 0, 1, 2"); + how = shutdown_how_arg(howto); + if (how != SHUT_WR && how != SHUT_RD && how != SHUT_RDWR) { + rb_raise(rb_eArgError, "`how' should be either :SHUT_RD, :SHUT_WR, :SHUT_RDWR"); } } GetOpenFile(sock, fptr); |