mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-04-13 09:01:55 +00:00
allow named pipe as stdin, fixes after review
This commit is contained in:
parent
c71d89c95a
commit
3df7430663
2 changed files with 10 additions and 8 deletions
|
@ -42,6 +42,13 @@ ConsoleCommands::ConsoleCommands(p2pool* pool)
|
|||
, m_readBuf{}
|
||||
, m_readBufInUse(false)
|
||||
{
|
||||
uv_handle_type stdin_type = uv_guess_handle(0);
|
||||
LOGINFO(3, "uv_guess_handle returned " << static_cast<int>(stdin_type));
|
||||
if (stdin_type != UV_TTY && stdin_type != UV_NAMED_PIPE) {
|
||||
LOGERR(1, "tty or named pipe 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));
|
||||
|
@ -55,8 +62,6 @@ ConsoleCommands::ConsoleCommands(p2pool* pool)
|
|||
}
|
||||
m_shutdownAsync.data = this;
|
||||
|
||||
uv_handle_type stdin_type = uv_guess_handle(0);
|
||||
LOGINFO(3, "uv_guess_handle returned " << (int)stdin_type);
|
||||
if (stdin_type == UV_TTY) {
|
||||
LOGINFO(3, "processing stdin as UV_TTY");
|
||||
err = uv_tty_init(&m_loop, &m_tty, 0, 1);
|
||||
|
@ -64,7 +69,7 @@ ConsoleCommands::ConsoleCommands(p2pool* pool)
|
|||
LOGERR(1, "uv_tty_init failed, error " << uv_err_name(err));
|
||||
throw std::exception();
|
||||
}
|
||||
m_stdin_handle = reinterpret_cast<uv_handle_t*>(&m_tty);
|
||||
m_stdin_handle = reinterpret_cast<uv_stream_t*>(&m_tty);
|
||||
} else if (stdin_type == UV_NAMED_PIPE) {
|
||||
LOGINFO(3, "processing stdin as UV_NAMED_PIPE");
|
||||
err = uv_pipe_init(&m_loop, &m_stdin_pipe, 0);
|
||||
|
@ -72,15 +77,12 @@ ConsoleCommands::ConsoleCommands(p2pool* pool)
|
|||
LOGERR(1, "uv_pipe_init failed, error " << uv_err_name(err));
|
||||
throw std::exception();
|
||||
}
|
||||
m_stdin_handle = reinterpret_cast<uv_handle_t*>(&m_stdin_pipe);
|
||||
m_stdin_handle = reinterpret_cast<uv_stream_t*>(&m_stdin_pipe);
|
||||
err = uv_pipe_open(&m_stdin_pipe, 0);
|
||||
if (err) {
|
||||
LOGERR(1, "uv_pipe_open failed, error " << uv_err_name(err));
|
||||
throw std::exception();
|
||||
}
|
||||
} else {
|
||||
LOGERR(1, "tty or named pipe is not available");
|
||||
throw std::exception();
|
||||
}
|
||||
m_stdin_handle->data = this;
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ private:
|
|||
uv_async_t m_shutdownAsync;
|
||||
uv_tty_t m_tty;
|
||||
uv_pipe_t m_stdin_pipe;
|
||||
uv_handle_t* m_stdin_handle;
|
||||
uv_stream_t* m_stdin_handle;
|
||||
uv_thread_t m_loopThread;
|
||||
|
||||
char m_readBuf[64];
|
||||
|
|
Loading…
Reference in a new issue