diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-22 09:40:42 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-22 09:40:42 +0000 |
commit | c160c6e59eb65e3159f979a54dc3d609265829c4 (patch) | |
tree | 8ff4e387cf85e7b33e958796613a567b80adf18f /ext/socket/option.c | |
parent | af7d8584c56e42c9fb2848f797dfddb37c41fb59 (diff) |
* ext/socket/option.c (inspect_errno): new function.
(sockopt_inspect): use inspect_errno for SO_ERROR.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/option.c')
-rw-r--r-- | ext/socket/option.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/ext/socket/option.c b/ext/socket/option.c index caac0abb26..a188061418 100644 --- a/ext/socket/option.c +++ b/ext/socket/option.c @@ -233,6 +233,22 @@ inspect_int(int level, int optname, VALUE data, VALUE ret) } } +static int +inspect_errno(int level, int optname, VALUE data, VALUE ret) +{ + if (RSTRING_LEN(data) == sizeof(int)) { + int i; + char *err; + memcpy((char*)&i, RSTRING_PTR(data), sizeof(int)); + err = strerror(i); + rb_str_catf(ret, " %s (%d)", err, i); + return 1; + } + else { + return 0; + } +} + #if defined(IPV6_MULTICAST_IF) || defined(IPV6_MULTICAST_LOOP) static int inspect_uint(int level, int optname, VALUE data, VALUE ret) @@ -429,7 +445,7 @@ sockopt_inspect(VALUE self) case SO_DEBUG: inspected = inspect_int(level, optname, data, ret); break; # endif # if defined(SO_ERROR) /* POSIX */ - case SO_ERROR: inspected = inspect_int(level, optname, data, ret); break; + case SO_ERROR: inspected = inspect_errno(level, optname, data, ret); break; # endif # if defined(SO_TYPE) /* POSIX */ case SO_TYPE: inspected = inspect_socktype(level, optname, data, ret); break; |