function _M.connect()

in lib/shenyu/register/zookeeper/zk_client.lua [42:79]


function _M.connect(self, host)
    
    local conn = self.conn
    
    local iptables = util.paras_host(host, ":")
    local ip = iptables[1]
    local port = iptables[2]
    local byt = conn:connect(ip, port)
    if not byt then
        return nil, "connection error" .. host
    end
    local bytes = proto:serialize(proto.request_header, proto.connect_request)
    local b, err = conn:write(bytes)
    if not b then
        return nil, "connection error " .. ip + ":" .. port
    end
    local len = conn:read_len()
    if not len then
        return nil, "error"
    end
    local bytes = conn:read(len)
    if not bytes then
        return nil, "connection read error"
    end
    local rsp = proto.connect_response:unpack(bytes, 1)
    if not rsp then
        return nil, "read connection response error"
    end
    self.xid = 0
    local t = rsp.timeout
    self.session_timeout = rsp.timeout
    self.ping_time = (t / 3) / 1000
    self.host = host
    self.session_id = rsp.session_id
    local tostring = "proto_ver:" .. rsp.proto_ver .. "," .. "timeout:" .. rsp.timeout .. "," .. "session_id:" .. util.long_to_hex_string(rsp.session_id)
    ngx_log(ngx.INFO, tostring)
    return true, nil
end