Created
January 28, 2014 21:35
-
-
Save rgs1/8677009 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc -Wall -I/usr/include/zookeeper -lzookeeper_mt get.c -o get | |
#include <errno.h> | |
#include <pthread.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <unistd.h> | |
#include "zookeeper.h" | |
void watcher(zhandle_t *, int, int, const char *, void *); | |
void log_msg(const char *msg) { | |
printf("%s\n", msg); | |
} | |
void error(const char *msg, int rc) { | |
printf("%s\n", msg); | |
exit(rc); | |
} | |
void watcher(zhandle_t *zzh, int type, int state, const char *path, | |
void *watcherCtx) { | |
printf("watcher has state = %d\n", state); | |
} | |
int main(int argc, char **argv) | |
{ | |
char *host, *path; | |
char buf[1024]; | |
zhandle_t *zh; | |
int len = 1024; | |
if (argc != 3) | |
error("Gimme host/path", 1); | |
host = argv[1]; | |
path = argv[2]; | |
zh = zookeeper_init(host, watcher, 1000, 0, 0, 0); | |
if (!zh) | |
error("Failed to connect", errno); | |
while (zoo_state(zh) != ZOO_CONNECTED_STATE) { | |
sleep(1); | |
} | |
zoo_get(zh, path, 0, buf, &len, NULL); | |
printf("%s\n", buf); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment