mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-15 07:09:43 +03:00
b4e478aa50
This required a fair bit of plumbing. The CharacterDevice::close() virtual will now be closed by ~FileDescriptor(), allowing device implementations to do custom cleanup at that point. One big problem remains: if the master PTY is closed before the slave PTY, we go into crashy land.
35 lines
982 B
C++
35 lines
982 B
C++
#pragma once
|
|
|
|
#include <AK/Badge.h>
|
|
#include <Kernel/CharacterDevice.h>
|
|
#include <Kernel/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;
|
|
void notify_slave_closed(Badge<SlavePTY>);
|
|
|
|
private:
|
|
// ^CharacterDevice
|
|
virtual const char* class_name() const override { return "MasterPTY"; }
|
|
|
|
RetainPtr<SlavePTY> m_slave;
|
|
unsigned m_index;
|
|
DoubleBuffer m_buffer;
|
|
};
|