diff options
author | antirez <antirez@gmail.com> | 2015-11-12 08:48:59 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2015-11-17 15:43:22 +0100 |
commit | e386cd8ccf9698a8218208e75528a460cb4cc277 (patch) | |
tree | f9ac7562deb8caf947c9e0711c2350286bb1111b | |
parent | 7492237c3ce377f7d8983b6a2943808cf05c1bea (diff) | |
download | redis-e386cd8ccf9698a8218208e75528a460cb4cc277.tar.gz |
Lua debugger: clear end of session protocol.
When the debugger exits now it produces an <endsession> tag that informs
redis-cli (or other debugging clients) that the session terminated.
This way the client knows there is yet another reply to read (the one of
the EVAL script itself), and can switch to non-debugging mode ASAP.
-rw-r--r-- | src/redis-cli.c | 28 | ||||
-rw-r--r-- | src/scripting.c | 4 |
2 files changed, 23 insertions, 9 deletions
diff --git a/src/redis-cli.c b/src/redis-cli.c index e620da943..67b707ad5 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -112,6 +112,7 @@ static struct config { char prompt[128]; char *eval; int eval_ldb; + int eval_ldb_end; int last_cmd_type; } config; @@ -377,14 +378,6 @@ static int cliConnect(int force) { if (context == NULL || force) { if (context != NULL) { redisFree(context); - /* Disconnection from the server signals end of EVAL - * debugging session. */ - if (config.eval_ldb) { - printf("\n(Lua debugging session terminated)\n\n"); - config.eval_ldb = 0; - config.output = OUTPUT_STANDARD; - cliRefreshPrompt(); - } } if (config.hostsocket == NULL) { @@ -553,7 +546,16 @@ static sds cliFormatReplyRaw(redisReply *r) { /* The Lua debugger replies with arrays of simple (status) * strings. We colorize the output for more fun if this * is a debugging session. */ - out = sdsCatColorizedLdbReply(out,r->str,r->len); + + /* Detect the end of a debugging session. */ + if (strstr(r->str,"<endsession>") == r->str) { + config.eval_ldb = 0; + config.eval_ldb_end = 1; /* Signal the caller session ended. */ + config.output = OUTPUT_STANDARD; + cliRefreshPrompt(); + } else { + out = sdsCatColorizedLdbReply(out,r->str,r->len); + } } else { out = sdscatlen(out,r->str,r->len); } @@ -1109,6 +1111,14 @@ static void repl(void) { issueCommandRepeat(argc-skipargs, argv+skipargs, repeat); + /* If our debugging session ended, show the EVAL final + * reply. */ + if (config.eval_ldb_end) { + config.eval_ldb_end = 0; + cliReadReply(0); + printf("\n(Lua debugging session ended)\n\n"); + } + elapsed = mstime()-start_time; if (elapsed >= 500) { printf("(%.2fs)\n",(double)elapsed/1000); diff --git a/src/scripting.c b/src/scripting.c index 64776fc4f..37f7ea62a 100644 --- a/src/scripting.c +++ b/src/scripting.c @@ -1593,6 +1593,10 @@ int ldbStartSession(client *c) { /* End a debugging session after the EVAL call with debugging enabled * returned. */ void ldbEndSession(client *c) { + /* Emit the remaining logs and an <endsession> mark. */ + ldbLog(sdsnew("<endsession>")); + ldbSendLogs(); + /* If it's a fork()ed session, we just exit. */ if (ldb.forked) { writeToClient(c->fd, c, 0); |