diff --git a/ChangeLog b/ChangeLog index 3f939becca..b917732fdc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Feb 22 18:40:04 2009 Tanaka Akira + + * ext/socket/option.c (inspect_errno): new function. + (sockopt_inspect): use inspect_errno for SO_ERROR. + Sun Feb 22 15:11:51 2009 Tanaka Akira * re.c (Init_Regexp): define Regexp::FIXEDENCODING. [ruby-dev:38066] 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;