aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2015-05-30 22:33:18 +0200
committerRiccardo Spagni <ric@spagni.net>2015-05-30 22:33:22 +0200
commitbcf064e9ed7bd969d76a41206ae16ed9da551757 (patch)
tree5c8b7a783c9fe4883c7c50f1919c7d608c8f0122
parentMerge pull request #298 (diff)
parentconsole_handler: handle EOF properly (diff)
downloadmonero-bcf064e9ed7bd969d76a41206ae16ed9da551757.tar.xz
Merge pull request #299
87c01c3 console_handler: handle EOF properly (moneromooo-monero)
-rw-r--r--contrib/epee/include/console_handler.h22
1 files changed, 19 insertions, 3 deletions
diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h
index fc8cc3841..256f272c2 100644
--- a/contrib/epee/include/console_handler.h
+++ b/contrib/epee/include/console_handler.h
@@ -58,6 +58,9 @@ namespace epee
if (!start_read())
return false;
+ if (state_eos == m_read_status)
+ return false;
+
std::unique_lock<std::mutex> lock(m_response_mutex);
while (state_init == m_read_status)
{
@@ -71,11 +74,14 @@ namespace epee
res = true;
}
- m_read_status = state_init;
+ if (!eos())
+ m_read_status = state_init;
return res;
}
+ bool eos() const { return m_read_status == state_eos; }
+
void stop()
{
if (m_run)
@@ -167,7 +173,12 @@ namespace epee
{
read_ok = false;
}
-
+ if (std::cin.eof()) {
+ m_read_status = state_eos;
+ m_response_cv.notify_one();
+ break;
+ }
+ else
{
std::unique_lock<std::mutex> lock(m_response_mutex);
if (m_run.load(std::memory_order_relaxed))
@@ -189,7 +200,8 @@ namespace epee
state_init,
state_success,
state_error,
- state_cancelled
+ state_cancelled,
+ state_eos
};
private:
@@ -266,6 +278,10 @@ namespace epee
{
LOG_PRINT("Failed to read line.", LOG_LEVEL_0);
}
+ if (m_stdin_reader.eos())
+ {
+ break;
+ }
string_tools::trim(command);
LOG_PRINT_L2("Read command: " << command);