mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
add a callback for mysql auth
This commit is contained in:
13
lualib/mysql.lua
Executable file → Normal file
13
lualib/mysql.lua
Executable file → Normal file
@@ -418,7 +418,7 @@ local function _recv_auth_resp(self)
|
||||
end
|
||||
|
||||
|
||||
local function _mysql_login(self,user,password,database)
|
||||
local function _mysql_login(self,user,password,database,cb)
|
||||
|
||||
return function(sockchannel)
|
||||
local packet, typ, err = sockchannel:response( _recv_decode_packet_resp(self) )
|
||||
@@ -490,7 +490,10 @@ local function _mysql_login(self,user,password,database)
|
||||
local packet_len = #req
|
||||
|
||||
local authpacket=_compose_packet(self,req,packet_len)
|
||||
return sockchannel:request(authpacket,_recv_auth_resp(self))
|
||||
sockchannel:request(authpacket,_recv_auth_resp(self))
|
||||
if cb then
|
||||
cb(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -626,7 +629,7 @@ local function _query_resp(self)
|
||||
end
|
||||
end
|
||||
|
||||
function _M.connect( opts)
|
||||
function _M.connect(opts, cb)
|
||||
|
||||
local self = setmetatable( {}, mt)
|
||||
|
||||
@@ -645,11 +648,11 @@ function _M.connect( opts)
|
||||
local channel = socketchannel.channel {
|
||||
host = opts.host,
|
||||
port = opts.port or 3306,
|
||||
auth = _mysql_login(self,user,password,database ),
|
||||
auth = _mysql_login(self,user,password,database,cb),
|
||||
}
|
||||
self.sockchannel = channel
|
||||
-- try connect first only once
|
||||
channel:connect(true)
|
||||
self.sockchannel = channel
|
||||
|
||||
|
||||
return self
|
||||
|
||||
Reference in New Issue
Block a user