diff options
author | Samuel Williams <[email protected]> | 2021-06-14 16:21:08 +1200 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-14 16:21:08 +1200 |
commit | 2792acc8f29c6ee1d04b57b7b70d43519a0ceda8 (patch) | |
tree | f34d853b85cac91a51cb2500c9c4b765433e3672 /ext/socket/socket.c | |
parent | 688b217706546c2bc9a0926de246dc29d0935261 (diff) |
Add scheduler hook `Addrinfo.getaddrinfo`. (#4375)
Co-authored-by: Bruno Sutic <[email protected]>
Notes
Notes:
Merged-By: ioquatix <[email protected]>
Diffstat (limited to 'ext/socket/socket.c')
-rw-r--r-- | ext/socket/socket.c | 32 |
1 files changed, 1 insertions, 31 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c index bebddd9e2b..09e8f2f00b 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -1279,34 +1279,10 @@ sock_s_getnameinfo(int argc, VALUE *argv, VALUE _) rb_raise(rb_eArgError, "array size should be 3 or 4, %ld given", RARRAY_LEN(sa)); } - /* host */ - if (NIL_P(host)) { - hptr = NULL; - } - else { - strncpy(hbuf, StringValueCStr(host), sizeof(hbuf)); - hbuf[sizeof(hbuf) - 1] = '\0'; - hptr = hbuf; - } - /* port */ - if (NIL_P(port)) { - strcpy(pbuf, "0"); - pptr = NULL; - } - else if (FIXNUM_P(port)) { - snprintf(pbuf, sizeof(pbuf), "%ld", NUM2LONG(port)); - pptr = pbuf; - } - else { - strncpy(pbuf, StringValueCStr(port), sizeof(pbuf)); - pbuf[sizeof(pbuf) - 1] = '\0'; - pptr = pbuf; - } hints.ai_socktype = (fl & NI_DGRAM) ? SOCK_DGRAM : SOCK_STREAM; /* af */ hints.ai_family = NIL_P(af) ? PF_UNSPEC : rsock_family_arg(af); - error = rb_getaddrinfo(hptr, pptr, &hints, &res); - if (error) goto error_exit_addr; + res = rsock_getaddrinfo(host, port, &hints, 0); sap = res->ai->ai_addr; salen = res->ai->ai_addrlen; } @@ -1336,12 +1312,6 @@ sock_s_getnameinfo(int argc, VALUE *argv, VALUE _) } return rb_assoc_new(rb_str_new2(hbuf), rb_str_new2(pbuf)); - error_exit_addr: - saved_errno = errno; - if (res) rb_freeaddrinfo(res); - errno = saved_errno; - rsock_raise_socket_error("getaddrinfo", error); - error_exit_name: saved_errno = errno; if (res) rb_freeaddrinfo(res); |