diff options
author | Damien Diederen <dd@crosstwine.com> | 2020-01-06 13:04:35 +0100 |
---|---|---|
committer | Andor Molnar <andor@apache.org> | 2020-01-06 13:04:35 +0100 |
commit | d7bc7b135f486f0b91bd7e40b150f39813ef9a9a (patch) | |
tree | eef3f870acf8802825b054c88ae9714fa16c69e3 /zookeeper-client | |
parent | c585f4b5005e4bda825a796de6251f16f3fe4dba (diff) | |
download | zookeeper-d7bc7b135f486f0b91bd7e40b150f39813ef9a9a.tar.gz |
ZOOKEEPER-3640: Implement "batch mode" in cli_mt
Batch mode never was implemented in `cli_mt`. This patch seems to work, but:
1. There may be a cleaner way of waiting for the completion;
2. ~~`nanosleep` is POSIX; the Windows path should probably use `Sleep`~~ (DONE).
symat: Comments welcome.
Author: Damien Diederen <dd@crosstwine.com>
Reviewers: andor@apache.org
Closes #1173 from ztzg/ZOOKEEPER-3640-implement-batch-mode-in-cli-mt
Diffstat (limited to 'zookeeper-client')
-rw-r--r-- | zookeeper-client/zookeeper-client-c/src/cli.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/zookeeper-client/zookeeper-client-c/src/cli.c b/zookeeper-client/zookeeper-client-c/src/cli.c index b2314345a..34f2b99ef 100644 --- a/zookeeper-client/zookeeper-client-c/src/cli.c +++ b/zookeeper-client/zookeeper-client-c/src/cli.c @@ -736,6 +736,19 @@ int handleBatchMode(const char* arg, const char** buf) { return 1; } +#ifdef THREADED +static void millisleep(int ms) { +#ifdef WIN32 + Sleep(ms); +#else /* !WIN32 */ + struct timespec ts; + ts.tv_sec = ms / 1000; + ts.tv_nsec = (ms % 1000) * 1000000; // to nanoseconds + nanosleep(&ts, NULL); +#endif /* WIN32 */ +} +#endif /* THREADED */ + int main(int argc, char **argv) { static struct option long_options[] = { {"host", required_argument, NULL, 'h'}, //hostPort @@ -896,9 +909,17 @@ int main(int argc, char **argv) { #endif #ifdef THREADED + if (batchMode) { + processline(cmd); + } while(!shutdownThisThing) { - int rc; - int len = sizeof(buffer) - bufoff -1; + int rc, len; + if (batchMode) { + // We are just waiting for the asynchronous command to complete. + millisleep(10); + continue; + } + len = sizeof(buffer) - bufoff -1; if (len <= 0) { fprintf(stderr, "Can't handle lines that long!\n"); exit(2); |