From be9d4f041117da7afa610328f13b7bfddadd12c8 Mon Sep 17 00:00:00 2001 From: Jethro Grassie Date: Thu, 22 Jun 2017 08:15:18 -0400 Subject: Fix multiline wallet cli output with readline monero-wallet-cli commands which have multine output sometimes causes issues with the readline support. This patch fixes show_transfers, payments and incoming_transfers. --- contrib/epee/src/readline_buffer.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'contrib/epee') diff --git a/contrib/epee/src/readline_buffer.cpp b/contrib/epee/src/readline_buffer.cpp index 2d17103b3..3865b565c 100644 --- a/contrib/epee/src/readline_buffer.cpp +++ b/contrib/epee/src/readline_buffer.cpp @@ -12,7 +12,7 @@ static void remove_line_handler(); static std::string last_line; static std::string last_prompt; -std::mutex line_mutex, sync_mutex; +std::mutex line_mutex, sync_mutex, process_mutex; std::condition_variable have_line; namespace @@ -21,6 +21,7 @@ namespace } rdln::suspend_readline::suspend_readline() +: m_buffer(NULL), m_restart(false) { m_buffer = current; if(!m_buffer) @@ -46,6 +47,7 @@ rdln::readline_buffer::readline_buffer() void rdln::readline_buffer::start() { + std::unique_lock lock(process_mutex); if(m_cout_buf != NULL) return; m_cout_buf = std::cout.rdbuf(); @@ -55,6 +57,7 @@ void rdln::readline_buffer::start() void rdln::readline_buffer::stop() { + std::unique_lock lock(process_mutex); if(m_cout_buf == NULL) return; std::cout.rdbuf(m_cout_buf); @@ -80,6 +83,7 @@ void rdln::readline_buffer::set_prompt(const std::string& prompt) int rdln::readline_buffer::process() { + std::unique_lock lock(process_mutex); if(m_cout_buf == NULL) return 0; return process_input(); -- cgit v1.2.3 From a73a42a6b0db8fc2f27e1eebdc046391f1289a3a Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 27 Jun 2017 08:10:26 -0700 Subject: monero-wallet-cli: hang on exit in readline code (#2117) readline_buffer: fix start/stop threads being starved by process process could run for quite some time re-acquiring the process lock, leaving start/stop starving. Yielding after unlock in process is much better but doesn't seem to be enough to reliably yield, so we sleep for a millisecond, which should be transparent for user input anyway. Signed-off-by: Jethro Grassie --- contrib/epee/src/readline_buffer.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'contrib/epee') diff --git a/contrib/epee/src/readline_buffer.cpp b/contrib/epee/src/readline_buffer.cpp index 3865b565c..34835b80d 100644 --- a/contrib/epee/src/readline_buffer.cpp +++ b/contrib/epee/src/readline_buffer.cpp @@ -5,6 +5,7 @@ #include #include #include +#include static int process_input(); static void install_line_handler(); @@ -83,10 +84,17 @@ void rdln::readline_buffer::set_prompt(const std::string& prompt) int rdln::readline_buffer::process() { - std::unique_lock lock(process_mutex); + process_mutex.lock(); if(m_cout_buf == NULL) + { + process_mutex.unlock(); + boost::this_thread::sleep_for(boost::chrono::milliseconds( 1 )); return 0; - return process_input(); + } + int count = process_input(); + process_mutex.unlock(); + boost::this_thread::sleep_for(boost::chrono::milliseconds( 1 )); + return count; } int rdln::readline_buffer::sync() -- cgit v1.2.3 From 76043b17fd061ecffcc8526db076559057edacd1 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 27 Jun 2017 08:12:14 -0700 Subject: monero-wallet-cli: hang on exit in readline code (#2117) readline_buffer: move a local to local scope Also limit the select fd limit to what we use Signed-off-by: Jethro Grassie --- contrib/epee/src/readline_buffer.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'contrib/epee') diff --git a/contrib/epee/src/readline_buffer.cpp b/contrib/epee/src/readline_buffer.cpp index 34835b80d..c959bf560 100644 --- a/contrib/epee/src/readline_buffer.cpp +++ b/contrib/epee/src/readline_buffer.cpp @@ -126,19 +126,18 @@ int rdln::readline_buffer::sync() return 0; } -static fd_set fds; - static int process_input() { int count; struct timeval t; + fd_set fds; t.tv_sec = 0; t.tv_usec = 1000; FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); - count = select(FD_SETSIZE, &fds, NULL, NULL, &t); + count = select(STDIN_FILENO + 1, &fds, NULL, NULL, &t); if (count < 1) { return count; -- cgit v1.2.3