1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:47:46 +00:00

TelnetServer: Implement basic telnet server

Fixes #407

Depends on #530 to run reliably.
This commit is contained in:
Conrad Pankoff 2019-09-08 17:51:28 +10:00 committed by Andreas Kling
parent 423807d772
commit 040947ee47
9 changed files with 521 additions and 0 deletions

View file

@ -0,0 +1,43 @@
#pragma once
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Types.h>
#include <LibCore/CNotifier.h>
#include <LibCore/CTCPSocket.h>
#include "Command.h"
#include "Parser.h"
class Client : public RefCounted<Client> {
public:
static NonnullRefPtr<Client> create(int id, CTCPSocket* socket, int ptm_fd)
{
return adopt(*new Client(id, socket, ptm_fd));
}
Function<void()> on_exit;
protected:
Client(int id, CTCPSocket* socket, int ptm_fd);
void drain_socket();
void drain_pty();
void handle_data(const StringView&);
void handle_command(const Command& command);
void handle_error();
void send_data(StringView str);
void send_command(Command command);
void send_commands(Vector<Command> commands);
void quit();
private:
// client id
int m_id { 0 };
// client resources
CTCPSocket* m_socket { nullptr };
Parser m_parser;
// pty resources
int m_ptm_fd { -1 };
CNotifier m_ptm_notifier;
};