p2pool/src/console_commands.h

73 lines
2 KiB
C
Raw Normal View History

2021-08-22 10:20:59 +00:00
/*
* This file is part of the Monero P2Pool <https://github.com/SChernykh/p2pool>
2024-01-02 13:06:19 +00:00
* Copyright (c) 2021-2024 SChernykh <https://github.com/SChernykh>
2021-08-22 10:20:59 +00:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "uv_util.h"
#include "tcp_server.h"
2021-08-22 10:20:59 +00:00
namespace p2pool {
class p2pool;
class ConsoleCommands : public TCPServer
2021-08-22 10:20:59 +00:00
{
public:
explicit ConsoleCommands(p2pool* pool);
~ConsoleCommands();
struct ConsoleClient : public Client
{
ConsoleClient() : Client(m_consoleReadBuf, sizeof(m_consoleReadBuf)) {}
~ConsoleClient() {}
static Client* allocate() { return new ConsoleClient(); }
size_t size() const override { return sizeof(ConsoleClient); }
bool on_connect() override { return true; };
bool on_read(char* data, uint32_t size) override { static_cast<ConsoleCommands*>(m_owner)->process_input(m_command, data, size); return true; };
char m_consoleReadBuf[1024] = {};
std::string m_command;
};
void on_shutdown() override;
2021-08-22 10:20:59 +00:00
private:
const char* get_log_category() const override;
2021-08-22 10:20:59 +00:00
p2pool* m_pool;
uv_tty_t m_tty;
2023-03-07 13:35:49 +00:00
uv_pipe_t m_stdin_pipe;
uv_stream_t* m_stdin_handle;
char m_readBuf[1024];
bool m_readBufInUse;
std::string m_command;
static void allocCallback(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
static void stdinReadCallback(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf);
void process_input(std::string& command, char* data, uint32_t size);
2021-08-22 10:20:59 +00:00
};
} // namespace p2pool