mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-11-16 15:57:39 +00:00
ConsoleCommands: check if console is available
This commit is contained in:
parent
a7da7f932c
commit
9d692d5194
2 changed files with 22 additions and 6 deletions
|
@ -40,32 +40,41 @@ ConsoleCommands::ConsoleCommands(p2pool* pool)
|
|||
, m_readBuf{}
|
||||
, m_readBufInUse(false)
|
||||
{
|
||||
if (uv_guess_handle(0) != UV_TTY) {
|
||||
LOGERR(1, "tty is not available");
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
int err = uv_loop_init(&m_loop);
|
||||
if (err) {
|
||||
LOGERR(1, "failed to create event loop, error " << uv_err_name(err));
|
||||
panic();
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
err = uv_async_init(&m_loop, &m_shutdownAsync, on_shutdown);
|
||||
if (err) {
|
||||
LOGERR(1, "uv_async_init failed, error " << uv_err_name(err));
|
||||
panic();
|
||||
throw std::exception();
|
||||
}
|
||||
m_shutdownAsync.data = this;
|
||||
|
||||
err = uv_tty_init(&m_loop, &m_tty, 0, 1);
|
||||
if (err) {
|
||||
LOGERR(1, "uv_tty_init failed, error " << uv_err_name(err));
|
||||
panic();
|
||||
throw std::exception();
|
||||
}
|
||||
m_tty.data = this;
|
||||
|
||||
uv_read_start(reinterpret_cast<uv_stream_t*>(&m_tty), allocCallback, stdinReadCallback);
|
||||
err = uv_read_start(reinterpret_cast<uv_stream_t*>(&m_tty), allocCallback, stdinReadCallback);
|
||||
if (err) {
|
||||
LOGERR(1, "uv_read_start failed, error " << uv_err_name(err));
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
err = uv_thread_create(&m_loopThread, loop, this);
|
||||
if (err) {
|
||||
LOGERR(1, "failed to start event loop thread, error " << uv_err_name(err));
|
||||
panic();
|
||||
throw std::exception();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -156,8 +156,15 @@ p2pool::p2pool(int argc, char* argv[])
|
|||
|
||||
m_blockTemplate = new BlockTemplate(this);
|
||||
m_mempool = new Mempool();
|
||||
|
||||
try {
|
||||
m_consoleCommands = new ConsoleCommands(this);
|
||||
}
|
||||
catch (...) {
|
||||
LOGERR(1, "Couldn't start console commands handler");
|
||||
m_consoleCommands = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
p2pool::~p2pool()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue