mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 14:45:08 +00:00
Kernel: Use KResultOr and TRY() for MasterPTY
This commit is contained in:
parent
01993d0af3
commit
631b8e90cd
3 changed files with 6 additions and 18 deletions
|
@ -16,22 +16,12 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
RefPtr<MasterPTY> MasterPTY::try_create(unsigned int index)
|
KResultOr<NonnullRefPtr<MasterPTY>> MasterPTY::try_create(unsigned int index)
|
||||||
{
|
{
|
||||||
auto buffer_or_error = DoubleBuffer::try_create();
|
auto buffer = TRY(DoubleBuffer::try_create());
|
||||||
if (buffer_or_error.is_error())
|
auto master_pty = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) MasterPTY(index, move(buffer))));
|
||||||
return {};
|
auto slave_pty = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) SlavePTY(*master_pty, index)));
|
||||||
|
|
||||||
auto master_pty = adopt_ref_if_nonnull(new (nothrow) MasterPTY(index, buffer_or_error.release_value()));
|
|
||||||
if (!master_pty)
|
|
||||||
return {};
|
|
||||||
|
|
||||||
auto slave_pty = adopt_ref_if_nonnull(new (nothrow) SlavePTY(*master_pty, index));
|
|
||||||
if (!slave_pty)
|
|
||||||
return {};
|
|
||||||
|
|
||||||
master_pty->m_slave = slave_pty;
|
master_pty->m_slave = slave_pty;
|
||||||
|
|
||||||
return master_pty;
|
return master_pty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ class SlavePTY;
|
||||||
|
|
||||||
class MasterPTY final : public CharacterDevice {
|
class MasterPTY final : public CharacterDevice {
|
||||||
public:
|
public:
|
||||||
[[nodiscard]] static RefPtr<MasterPTY> try_create(unsigned index);
|
static KResultOr<NonnullRefPtr<MasterPTY>> try_create(unsigned index);
|
||||||
virtual ~MasterPTY() override;
|
virtual ~MasterPTY() override;
|
||||||
|
|
||||||
unsigned index() const { return m_index; }
|
unsigned index() const { return m_index; }
|
||||||
|
|
|
@ -42,9 +42,7 @@ KResultOr<NonnullRefPtr<OpenFileDescription>> PTYMultiplexer::open(int options)
|
||||||
return EBUSY;
|
return EBUSY;
|
||||||
|
|
||||||
auto master_index = freelist.take_last();
|
auto master_index = freelist.take_last();
|
||||||
auto master = MasterPTY::try_create(master_index);
|
auto master = TRY(MasterPTY::try_create(master_index));
|
||||||
if (!master)
|
|
||||||
return ENOMEM;
|
|
||||||
dbgln_if(PTMX_DEBUG, "PTYMultiplexer::open: Vending master {}", master->index());
|
dbgln_if(PTMX_DEBUG, "PTYMultiplexer::open: Vending master {}", master->index());
|
||||||
auto description = TRY(OpenFileDescription::try_create(*master));
|
auto description = TRY(OpenFileDescription::try_create(*master));
|
||||||
description->set_rw_mode(options);
|
description->set_rw_mode(options);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue