libgo icon indicating copy to clipboard operation
libgo copied to clipboard

hook getaddrinfo

Open birdwyx opened this issue 6 years ago • 1 comments

与gethostbyname/gethostbyaddr 一样, getaddrinfo也有共用socket问题, 过个协程同时调用getaddrinfo会导致错误 ( 通常会触发FileDescriptorCtx::add_into_reactor 中 assert(false) )。

以下代码可以解决问题,我在一个较老版本libgo上使用正常。若果没有意见的话,我整理一下提交pr? @yyzybb537

int getaddrinfo(const char *__restrict host, const char *__restrict service, const struct addrinfo *__restrict hint, struct addrinfo **__restrict res) { if (!getaddrinfo_f) coroutine_hook_init();

Task* tk = g_Scheduler.GetCurrentTask();
DebugPrint(dbg_hook, "task(%s) hook getaddrinfo(host=%s, service=%s).",
        tk ? tk->DebugInfo() : "nil", host ? host : "", service ? service : "");
		
std::unique_lock<CoMutex> lock(g_dns_getaddrinfo_mtx);
return getaddrinfo_f(host, service, hint, res);

}

birdwyx avatar Oct 22 '18 09:10 birdwyx

OK, 希望可以提交到master分支上

yyzybb537 avatar Oct 22 '18 10:10 yyzybb537