在访问zookeeper句柄时取消引用指向不完整类型的指针

时间:2016-03-17 05:26:15

标签: c apache-zookeeper

我是ZooKeeper的新手。我的代码非常简单,如下所示。但是,当我想获取zookeeper句柄的文件描述符时,我得到了错误dereferencing pointer to incomplete type

#include <stdio.h>
#include "zookeeper.h"

static zhandle_t *zh;
typedef struct String_vector zoo_string;

void my_watcher_func(zhandle_t *zzh, int type, int state, const char *path, void watcherCtx()) {}

int main(int argc, char *argv[]) {
    int i, retval;
    char *host_port = "localhost:2191";
    char *zoo_root = "/";
    zoo_string *children_list = (zoo_string *)malloc(sizeof(zoo_string));

    zh = zookeeper_init(host_port, my_watcher_func, 2000, 0, NULL, 0);
    if (zh == NULL) {
        fprintf(stderr, "Error connecting to zookeeper server!\n");
        exit(EXIT_FAILURE);
    }

    retval = zoo_get_children(zh, zoo_root, 0, children_list);
    if (retval != ZOK) {
        fprintf(stderr, "Error retrieving znode from path %s!\n", zoo_root);
        exit(EXIT_FAILURE);
    }

    fprintf(stderr, "\n=== znode string === [ %s ]\n", zoo_root);
    for (i = 0; i < children_list->count; ++i) {
        fprintf(stderr, "\n(%d): %s\n", i + 1, children_list->data[i]);
    }
    fprintf(stderr, "\n=== done ===\n");
    fprintf(stderr, "%d\n", zh->fd); //error

    zookeeper_close(zh);
    return 0;
}

0 个答案:

没有答案