mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 14:05:09 +00:00
Add a PTY multiplexer (/dev/ptmx) device.
When you open /dev/ptmx, you get a file descriptor pointing to one of the available MasterPTY's. If none are available, you get an EBUSY. This makes it possible to open multiple (up to 4) Terminals. :^) To support this, I also added a CharacterDevice::open() that gets control when VFS is opening a CharacterDevice. This is useful when we want to return a custom FileDescriptor like we do here.
This commit is contained in:
parent
b46ae2bf09
commit
9dd29f9aa9
13 changed files with 75 additions and 37 deletions
27
Kernel/PTYMultiplexer.cpp
Normal file
27
Kernel/PTYMultiplexer.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "PTYMultiplexer.h"
|
||||
#include "MasterPTY.h"
|
||||
#include <LibC/errno_numbers.h>
|
||||
|
||||
PTYMultiplexer::PTYMultiplexer()
|
||||
: CharacterDevice(5, 2)
|
||||
{
|
||||
m_freelist.ensureCapacity(4);
|
||||
for (int i = 4; i > 0; --i)
|
||||
m_freelist.unchecked_append(adopt(*new MasterPTY(i - 1)));
|
||||
}
|
||||
|
||||
PTYMultiplexer::~PTYMultiplexer()
|
||||
{
|
||||
}
|
||||
|
||||
RetainPtr<FileDescriptor> PTYMultiplexer::open(int& error, int options)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
if (m_freelist.is_empty()) {
|
||||
error = -EBUSY;
|
||||
return nullptr;
|
||||
}
|
||||
auto master = m_freelist.takeLast();
|
||||
dbgprintf("PTYMultiplexer::open: Vending master %u\n", master->index());
|
||||
return VFS::the().open(move(master), error, options);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue