ladybird/Kernel/MasterPTY.h
Andreas Kling b896d4b237 PTY: Disallow infinite writing to slaves.
This way we don't buffer ungodly amounts of output in the kernel when doing
e.g "cat /dev/random" on a PTY.
2019-01-25 00:13:54 +01:00

33 lines
896 B
C++

#pragma once
#include <Kernel/CharacterDevice.h>
#include "DoubleBuffer.h"
class SlavePTY;
class MasterPTY final : public CharacterDevice {
public:
explicit MasterPTY(unsigned index);
virtual ~MasterPTY() override;
// ^CharacterDevice
virtual ssize_t read(Process&, byte*, size_t) override;
virtual ssize_t write(Process&, const byte*, size_t) override;
virtual bool can_read(Process&) const override;
virtual bool can_write(Process&) const override;
virtual bool is_master_pty() const override { return true; }
unsigned index() const { return m_index; }
String pts_name() const;
void on_slave_write(const byte*, size_t);
bool can_write_from_slave() const;
private:
// ^CharacterDevice
virtual const char* class_name() const override { return "MasterPTY"; }
SlavePTY& m_slave;
unsigned m_index;
DoubleBuffer m_buffer;
};