#include "xs.h" #include #include #include int main(void) { const char path[] = "/tool/test"; struct xs_handle *xs; xs_transaction_t th; int fd_q; int num, len; char **vec, *buf; fd_set set_q; xs = xs_daemon_open(); printf("xs: %p\n", xs); th = xs_transaction_start(xs); xs_write(xs, th, path, "init", strlen("init")); xs_transaction_end(xs, th, 0); xs_watch(xs, path, "commandee"); fd_q = xs_fileno(xs); while(1){ struct timeval tv = {.tv_sec=1, .tv_usec=0}; FD_ZERO(&set_q); FD_SET(fd_q, &set_q); if(select(fd_q + 1, &set_q, NULL, NULL, &tv) > 0 && FD_ISSET(fd_q, &set_q)) { vec = xs_read_watch(xs, &num); if(vec != NULL){ th = xs_transaction_start(xs); buf = xs_read(xs, th, vec[XS_WATCH_PATH], &len); xs_transaction_end(xs, th, 0); printf("Got %s\n", buf); if(!strstr(buf, "_done")) { char *fu; printf("Wrote Response\n"); th = xs_transaction_start(xs); asprintf(&fu, "%s_done", buf); xs_write(xs, th, path, fu, strlen(fu)); free(fu); xs_transaction_end(xs, th, 0); } free(buf); free(vec); } } } xs_unwatch(xs, path, "commandee"); }