aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2015-06-11 10:27:30 +0200
committerRiccardo Spagni <ric@spagni.net>2015-06-11 10:27:36 +0200
commitf89cf1df87889d67dcd30c6e7ea954732e222f9c (patch)
treedfbd2824defe10755997e197c8c6866c92828837
parentMerge pull request #303 (diff)
parentfix ^D exit for bitmonerod (diff)
downloadmonero-f89cf1df87889d67dcd30c6e7ea954732e222f9c.tar.xz
Merge pull request #308
35b160e fix ^D exit for bitmonerod (moneromooo-monero)
-rw-r--r--contrib/epee/include/console_handler.h16
-rw-r--r--src/daemon/command_server.cpp4
-rw-r--r--src/daemon/command_server.h2
-rw-r--r--src/daemon/daemon.cpp2
4 files changed, 12 insertions, 12 deletions
diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h
index 256f272c2..952fc3c96 100644
--- a/contrib/epee/include/console_handler.h
+++ b/contrib/epee/include/console_handler.h
@@ -240,9 +240,9 @@ namespace epee
}
template<class chain_handler>
- bool run(chain_handler ch_handler, const std::string& prompt = "#", const std::string& usage = "")
+ bool run(chain_handler ch_handler, const std::string& prompt = "#", const std::string& usage = "", std::function<void(void)> exit_handler = NULL)
{
- return run(prompt, usage, [&](const std::string& cmd) { return ch_handler(cmd); }, [] { });
+ return run(prompt, usage, [&](const std::string& cmd) { return ch_handler(cmd); }, exit_handler);
}
void stop()
@@ -252,8 +252,8 @@ namespace epee
}
private:
- template<typename t_cmd_handler, typename t_exit_handler>
- bool run(const std::string& prompt, const std::string& usage, const t_cmd_handler& cmd_handler, const t_exit_handler& exit_handler)
+ template<typename t_cmd_handler>
+ bool run(const std::string& prompt, const std::string& usage, const t_cmd_handler& cmd_handler, std::function<void(void)> exit_handler)
{
TRY_ENTRY();
bool continue_handle = true;
@@ -429,9 +429,9 @@ namespace epee
std::unique_ptr<boost::thread> m_console_thread;
async_console_handler m_console_handler;
public:
- bool start_handling(const std::string& prompt, const std::string& usage_string = "")
+ bool start_handling(const std::string& prompt, const std::string& usage_string = "", std::function<void(void)> exit_handler = NULL)
{
- m_console_thread.reset(new boost::thread(boost::bind(&console_handlers_binder::run_handling, this, prompt, usage_string)));
+ m_console_thread.reset(new boost::thread(boost::bind(&console_handlers_binder::run_handling, this, prompt, usage_string, exit_handler)));
m_console_thread->detach();
return true;
}
@@ -441,9 +441,9 @@ namespace epee
m_console_handler.stop();
}
- bool run_handling(const std::string& prompt, const std::string& usage_string)
+ bool run_handling(const std::string& prompt, const std::string& usage_string, std::function<void(void)> exit_handler = NULL)
{
- return m_console_handler.run(boost::bind(&console_handlers_binder::process_command_str, this, _1), prompt, usage_string);
+ return m_console_handler.run(boost::bind(&console_handlers_binder::process_command_str, this, _1), prompt, usage_string, exit_handler);
}
};
diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp
index 5510ee594..65bceff75 100644
--- a/src/daemon/command_server.cpp
+++ b/src/daemon/command_server.cpp
@@ -196,11 +196,11 @@ bool t_command_server::process_command_vec(const std::vector<std::string>& cmd)
return result;
}
-bool t_command_server::start_handling()
+bool t_command_server::start_handling(std::function<void(void)> exit_handler)
{
if (m_is_rpc) return false;
- m_command_lookup.start_handling("", get_commands_str());
+ m_command_lookup.start_handling("", get_commands_str(), exit_handler);
return true;
}
diff --git a/src/daemon/command_server.h b/src/daemon/command_server.h
index aa8e0770e..5df457288 100644
--- a/src/daemon/command_server.h
+++ b/src/daemon/command_server.h
@@ -62,7 +62,7 @@ public:
bool process_command_vec(const std::vector<std::string>& cmd);
- bool start_handling();
+ bool start_handling(std::function<void(void)> exit_handler = NULL);
void stop_handling();
diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp
index 7931ba03f..2bd592611 100644
--- a/src/daemon/daemon.cpp
+++ b/src/daemon/daemon.cpp
@@ -126,7 +126,7 @@ bool t_daemon::run(bool interactive)
if (interactive)
{
rpc_commands = new daemonize::t_command_server(0, 0, false, mp_internals->rpc.get_server());
- rpc_commands->start_handling();
+ rpc_commands->start_handling(std::bind(&daemonize::t_daemon::stop, this));
}
mp_internals->p2p.run(); // blocks until p2p goes down