mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
bugfix: socketchannel auth
This commit is contained in:
@@ -177,6 +177,9 @@ local function connect_backup(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function connect_once(self)
|
local function connect_once(self)
|
||||||
|
if self.__closed then
|
||||||
|
return false
|
||||||
|
end
|
||||||
assert(not self.__sock and not self.__authcoroutine)
|
assert(not self.__sock and not self.__authcoroutine)
|
||||||
local fd = socket.open(self.__host, self.__port)
|
local fd = socket.open(self.__host, self.__port)
|
||||||
if not fd then
|
if not fd then
|
||||||
@@ -185,29 +188,29 @@ local function connect_once(self)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
while not self.__closed do
|
|
||||||
|
self.__sock = setmetatable( {fd} , channel_socket_meta )
|
||||||
|
skynet.fork(dispatch_function(self), self)
|
||||||
|
|
||||||
|
if self.__auth then
|
||||||
self.__authcoroutine = coroutine.running()
|
self.__authcoroutine = coroutine.running()
|
||||||
self.__sock = setmetatable( {fd} , channel_socket_meta )
|
local ok , message = pcall(self.__auth, self)
|
||||||
skynet.fork(dispatch_function(self), self)
|
if not ok then
|
||||||
|
close_channel_socket(self)
|
||||||
if self.__auth then
|
if message ~= socket_error then
|
||||||
local ok , message = pcall(self.__auth, self)
|
skynet.error("socket: auth failed", message)
|
||||||
if not ok then
|
|
||||||
close_channel_socket(self)
|
|
||||||
if message ~= socket_error then
|
|
||||||
skynet.error("socket: auth failed", message)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
self.__authcoroutine = false
|
|
||||||
return ok
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self.__authcoroutine = false
|
self.__authcoroutine = false
|
||||||
if self.__sock then
|
if self.__sock then
|
||||||
return true
|
return ok
|
||||||
|
else
|
||||||
|
-- auth may change host, so connect again
|
||||||
|
return connect_once(self)
|
||||||
end
|
end
|
||||||
-- auth may change host, so connect again
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function try_connect(self , once)
|
local function try_connect(self , once)
|
||||||
|
|||||||
Reference in New Issue
Block a user