diff options
author | Yusuke Endoh <[email protected]> | 2023-10-18 18:48:29 +0900 |
---|---|---|
committer | Yusuke Endoh <[email protected]> | 2023-10-24 12:22:53 +0900 |
commit | 3dc311bdc8badb680267f5a10e0c467ddd9dfe4c () | |
tree | d1a853baf41ec43fdc28bf4653881850e7f5fe3a /ext/socket/raddrinfo.c | |
parent | efd58f19ea473ac34d27658997eee6af3521e1d9 (diff) |
Make rb_getaddrinfo interruptible
When pthread_create is available, rb_getaddrinfo creates a pthread and executes getaddrinfo(3) in it. The caller thread waits for the pthread to complete, but detaches it if interrupted. This allows name resolution to be interuppted by Timeout.timeout, etc. even if it takes a long time (for example, when the DNS server does not respond). [Feature #19965]
-rw-r--r-- | ext/socket/raddrinfo.c | 186 |
1 files changed, 184 insertions, 2 deletions
@@ -12,12 +12,17 @@ // GETADDRINFO_IMPL == 0 : call getaddrinfo/getnameinfo directly // GETADDRINFO_IMPL == 1 : call getaddrinfo/getnameinfo without gvl (but uncancellable) #ifndef GETADDRINFO_IMPL # ifdef GETADDRINFO_EMU # define GETADDRINFO_IMPL 0 -# else # define GETADDRINFO_IMPL 1 # endif #endif @@ -333,6 +338,183 @@ rb_getaddrinfo(const char *hostp, const char *portp, const struct addrinfo *hint return (int)(VALUE)rb_thread_call_without_gvl(nogvl_getaddrinfo, &arg, RUBY_UBF_IO, 0); } #endif #if GETADDRINFO_IMPL == 0 @@ -345,7 +527,7 @@ rb_getnameinfo(const struct sockaddr *sa, socklen_t salen, return getnameinfo(sa, salen, host, hostlen, serv, servlen, flags); } -#elif GETADDRINFO_IMPL == 1 struct getnameinfo_arg { |