zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an...@apache.org
Subject [zookeeper] branch master updated: ZOOKEEPER-3640: Implement "batch mode" in cli_mt
Date Mon, 06 Jan 2020 12:04:42 GMT
This is an automated email from the ASF dual-hosted git repository.

andor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new d7bc7b1  ZOOKEEPER-3640: Implement "batch mode" in cli_mt
d7bc7b1 is described below

commit d7bc7b135f486f0b91bd7e40b150f39813ef9a9a
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
---
 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);


Mime
View raw message