refactor a call to getaddrinfo

This commit is contained in:
Yusuke Endoh 2023-10-18 15:51:49 +09:00
parent 30f5a2bbcd
commit 9ce607a8d4

View File

@ -302,6 +302,22 @@ rb_freeaddrinfo(struct rb_addrinfo *ai)
xfree(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 #ifndef GETADDRINFO_EMU
struct getnameinfo_arg struct getnameinfo_arg
{ {
@ -550,17 +566,7 @@ rsock_getaddrinfo(VALUE host, VALUE port, struct addrinfo *hints, int socktype_h
} }
if (!resolved) { if (!resolved) {
#ifdef GETADDRINFO_EMU error = rb_getaddrinfo(hostp, portp, hints, &ai);
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
if (error == 0) { if (error == 0) {
res = (struct rb_addrinfo *)xmalloc(sizeof(struct rb_addrinfo)); res = (struct rb_addrinfo *)xmalloc(sizeof(struct rb_addrinfo));
res->allocated_by_malloc = 0; res->allocated_by_malloc = 0;