diff options
author | Samuel Williams <[email protected]> | 2021-06-14 16:21:08 +1200 |
---|---|---|
committer | <[email protected]> | 2021-06-14 16:21:08 +1200 |
commit | 2792acc8f29c6ee1d04b57b7b70d43519a0ceda8 () | |
tree | f34d853b85cac91a51cb2500c9c4b765433e3672 /ext/socket/raddrinfo.c | |
parent | 688b217706546c2bc9a0926de246dc29d0935261 (diff) |
Add scheduler hook `Addrinfo.getaddrinfo`. (#4375)
Co-authored-by: Bruno Sutic <[email protected]>
Notes: Merged-By: ioquatix <[email protected]>
-rw-r--r-- | ext/socket/raddrinfo.c | 125 |
1 files changed, 89 insertions, 36 deletions
@@ -284,40 +284,6 @@ numeric_getaddrinfo(const char *node, const char *service, return EAI_FAIL; } -int -rb_getaddrinfo(const char *node, const char *service, - const struct addrinfo *hints, - struct rb_addrinfo **res) -{ - struct addrinfo *ai; - int ret; - int allocated_by_malloc = 0; - - ret = numeric_getaddrinfo(node, service, hints, &ai); - if (ret == 0) - allocated_by_malloc = 1; - else { -#ifdef GETADDRINFO_EMU - ret = getaddrinfo(node, service, hints, &ai); -#else - struct getaddrinfo_arg arg; - MEMZERO(&arg, struct getaddrinfo_arg, 1); - arg.node = node; - arg.service = service; - arg.hints = hints; - arg.res = &ai; - ret = (int)(VALUE)rb_thread_call_without_gvl(nogvl_getaddrinfo, &arg, RUBY_UBF_IO, 0); -#endif - } - - if (ret == 0) { - *res = (struct rb_addrinfo *)xmalloc(sizeof(struct rb_addrinfo)); - (*res)->allocated_by_malloc = allocated_by_malloc; - (*res)->ai = ai; - } - return ret; -} - void rb_freeaddrinfo(struct rb_addrinfo *ai) { @@ -498,12 +464,63 @@ port_str(VALUE port, char *pbuf, size_t pbuflen, int *flags_ptr) } } struct rb_addrinfo* rsock_getaddrinfo(VALUE host, VALUE port, struct addrinfo *hints, int socktype_hack) { struct rb_addrinfo* res = NULL; char *hostp, *portp; - int error; char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV]; int additional_flags = 0; @@ -515,7 +532,43 @@ rsock_getaddrinfo(VALUE host, VALUE port, struct addrinfo *hints, int socktype_h } hints->ai_flags |= additional_flags; - error = rb_getaddrinfo(hostp, portp, hints, &res); if (error) { if (hostp && hostp[strlen(hostp)-1] == '\n') { rb_raise(rb_eSocket, "newline at the end of hostname"); |