summaryrefslogtreecommitdiff
path: root/Kernel/MasterPTY.cpp
blob: 138d9bc5b05fa9dc1fa3cc78e47d51a5156a69d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "MasterPTY.h"
#include "SlavePTY.h"

MasterPTY::MasterPTY(unsigned index)
    : CharacterDevice(10, index)
    , m_index(index)
{

}

MasterPTY::~MasterPTY()
{
}

String MasterPTY::pts_name() const
{
    dbgprintf("MasterPTY::pts_name requested for index %u!\n", m_index);
    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 m_buffer.bytes_in_write_buffer() < 4096;
}

void MasterPTY::on_slave_write(const byte* data, size_t size)
{
    m_buffer.write(data, size);
}