-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathmulti_watch.c
46 lines (38 loc) · 1.22 KB
/
multi_watch.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "../cetcd.h"
#include <signal.h>
#include <unistd.h>
int quit = 0;
void sighandler(int sig) {
quit = 1;
}
int watch(void *userdata, cetcd_response *resp) {
cetcd_response_print(resp);
return 0;
}
int main(int argc, char *argv[]) {
cetcd_client cli;
cetcd_array addrs;
cetcd_array watchers;
cetcd_watch_id wid;
/*initialize the address array*/
cetcd_array_init(&addrs, 3);
/*append the address of etcd*/
cetcd_array_append(&addrs, "http://127.0.0.1:2379");
/*initialize the cetcd_client*/
cetcd_client_init(&cli, &addrs);
//cli.settings.verbose = 1;
signal(SIGINT, sighandler);
cetcd_array_init(&watchers, 3);
cetcd_add_watcher(&watchers, cetcd_watcher_create(&cli, "/test/watch", 0, 1, 1, watch, NULL));
cetcd_add_watcher(&watchers, cetcd_watcher_create(&cli, "/test/watch", 0, 1, 1, watch, NULL));
cetcd_add_watcher(&watchers, cetcd_watcher_create(&cli, "/test/watch", 0, 1, 1, watch, NULL));
wid = cetcd_multi_watch_async(&cli, &watchers);
while(!quit) {
usleep(10000);
}
cetcd_multi_watch_async_stop(&cli, wid);
cetcd_client_destroy(&cli);
cetcd_array_destroy(&addrs);
cetcd_array_destroy(&watchers);
return 0;
}