Skip to content

Commit

Permalink
Add Socket::ResolutionError & Socket::ResolutionError#error_code
Browse files Browse the repository at this point in the history
Socket::ResolutionError#error_code returns Socket::EAI_XXX
  • Loading branch information
shioimm authored and mame committed Nov 30, 2023
1 parent db7f306 commit e905027
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ext/socket/init.c
Expand Up @@ -27,13 +27,15 @@ VALUE rb_cSocket;
VALUE rb_cAddrinfo;

VALUE rb_eSocket;
VALUE rb_eResolution;

#ifdef SOCKS
VALUE rb_cSOCKSSocket;
#endif

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)
Expand Down Expand Up @@ -772,13 +774,21 @@ 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)
{
/*
* 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();
Expand All @@ -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"));

Expand Down
1 change: 1 addition & 0 deletions ext/socket/rubysocket.h
Expand Up @@ -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;
Expand Down

0 comments on commit e905027

Please sign in to comment.