summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-01 15:59:10 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-01 15:59:10 +0000
commitc6bbf28a9f139a5fbf34e54673328d3d58e8e397 (patch)
treeca298128a1041c1a1fff2e5a77513ef7e0a190ea
parent31fa80daddbdeb074bd8bb4afb5e129f1c92ec82 (diff)
* ext/socket/socket.c (family_arg): accept symbols as well.
(socktype_arg): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21257 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/socket/socket.c16
-rw-r--r--test/socket/test_socket.rb5
-rw-r--r--test/socket/test_udp.rb1
4 files changed, 23 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 998486b90f..8dd5b9f786 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Jan 2 00:58:40 2009 Tanaka Akira <akr@fsij.org>
+
+ * ext/socket/socket.c (family_arg): accept symbols as well.
+ (socktype_arg): ditto.
+
Fri Jan 2 00:49:44 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/socket.c (sock_s_getaddrinfo): use socktype_arg.
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 94244fc5ad..7b7aa416ac 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -249,9 +249,13 @@ family_arg(VALUE domain)
char *ptr;
int ret;
- tmp = rb_check_string_type(domain);
- if (!NIL_P(tmp)) {
+ if (SYMBOL_P(domain)) {
+ domain = rb_sym_to_s(domain);
+ goto str;
+ }
+ else if (!NIL_P(tmp = rb_check_string_type(domain))) {
domain = tmp;
+ str:
rb_check_safe_obj(domain);
ptr = RSTRING_PTR(domain);
if (family_to_int(ptr, RSTRING_LEN(domain), &ret) == -1)
@@ -271,9 +275,13 @@ socktype_arg(VALUE type)
char *ptr;
int ret;
- tmp = rb_check_string_type(type);
- if (!NIL_P(tmp)) {
+ if (SYMBOL_P(type)) {
+ type = rb_sym_to_s(type);
+ goto str;
+ }
+ else if (!NIL_P(tmp = rb_check_string_type(type))) {
type = tmp;
+ str:
rb_check_safe_obj(type);
ptr = RSTRING_PTR(type);
if (socktype_to_int(ptr, RSTRING_LEN(type), &ret) == -1)
diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb
index 4c88177c9e..130b1f4390 100644
--- a/test/socket/test_socket.rb
+++ b/test/socket/test_socket.rb
@@ -109,6 +109,11 @@ class TestSocket < Test::Unit::TestCase
assert_nothing_raised { Socket.unpack_sockaddr_in(addr) }
assert_raise(ArgumentError) { Socket.unpack_sockaddr_un(addr) }
}
+ Socket.open(:AF_INET, :SOCK_STREAM, 0) {|s|
+ addr = s.getsockname
+ assert_nothing_raised { Socket.unpack_sockaddr_in(addr) }
+ assert_raise(ArgumentError) { Socket.unpack_sockaddr_un(addr) }
+ }
end
def test_getaddrinfo
diff --git a/test/socket/test_udp.rb b/test/socket/test_udp.rb
index 4893a1f3ca..9a45a86cb3 100644
--- a/test/socket/test_udp.rb
+++ b/test/socket/test_udp.rb
@@ -10,6 +10,7 @@ class TestUDPSocket < Test::Unit::TestCase
assert_nothing_raised { UDPSocket.open {} }
assert_nothing_raised { UDPSocket.open(Socket::AF_INET) {} }
assert_nothing_raised { UDPSocket.open("AF_INET") {} }
+ assert_nothing_raised { UDPSocket.open(:AF_INET) {} }
if defined? Socket::AF_INET6
assert_nothing_raised { UDPSocket.open(Socket::AF_INET6) {} }
end