You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by an...@apache.org on 2020/01/06 12:04:53 UTC
[zookeeper] branch branch-3.6 updated: ZOOKEEPER-3640: Implement
"batch mode" in cli_mt
This is an automated email from the ASF dual-hosted git repository.
andor pushed a commit to branch branch-3.6
in repository https://gitbox.apache.org/repos/asf/zookeeper.git
The following commit(s) were added to refs/heads/branch-3.6 by this push:
new d01dac1 ZOOKEEPER-3640: Implement "batch mode" in cli_mt
d01dac1 is described below
commit d01dac1fc4983fdde60dee64f0dd2b083a4e6bf2
Author: Damien Diederen <dd...@crosstwine.com>
AuthorDate: Mon Jan 6 13:04:35 2020 +0100
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
(cherry picked from commit d7bc7b135f486f0b91bd7e40b150f39813ef9a9a)
Signed-off-by: Andor Molnar <an...@apache.org>
---
zookeeper-client/zookeeper-client-c/src/cli.c | 25 +++++++++++++++++++++++--
1 file 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 b231434..34f2b99 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);