From f0ac66787eb5ade795dd919140390ffb62ef6b36 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Wed, 23 Dec 2015 20:22:46 +0800 Subject: [PATCH] socket channel connect should wait for last closing --- lualib/socketchannel.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lualib/socketchannel.lua b/lualib/socketchannel.lua index 7a9b74fc..cf918645 100644 --- a/lualib/socketchannel.lua +++ b/lualib/socketchannel.lua @@ -81,6 +81,10 @@ local function exit_thread(self) local co = coroutine.running() if self.__dispatch_thread == co then self.__dispatch_thread = nil + local connecting = self.__connecting_thread + if connecting then + skynet.wakeup(connecting) + end end end @@ -332,6 +336,14 @@ end function channel:connect(once) if self.__closed then + if self.__dispatch_thread then + -- closing, wait + assert(self.__connecting_thread == nil, "already connecting") + local co = coroutine.running() + self.__connecting_thread = co + skynet.wait(co) + self.__connecting_thread = nil + end self.__closed = false end