mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 14:05:15 +00:00
You can now open as many PTY pairs as you like. Well, it's actually capped at 8 for now, but it's just a constant and trivial to change. Unregistering a PTY pair is untested because I didn't want to start mucking with that in Terminal right now.
30 lines
793 B
C++
30 lines
793 B
C++
#include "PTYMultiplexer.h"
|
|
#include "MasterPTY.h"
|
|
#include <LibC/errno_numbers.h>
|
|
|
|
static const unsigned s_max_pty_pairs = 8;
|
|
|
|
PTYMultiplexer::PTYMultiplexer()
|
|
: CharacterDevice(5, 2)
|
|
{
|
|
m_freelist.ensure_capacity(s_max_pty_pairs);
|
|
for (int i = s_max_pty_pairs; i > 0; --i)
|
|
m_freelist.unchecked_append(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_index = m_freelist.take_last();
|
|
auto master = adopt(*new MasterPTY(master_index));
|
|
dbgprintf("PTYMultiplexer::open: Vending master %u\n", master->index());
|
|
return VFS::the().open(move(master), error, options);
|
|
}
|