Merge pull request #366 from fztcjjl/master

add a callback for mysql auth
This commit is contained in:
云风
2015-10-28 20:49:44 +08:00
2 changed files with 15 additions and 10 deletions

13
lualib/mysql.lua Executable file → Normal file
View 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,on_connect)
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 on_connect then
on_connect(self)
end
end
end
@@ -626,7 +629,7 @@ local function _query_resp(self)
end
end
function _M.connect( opts)
function _M.connect(opts)
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,opts.on_connect),
}
self.sockchannel = channel
-- try connect first only once
channel:connect(true)
self.sockchannel = channel
return self