diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2023-10-18 15:51:49 +0900 |
---|---|---|
committer | Yusuke Endoh <mame@ruby-lang.org> | 2023-10-24 12:22:53 +0900 |
commit | 9ce607a8d4944de3ebda23d7879bb60fa74121f0 (patch) | |
tree | 84f725e3618b5f94307dee93b16aca308bc6f7fc /ext/socket | |
parent | 30f5a2bbcd0151ce25b1e55dcff31626d4ab253a (diff) |
refactor a call to getaddrinfo
Diffstat (limited to 'ext/socket')
-rw-r--r-- | ext/socket/raddrinfo.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c index 12d086ef37..d267274e2d 100644 --- a/ext/socket/raddrinfo.c +++ b/ext/socket/raddrinfo.c @@ -302,6 +302,22 @@ rb_freeaddrinfo(struct rb_addrinfo *ai) xfree(ai); } +static int +rb_getaddrinfo(const char *hostp, const char *portp, const struct addrinfo *hints, struct addrinfo **ai) +{ +#ifdef GETADDRINFO_EMU + return getaddrinfo(hostp, portp, hints, ai); +#else + struct getaddrinfo_arg arg; + MEMZERO(&arg, struct getaddrinfo_arg, 1); + arg.node = hostp; + arg.service = portp; + arg.hints = hints; + arg.res = ai; + return (int)(VALUE)rb_thread_call_without_gvl(nogvl_getaddrinfo, &arg, RUBY_UBF_IO, 0); +#endif +} + #ifndef GETADDRINFO_EMU struct getnameinfo_arg { @@ -550,17 +566,7 @@ rsock_getaddrinfo(VALUE host, VALUE port, struct addrinfo *hints, int socktype_h } if (!resolved) { -#ifdef GETADDRINFO_EMU - error = getaddrinfo(hostp, portp, hints, &ai); -#else - struct getaddrinfo_arg arg; - MEMZERO(&arg, struct getaddrinfo_arg, 1); - arg.node = hostp; - arg.service = portp; - arg.hints = hints; - arg.res = &ai; - error = (int)(VALUE)rb_thread_call_without_gvl(nogvl_getaddrinfo, &arg, RUBY_UBF_IO, 0); -#endif + error = rb_getaddrinfo(hostp, portp, hints, &ai); if (error == 0) { res = (struct rb_addrinfo *)xmalloc(sizeof(struct rb_addrinfo)); res->allocated_by_malloc = 0; |