mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
add a callback for mysql auth
This commit is contained in:
@@ -418,7 +418,7 @@ local function _recv_auth_resp(self)
|
||||
end
|
||||
|
||||
|
||||
local function _mysql_login(self,user,password,database,cb)
|
||||
local function _mysql_login(self,user,password,database,on_connect)
|
||||
|
||||
return function(sockchannel)
|
||||
local packet, typ, err = sockchannel:response( _recv_decode_packet_resp(self) )
|
||||
@@ -491,8 +491,8 @@ local function _mysql_login(self,user,password,database,cb)
|
||||
|
||||
local authpacket=_compose_packet(self,req,packet_len)
|
||||
sockchannel:request(authpacket,_recv_auth_resp(self))
|
||||
if cb then
|
||||
cb(self)
|
||||
if on_connect then
|
||||
on_connect(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -629,7 +629,7 @@ local function _query_resp(self)
|
||||
end
|
||||
end
|
||||
|
||||
function _M.connect(opts, cb)
|
||||
function _M.connect(opts)
|
||||
|
||||
local self = setmetatable( {}, mt)
|
||||
|
||||
@@ -648,7 +648,7 @@ function _M.connect(opts, cb)
|
||||
local channel = socketchannel.channel {
|
||||
host = opts.host,
|
||||
port = opts.port or 3306,
|
||||
auth = _mysql_login(self,user,password,database,cb),
|
||||
auth = _mysql_login(self,user,password,database,opts.on_connect),
|
||||
}
|
||||
self.sockchannel = channel
|
||||
-- try connect first only once
|
||||
|
||||
@@ -70,14 +70,18 @@ local function test3( db)
|
||||
end
|
||||
skynet.start(function()
|
||||
|
||||
local function on_connect(db)
|
||||
db:query("set charset utf8");
|
||||
end
|
||||
local db=mysql.connect({
|
||||
host="127.0.0.1",
|
||||
port=3306,
|
||||
database="skynet",
|
||||
user="root",
|
||||
password="1",
|
||||
max_packet_size = 1024 * 1024
|
||||
}, function(db) db:query("set charset utf8") end)
|
||||
max_packet_size = 1024 * 1024,
|
||||
on_connect = on_connect
|
||||
})
|
||||
if not db then
|
||||
print("failed to connect")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user