summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/socket/init.c12
-rw-r--r--test/socket/test_addrinfo.rb8
2 files changed, 20 insertions, 0 deletions
diff --git a/ext/socket/init.c b/ext/socket/init.c
index 189977dcba0..3b22c1308b1 100644
--- a/ext/socket/init.c
+++ b/ext/socket/init.c
@@ -10,6 +10,10 @@
#include "rubysocket.h"
+#ifdef _WIN32
+VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc);
+#endif
+
VALUE rb_cBasicSocket;
VALUE rb_cIPSocket;
VALUE rb_cTCPSocket;
@@ -39,7 +43,15 @@ rsock_raise_socket_error(const char *reason, int error)
if (error == EAI_SYSTEM && (e = errno) != 0)
rb_syserr_fail(e, reason);
#endif
+#ifdef _WIN32
+ rb_encoding *enc = rb_default_internal_encoding();
+ VALUE msg = rb_sprintf("%s: ", reason);
+ if (!enc) enc = rb_default_internal_encoding();
+ rb_str_concat(msg, rb_w32_conv_from_wchar(gai_strerrorW(error), enc));
+ rb_exc_raise(rb_exc_new_str(rb_eSocket, msg));
+#else
rb_raise(rb_eSocket, "%s: %s", reason, gai_strerror(error));
+#endif
}
#ifdef _WIN32
diff --git a/test/socket/test_addrinfo.rb b/test/socket/test_addrinfo.rb
index 132d1723806..a06f3eb451b 100644
--- a/test/socket/test_addrinfo.rb
+++ b/test/socket/test_addrinfo.rb
@@ -102,6 +102,14 @@ class TestSocketAddrinfo < Test::Unit::TestCase
assert(!ipv4_ai.unix?)
end
+ def test_error_message
+ e = assert_raise_with_message(SocketError, /getaddrinfo:/) do
+ Addrinfo.ip("...")
+ end
+ m = e.message
+ assert_not_equal([false, Encoding::ASCII_8BIT], [m.ascii_only?, m.encoding], proc {m.inspect})
+ end
+
def test_ipv4_address_predicates
list = [
[:ipv4_private?, "10.0.0.0", "10.255.255.255",