function _M._get_children()

in lib/shenyu/register/zookeeper/zk_client.lua [85:126]


function _M._get_children(self, path, is_watch)
    local conn = self.conn
    if not conn then
        return nil, "not initialized connection"
    end
    local xid = self.xid + 1
    local h = proto.request_header
    h.xid = xid
    h.type = const.ZOO_GET_CHILDREN
    local r = proto.get_children_request
    r.path = path
    r.watch = is_watch
    local req = proto:serialize(h, r)
    local bytes, err = conn:write(req)
    if not bytes then
        return bytes, "write bytes error"
    end
    
    :: continue ::
    local rsp_header, bytes, end_index = conn:read_header()
    if not rsp_header then
        return nil, "read headler error"
    end
    if rsp_header.err ~= 0 then
        ngx_log(ngx.ERR, "zookeeper remote error: " .. const.get_err_msg(rsp_header.err) .. "," .. path)
        return nil, const.get_err_msg(rsp_header.err)
    end
    if strlen(bytes) > 16 and rsp_header.xid > 0 then
        self.xid = rsp_header.xid + 1
        local get_children_response = proto.get_children_response:unpack(bytes, end_index)
        return {
            xid = rsp_header.xid,
            zxid = rsp_header.zxid,
            path = get_children_response.paths
        }
    end
    if rsp_header.xid == const.XID_PING then
        goto
        continue
    end
    return nil, "get_children error"
end