bugfix : handshake error handle

This commit is contained in:
Cloud Wu
2019-01-12 00:08:57 +08:00
committed by 云风
parent 304272249e
commit 68c3762abf

View File

@@ -363,35 +363,25 @@ local function _recv_field_packet(self, sock)
end end
local function _recv_decode_packet_resp(self) local function _recv_decode_packet_resp(self)
return function(sock)
-- don't return more than 2 results
return true, (_recv_packet(self,sock))
end
end
local function _recv_auth_resp(self)
return function(sock) return function(sock)
local packet, typ, err = _recv_packet(self,sock) local packet, typ, err = _recv_packet(self,sock)
if not packet then if not packet then
--print("recv auth resp : failed to receive the result packet") return false, "failed to receive the result packet"..err
error ("failed to receive the result packet"..err)
--return nil,err
end end
if typ == 'ERR' then if typ == 'ERR' then
local errno, msg, sqlstate = _parse_err_packet(packet) local errno, msg, sqlstate = _parse_err_packet(packet)
error( strformat("errno:%d, msg:%s,sqlstate:%s",errno,msg,sqlstate)) return false, strformat("errno:%d, msg:%s,sqlstate:%s",errno,msg,sqlstate)
--return nil, errno,msg, sqlstate
end end
if typ == 'EOF' then if typ == 'EOF' then
error "old pre-4.1 authentication protocol not supported" return false, "old pre-4.1 authentication protocol not supported"
end end
if typ ~= 'OK' then if typ ~= 'OK' then
error "bad packet type: " return false, "bad packet type: "
end end
return true, true return true, packet
end end
end end
@@ -399,16 +389,8 @@ end
local function _mysql_login(self,user,password,database,on_connect) local function _mysql_login(self,user,password,database,on_connect)
return function(sockchannel) return function(sockchannel)
local packet, typ, err = sockchannel:response( _recv_decode_packet_resp(self) ) local dispatch_resp = _recv_decode_packet_resp(self)
--local aat={} local packet = sockchannel:response( dispatch_resp )
if not packet then
error( err )
end
if typ == "ERR" then
local errno, msg, sqlstate = _parse_err_packet(packet)
error( strformat("errno:%d, msg:%s,sqlstate:%s",errno,msg,sqlstate))
end
self.protocol_ver = strbyte(packet) self.protocol_ver = strbyte(packet)
@@ -468,7 +450,7 @@ local function _mysql_login(self,user,password,database,on_connect)
local packet_len = #req local packet_len = #req
local authpacket=_compose_packet(self,req,packet_len) local authpacket=_compose_packet(self,req,packet_len)
sockchannel:request(authpacket,_recv_auth_resp(self)) sockchannel:request(authpacket, dispatch_resp)
if on_connect then if on_connect then
on_connect(self) on_connect(self)
end end