Skip to content

Commit

Permalink
ZOOKEEPER-3640: Implement "batch mode" in cli_mt
Browse files Browse the repository at this point in the history
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 apache#1173 from ztzg/ZOOKEEPER-3640-implement-batch-mode-in-cli-mt
  • Loading branch information
ztzg authored and anmolnar committed Jan 6, 2020
1 parent c585f4b commit d7bc7b1
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions zookeeper-client/zookeeper-client-c/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d7bc7b1

Please sign in to comment.