diff options
author | Misaki Shioi <shioi.mm@gmail.com> | 2023-11-23 16:30:37 +0900 |
---|---|---|
committer | Yusuke Endoh <mame@ruby-lang.org> | 2023-11-30 13:27:19 +0900 |
commit | e9050270d7d8b1bc6be2c1352772b906031adc6e (patch) | |
tree | ad9010b88a9910763343381c7e584cf4e33e6a5f /ext/socket | |
parent | db7f3064a8fce5a59e4ed0565273d8d43e27d52c (diff) |
Add Socket::ResolutionError & Socket::ResolutionError#error_code
Socket::ResolutionError#error_code returns Socket::EAI_XXX
Diffstat (limited to 'ext/socket')
-rw-r--r-- | ext/socket/init.c | 12 | ||||
-rw-r--r-- | ext/socket/rubysocket.h | 1 |
2 files changed, 13 insertions, 0 deletions
diff --git a/ext/socket/init.c b/ext/socket/init.c index e9dc6f8483..5ca0cdbb1d 100644 --- a/ext/socket/init.c +++ b/ext/socket/init.c @@ -27,6 +27,7 @@ VALUE rb_cSocket; VALUE rb_cAddrinfo; VALUE rb_eSocket; +VALUE rb_eResolution; #ifdef SOCKS VALUE rb_cSOCKSSocket; @@ -34,6 +35,7 @@ VALUE rb_cSOCKSSocket; int rsock_do_not_reverse_lookup = 1; static VALUE sym_wait_readable; +static ID id_error_code; void rsock_raise_socket_error(const char *reason, int error) @@ -772,6 +774,12 @@ rsock_getfamily(rb_io_t *fptr) return ss.addr.sa_family; } +static VALUE +sock_resolv_error_code(VALUE self) +{ + return rb_attr_get(self, id_error_code); +} + void rsock_init_socket_init(void) { @@ -779,6 +787,8 @@ rsock_init_socket_init(void) * SocketError is the error class for socket. */ rb_eSocket = rb_define_class("SocketError", rb_eStandardError); + rb_eResolution = rb_define_class_under(rb_cSocket, "ResolutionError", rb_eSocket); + rb_define_method(rb_eResolution, "error_code", sock_resolv_error_code, 0); rsock_init_ipsocket(); rsock_init_tcpsocket(); rsock_init_tcpserver(); @@ -792,6 +802,8 @@ rsock_init_socket_init(void) rsock_init_sockifaddr(); rsock_init_socket_constants(); + id_error_code = rb_intern_const("error_code"); + #undef rb_intern sym_wait_readable = ID2SYM(rb_intern("wait_readable")); diff --git a/ext/socket/rubysocket.h b/ext/socket/rubysocket.h index 7c5739808d..24e20efef1 100644 --- a/ext/socket/rubysocket.h +++ b/ext/socket/rubysocket.h @@ -285,6 +285,7 @@ extern VALUE rb_cAddrinfo; extern VALUE rb_cSockOpt; extern VALUE rb_eSocket; +extern VALUE rb_eResolution; #ifdef SOCKS extern VALUE rb_cSOCKSSocket; |