summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMisaki Shioi <[email protected]>2024-12-23 15:05:00 +0900
committerGitHub <[email protected]>2024-12-23 15:05:00 +0900
commit34e6bb48af2814eefd91968c58c1dede3b56f30e (patch)
tree02997aea6874fe176c0e30e92a3126e0e5559e10
parentf2d1c3d3ce80e895b3295443c6bd3d63647d7d04 (diff)
Improve doc for `Socket::ResolutionError` (#12434)
Also, a topic about Socket::ResolutionError is added to NEWS
Notes
Notes: Merged-By: shioimm <[email protected]>
-rw-r--r--NEWS.md5
-rw-r--r--ext/socket/init.c14
2 files changed, 17 insertions, 2 deletions
diff --git a/NEWS.md b/NEWS.md
index 747ad65bae..8139ed9bbe 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -173,6 +173,11 @@ We only list stdlib changes that are notable feature changes.
* This library is now extracted from the Ruby repository to [ruby/net-http-sspi].
[[Feature #20775]]
+* Socket
+
+ * Socket::ResolutionError and Socket::ResolutionError#error_code was added.
+ [[Feature #20018]]
+
Other changes are listed in the following sections. we also listed release history from the previous bundled version that is Ruby 3.3.0 if it has GitHub releases.
The following default gem is added.
diff --git a/ext/socket/init.c b/ext/socket/init.c
index 83af8c5b0e..8e405609ba 100644
--- a/ext/socket/init.c
+++ b/ext/socket/init.c
@@ -786,7 +786,17 @@ rsock_getfamily(rb_io_t *fptr)
* call-seq:
* error_code -> integer
*
- * Returns the raw error code occurred at name resolution.
+ * Returns the raw error code indicating the cause of the hostname resolution failure.
+ *
+ * begin
+ * Addrinfo.getaddrinfo("ruby-lang.org", nil)
+ * rescue Socket::ResolutionError => e
+ * if e.error_code == Socket::EAI_AGAIN
+ * puts "Temporary failure in name resolution."
+ * end
+ * end
+ *
+ * Note that error codes depend on the operating system.
*/
static VALUE
sock_resolv_error_code(VALUE self)
@@ -802,7 +812,7 @@ rsock_init_socket_init(void)
*/
rb_eSocket = rb_define_class("SocketError", rb_eStandardError);
/*
- * ResolutionError is the error class for socket name resolution.
+ * Socket::ResolutionError is the error class for hostname resolution.
*/
rb_eResolution = rb_define_class_under(rb_cSocket, "ResolutionError", rb_eSocket);
rb_define_method(rb_eResolution, "error_code", sock_resolv_error_code, 0);