console_handler: handle EOF properly
Exit instead of reading "empty" commands in an infinite loop.
This commit is contained in:
parent
5001489353
commit
87c01c30f3
|
@ -58,6 +58,9 @@ namespace epee
|
||||||
if (!start_read())
|
if (!start_read())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (state_eos == m_read_status)
|
||||||
|
return false;
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(m_response_mutex);
|
std::unique_lock<std::mutex> lock(m_response_mutex);
|
||||||
while (state_init == m_read_status)
|
while (state_init == m_read_status)
|
||||||
{
|
{
|
||||||
|
@ -71,11 +74,14 @@ namespace epee
|
||||||
res = true;
|
res = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_read_status = state_init;
|
if (!eos())
|
||||||
|
m_read_status = state_init;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool eos() const { return m_read_status == state_eos; }
|
||||||
|
|
||||||
void stop()
|
void stop()
|
||||||
{
|
{
|
||||||
if (m_run)
|
if (m_run)
|
||||||
|
@ -167,7 +173,12 @@ namespace epee
|
||||||
{
|
{
|
||||||
read_ok = false;
|
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);
|
std::unique_lock<std::mutex> lock(m_response_mutex);
|
||||||
if (m_run.load(std::memory_order_relaxed))
|
if (m_run.load(std::memory_order_relaxed))
|
||||||
|
@ -189,7 +200,8 @@ namespace epee
|
||||||
state_init,
|
state_init,
|
||||||
state_success,
|
state_success,
|
||||||
state_error,
|
state_error,
|
||||||
state_cancelled
|
state_cancelled,
|
||||||
|
state_eos
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -266,6 +278,10 @@ namespace epee
|
||||||
{
|
{
|
||||||
LOG_PRINT("Failed to read line.", LOG_LEVEL_0);
|
LOG_PRINT("Failed to read line.", LOG_LEVEL_0);
|
||||||
}
|
}
|
||||||
|
if (m_stdin_reader.eos())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
string_tools::trim(command);
|
string_tools::trim(command);
|
||||||
|
|
||||||
LOG_PRINT_L2("Read command: " << command);
|
LOG_PRINT_L2("Read command: " << command);
|
||||||
|
|
Loading…
Reference in New Issue