From 2056a35b441d8330d8a293f05f90f6ae117ce6fe Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 12 May 2019 18:19:40 -0400 Subject: [PATCH 1/2] Set `cli_quitting` to true in cli::cancel() --- src/rpc/cli.cpp | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/rpc/cli.cpp b/src/rpc/cli.cpp index ec6cfe6..f1b5ab4 100644 --- a/src/rpc/cli.cpp +++ b/src/rpc/cli.cpp @@ -54,29 +54,6 @@ void cli::send_notice( uint64_t callback_id, variants args /* = variants() */ ) FC_ASSERT(false); } -void cli::stop() -{ - cancel(); - _run_complete.wait(); -} - -void cli::cancel() -{ - _run_complete.cancel(); -#ifdef HAVE_EDITLINE - if( _getline_thread ) - { - _getline_thread->signal(SIGINT); - _getline_thread = nullptr; - } -#endif -} - -void cli::wait() -{ - _run_complete.wait(); -} - void cli::format_result( const string& method, std::function formatter) { _result_formatters[method] = formatter; @@ -292,6 +269,30 @@ void cli::start() _run_complete = fc::async( [this](){ run(); } ); } +void cli::cancel() +{ + _run_complete.cancel(); +#ifdef HAVE_EDITLINE + cli_quitting = true; + if( _getline_thread ) + { + _getline_thread->signal(SIGINT); + _getline_thread = nullptr; + } +#endif +} + +void cli::stop() +{ + cancel(); + _run_complete.wait(); +} + +void cli::wait() +{ + _run_complete.wait(); +} + /*** * @brief Read input from the user * @param prompt the prompt to display From 30ea9b4a1dca893716ce8a64e24d9a30ad8e21d6 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 12 May 2019 19:44:22 -0400 Subject: [PATCH 2/2] Let rl_getc() always return EOF when quitting even if got an EOL or CTRL+C or etc --- src/rpc/cli.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/cli.cpp b/src/rpc/cli.cpp index f1b5ab4..049c8bd 100644 --- a/src/rpc/cli.cpp +++ b/src/rpc/cli.cpp @@ -244,7 +244,7 @@ static int interruptible_getc(void) if( r == -1 && errno == EINTR ) cli_quitting = true; - return r == 1 ? c : EOF; + return r == 1 && !cli_quitting ? c : EOF; } void cli::start()