1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:58:13 +00:00
serenity/Kernel/MasterPTY.cpp
Andreas Kling ccf3fc4618 TTY: MasterPTY's are always writable when open.
This should probably have some limitations eventually, but for now let's just
say we always accept data for shoveling over to SlavePTY.
2019-01-24 21:23:46 +01:00

47 lines
870 B
C++

#include "MasterPTY.h"
#include "SlavePTY.h"
MasterPTY::MasterPTY(unsigned index)
: CharacterDevice(10, index)
, m_slave(*new SlavePTY(*this, index))
, m_index(index)
{
VFS::the().register_character_device(m_slave);
}
MasterPTY::~MasterPTY()
{
}
String MasterPTY::pts_name() const
{
char buffer[32];
ksprintf(buffer, "/dev/pts%u", m_index);
return buffer;
}
ssize_t MasterPTY::read(Process&, byte* buffer, size_t size)
{
return m_buffer.read(buffer, size);
}
ssize_t MasterPTY::write(Process&, const byte* buffer, size_t size)
{
m_slave.on_master_write(buffer, size);
return size;
}
bool MasterPTY::can_read(Process&) const
{
return !m_buffer.is_empty();
}
bool MasterPTY::can_write(Process&) const
{
return true;
}
void MasterPTY::on_slave_write(const byte* data, size_t size)
{
m_buffer.write(data, size);
}