mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 17:48:12 +00:00
LibCore: Simplify Core::Notifier by only allowing one event type
Not a single client of this API actually used the event mask feature to listen for readability AND writability. Let's simplify the API and have only one hook: on_activation.
This commit is contained in:
parent
1587caef84
commit
411d36719e
24 changed files with 80 additions and 99 deletions
|
@ -51,7 +51,7 @@ static void proxy_socket_through_notifier(ClientType& client, QSocketNotifier& n
|
||||||
notifier.setEnabled(true);
|
notifier.setEnabled(true);
|
||||||
|
|
||||||
QObject::connect(¬ifier, &QSocketNotifier::activated, [&client]() mutable {
|
QObject::connect(¬ifier, &QSocketNotifier::activated, [&client]() mutable {
|
||||||
client.socket().notifier()->on_ready_to_read();
|
client.socket().notifier()->on_activation();
|
||||||
});
|
});
|
||||||
|
|
||||||
client.set_deferred_invoker(make<DeferredInvokerQt>());
|
client.set_deferred_invoker(make<DeferredInvokerQt>());
|
||||||
|
|
|
@ -610,7 +610,7 @@ void WebContentView::create_client(WebView::EnableCallgrindProfiling enable_call
|
||||||
|
|
||||||
QObject::connect(&m_web_content_notifier, &QSocketNotifier::activated, [new_client = new_client.ptr()] {
|
QObject::connect(&m_web_content_notifier, &QSocketNotifier::activated, [new_client = new_client.ptr()] {
|
||||||
if (auto notifier = new_client->socket().notifier())
|
if (auto notifier = new_client->socket().notifier())
|
||||||
notifier->on_ready_to_read();
|
notifier->on_activation();
|
||||||
});
|
});
|
||||||
|
|
||||||
struct DeferredInvokerQt final : IPC::DeferredInvoker {
|
struct DeferredInvokerQt final : IPC::DeferredInvoker {
|
||||||
|
|
|
@ -69,8 +69,8 @@ FileOperationProgressWidget::FileOperationProgressWidget(FileOperation operation
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_notifier = Core::Notifier::construct(helper_pipe_fd, Core::Notifier::Read);
|
m_notifier = Core::Notifier::construct(helper_pipe_fd, Core::Notifier::Type::Read);
|
||||||
m_notifier->on_ready_to_read = [this] {
|
m_notifier->on_activation = [this] {
|
||||||
auto line_buffer_or_error = ByteBuffer::create_zeroed(1 * KiB);
|
auto line_buffer_or_error = ByteBuffer::create_zeroed(1 * KiB);
|
||||||
if (line_buffer_or_error.is_error()) {
|
if (line_buffer_or_error.is_error()) {
|
||||||
did_error("Failed to allocate ByteBuffer for reading data."sv);
|
did_error("Failed to allocate ByteBuffer for reading data."sv);
|
||||||
|
@ -211,7 +211,7 @@ void FileOperationProgressWidget::close_pipe()
|
||||||
m_helper_pipe = nullptr;
|
m_helper_pipe = nullptr;
|
||||||
if (m_notifier) {
|
if (m_notifier) {
|
||||||
m_notifier->set_enabled(false);
|
m_notifier->set_enabled(false);
|
||||||
m_notifier->on_ready_to_read = nullptr;
|
m_notifier->on_activation = nullptr;
|
||||||
}
|
}
|
||||||
m_notifier = nullptr;
|
m_notifier = nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace Chess::UCI {
|
||||||
Endpoint::Endpoint(NonnullRefPtr<Core::IODevice> in, NonnullRefPtr<Core::IODevice> out)
|
Endpoint::Endpoint(NonnullRefPtr<Core::IODevice> in, NonnullRefPtr<Core::IODevice> out)
|
||||||
: m_in(in)
|
: m_in(in)
|
||||||
, m_out(out)
|
, m_out(out)
|
||||||
, m_in_notifier(Core::Notifier::construct(in->fd(), Core::Notifier::Read))
|
, m_in_notifier(Core::Notifier::construct(in->fd(), Core::Notifier::Type::Read))
|
||||||
{
|
{
|
||||||
set_in_notifier();
|
set_in_notifier();
|
||||||
}
|
}
|
||||||
|
@ -70,8 +70,8 @@ void Endpoint::custom_event(Core::CustomEvent& custom_event)
|
||||||
|
|
||||||
void Endpoint::set_in_notifier()
|
void Endpoint::set_in_notifier()
|
||||||
{
|
{
|
||||||
m_in_notifier = Core::Notifier::construct(m_in->fd(), Core::Notifier::Read);
|
m_in_notifier = Core::Notifier::construct(m_in->fd(), Core::Notifier::Type::Read);
|
||||||
m_in_notifier->on_ready_to_read = [this] {
|
m_in_notifier->on_activation = [this] {
|
||||||
if (!m_in->can_read_line()) {
|
if (!m_in->can_read_line()) {
|
||||||
Core::EventLoop::current().post_event(*this, make<Core::CustomEvent>(EndpointEventType::UnexpectedEof));
|
Core::EventLoop::current().post_event(*this, make<Core::CustomEvent>(EndpointEventType::UnexpectedEof));
|
||||||
m_in_notifier->set_enabled(false);
|
m_in_notifier->set_enabled(false);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
|
||||||
* Copyright (c) 2022, the SerenityOS developers.
|
* Copyright (c) 2022, the SerenityOS developers.
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
@ -21,8 +21,7 @@ public:
|
||||||
Invalid = 0,
|
Invalid = 0,
|
||||||
Quit,
|
Quit,
|
||||||
Timer,
|
Timer,
|
||||||
NotifierRead,
|
NotifierActivation,
|
||||||
NotifierWrite,
|
|
||||||
DeferredInvoke,
|
DeferredInvoke,
|
||||||
ChildAdded,
|
ChildAdded,
|
||||||
ChildRemoved,
|
ChildRemoved,
|
||||||
|
@ -79,29 +78,14 @@ private:
|
||||||
int m_timer_id;
|
int m_timer_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
class NotifierReadEvent final : public Event {
|
class NotifierActivationEvent final : public Event {
|
||||||
public:
|
public:
|
||||||
explicit NotifierReadEvent(int fd)
|
explicit NotifierActivationEvent(int fd)
|
||||||
: Event(Event::NotifierRead)
|
: Event(Event::NotifierActivation)
|
||||||
, m_fd(fd)
|
, m_fd(fd)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
~NotifierReadEvent() = default;
|
~NotifierActivationEvent() = default;
|
||||||
|
|
||||||
int fd() const { return m_fd; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
int m_fd;
|
|
||||||
};
|
|
||||||
|
|
||||||
class NotifierWriteEvent final : public Event {
|
|
||||||
public:
|
|
||||||
explicit NotifierWriteEvent(int fd)
|
|
||||||
: Event(Event::NotifierWrite)
|
|
||||||
, m_fd(fd)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
~NotifierWriteEvent() = default;
|
|
||||||
|
|
||||||
int fd() const { return m_fd; }
|
int fd() const { return m_fd; }
|
||||||
|
|
||||||
|
|
|
@ -651,11 +651,11 @@ retry:
|
||||||
max_fd = max(max_fd, max_fd_added);
|
max_fd = max(max_fd, max_fd_added);
|
||||||
|
|
||||||
for (auto& notifier : *s_notifiers) {
|
for (auto& notifier : *s_notifiers) {
|
||||||
if (notifier->event_mask() & Notifier::Read)
|
if (notifier->type() == Notifier::Type::Read)
|
||||||
add_fd_to_set(notifier->fd(), rfds);
|
add_fd_to_set(notifier->fd(), rfds);
|
||||||
if (notifier->event_mask() & Notifier::Write)
|
if (notifier->type() == Notifier::Type::Write)
|
||||||
add_fd_to_set(notifier->fd(), wfds);
|
add_fd_to_set(notifier->fd(), wfds);
|
||||||
if (notifier->event_mask() & Notifier::Exceptional)
|
if (notifier->type() == Notifier::Type::Exceptional)
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -757,13 +757,11 @@ try_select_again:
|
||||||
|
|
||||||
// Handle file system notifiers by making them normal events.
|
// Handle file system notifiers by making them normal events.
|
||||||
for (auto& notifier : *s_notifiers) {
|
for (auto& notifier : *s_notifiers) {
|
||||||
if (FD_ISSET(notifier->fd(), &rfds)) {
|
if (notifier->type() == Notifier::Type::Read && FD_ISSET(notifier->fd(), &rfds)) {
|
||||||
if (notifier->event_mask() & Notifier::Event::Read)
|
post_event(*notifier, make<NotifierActivationEvent>(notifier->fd()));
|
||||||
post_event(*notifier, make<NotifierReadEvent>(notifier->fd()));
|
|
||||||
}
|
}
|
||||||
if (FD_ISSET(notifier->fd(), &wfds)) {
|
if (notifier->type() == Notifier::Type::Write && FD_ISSET(notifier->fd(), &wfds)) {
|
||||||
if (notifier->event_mask() & Notifier::Event::Write)
|
post_event(*notifier, make<NotifierActivationEvent>(notifier->fd()));
|
||||||
post_event(*notifier, make<NotifierWriteEvent>(notifier->fd()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ ErrorOr<NonnullRefPtr<FileWatcher>> FileWatcher::create(FileWatcherFlags flags)
|
||||||
if (watcher_fd < 0)
|
if (watcher_fd < 0)
|
||||||
return Error::from_errno(errno);
|
return Error::from_errno(errno);
|
||||||
|
|
||||||
auto notifier = TRY(Notifier::try_create(watcher_fd, Notifier::Event::Read));
|
auto notifier = TRY(Notifier::try_create(watcher_fd, Notifier::Type::Read));
|
||||||
return adopt_nonnull_ref_or_enomem(new (nothrow) FileWatcher(watcher_fd, move(notifier)));
|
return adopt_nonnull_ref_or_enomem(new (nothrow) FileWatcher(watcher_fd, move(notifier)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ FileWatcher::FileWatcher(int watcher_fd, NonnullRefPtr<Notifier> notifier)
|
||||||
: FileWatcherBase(watcher_fd)
|
: FileWatcherBase(watcher_fd)
|
||||||
, m_notifier(move(notifier))
|
, m_notifier(move(notifier))
|
||||||
{
|
{
|
||||||
m_notifier->on_ready_to_read = [this] {
|
m_notifier->on_activation = [this] {
|
||||||
auto maybe_event = get_event_from_fd(m_notifier->fd(), m_wd_to_path);
|
auto maybe_event = get_event_from_fd(m_notifier->fd(), m_wd_to_path);
|
||||||
if (maybe_event.has_value()) {
|
if (maybe_event.has_value()) {
|
||||||
auto event = maybe_event.value();
|
auto event = maybe_event.value();
|
||||||
|
|
|
@ -59,7 +59,7 @@ public:
|
||||||
|
|
||||||
// NOTE: This isn't actually used on macOS, but is needed for FileWatcherBase.
|
// NOTE: This isn't actually used on macOS, but is needed for FileWatcherBase.
|
||||||
// Creating it with an FD of -1 will effectively disable the notifier.
|
// Creating it with an FD of -1 will effectively disable the notifier.
|
||||||
auto notifier = TRY(Notifier::try_create(-1, Notifier::Event::None));
|
auto notifier = TRY(Notifier::try_create(-1, Notifier::Type::None));
|
||||||
|
|
||||||
return adopt_nonnull_ref_or_enomem(new (nothrow) FileWatcherMacOS(move(context), dispatch_queue, move(notifier)));
|
return adopt_nonnull_ref_or_enomem(new (nothrow) FileWatcherMacOS(move(context), dispatch_queue, move(notifier)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,7 +188,7 @@ ErrorOr<NonnullRefPtr<FileWatcher>> FileWatcher::create(FileWatcherFlags flags)
|
||||||
if (watcher_fd < 0)
|
if (watcher_fd < 0)
|
||||||
return Error::from_errno(errno);
|
return Error::from_errno(errno);
|
||||||
|
|
||||||
auto notifier = Notifier::construct(watcher_fd, Notifier::Event::Read);
|
auto notifier = Notifier::construct(watcher_fd, Notifier::Type::Read);
|
||||||
return adopt_ref(*new FileWatcher(watcher_fd, move(notifier)));
|
return adopt_ref(*new FileWatcher(watcher_fd, move(notifier)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ FileWatcher::FileWatcher(int watcher_fd, NonnullRefPtr<Notifier> notifier)
|
||||||
: FileWatcherBase(watcher_fd)
|
: FileWatcherBase(watcher_fd)
|
||||||
, m_notifier(move(notifier))
|
, m_notifier(move(notifier))
|
||||||
{
|
{
|
||||||
m_notifier->on_ready_to_read = [this] {
|
m_notifier->on_activation = [this] {
|
||||||
auto maybe_event = get_event_from_fd(m_notifier->fd(), m_wd_to_path);
|
auto maybe_event = get_event_from_fd(m_notifier->fd(), m_wd_to_path);
|
||||||
if (maybe_event.has_value()) {
|
if (maybe_event.has_value()) {
|
||||||
auto event = maybe_event.value();
|
auto event = maybe_event.value();
|
||||||
|
@ -214,7 +214,7 @@ FileWatcher::FileWatcher(int watcher_fd, NonnullRefPtr<Notifier> notifier)
|
||||||
|
|
||||||
FileWatcher::~FileWatcher()
|
FileWatcher::~FileWatcher()
|
||||||
{
|
{
|
||||||
m_notifier->on_ready_to_read = nullptr;
|
m_notifier->on_activation = nullptr;
|
||||||
close(m_notifier->fd());
|
close(m_notifier->fd());
|
||||||
dbgln_if(FILE_WATCHER_DEBUG, "Stopped watcher at fd {}", m_notifier->fd());
|
dbgln_if(FILE_WATCHER_DEBUG, "Stopped watcher at fd {}", m_notifier->fd());
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,8 @@ ErrorOr<void> LocalServer::take_over_from_system_server(DeprecatedString const&
|
||||||
|
|
||||||
void LocalServer::setup_notifier()
|
void LocalServer::setup_notifier()
|
||||||
{
|
{
|
||||||
m_notifier = Notifier::construct(m_fd, Notifier::Event::Read, this);
|
m_notifier = Notifier::construct(m_fd, Notifier::Type::Read, this);
|
||||||
m_notifier->on_ready_to_read = [this] {
|
m_notifier->on_activation = [this] {
|
||||||
if (on_accept) {
|
if (on_accept) {
|
||||||
auto maybe_client_socket = accept();
|
auto maybe_client_socket = accept();
|
||||||
if (maybe_client_socket.is_error()) {
|
if (maybe_client_socket.is_error()) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -10,10 +10,10 @@
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
Notifier::Notifier(int fd, unsigned event_mask, Object* parent)
|
Notifier::Notifier(int fd, Type type, Object* parent)
|
||||||
: Object(parent)
|
: Object(parent)
|
||||||
, m_fd(fd)
|
, m_fd(fd)
|
||||||
, m_event_mask(event_mask)
|
, m_type(type)
|
||||||
{
|
{
|
||||||
set_enabled(true);
|
set_enabled(true);
|
||||||
}
|
}
|
||||||
|
@ -43,13 +43,12 @@ void Notifier::close()
|
||||||
|
|
||||||
void Notifier::event(Core::Event& event)
|
void Notifier::event(Core::Event& event)
|
||||||
{
|
{
|
||||||
if (event.type() == Core::Event::NotifierRead && on_ready_to_read) {
|
if (event.type() == Core::Event::NotifierActivation) {
|
||||||
on_ready_to_read();
|
if (on_activation)
|
||||||
} else if (event.type() == Core::Event::NotifierWrite && on_ready_to_write) {
|
on_activation();
|
||||||
on_ready_to_write();
|
return;
|
||||||
} else {
|
|
||||||
Object::event(event);
|
|
||||||
}
|
}
|
||||||
|
Object::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -11,36 +11,36 @@
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
class Notifier : public Object {
|
class Notifier final : public Object {
|
||||||
C_OBJECT(Notifier)
|
C_OBJECT(Notifier);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Event {
|
enum class Type {
|
||||||
None = 0,
|
None,
|
||||||
Read = 1,
|
Read,
|
||||||
Write = 2,
|
Write,
|
||||||
Exceptional = 4,
|
Exceptional,
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~Notifier() override;
|
virtual ~Notifier() override;
|
||||||
|
|
||||||
void set_enabled(bool);
|
void set_enabled(bool);
|
||||||
|
|
||||||
Function<void()> on_ready_to_read;
|
Function<void()> on_activation;
|
||||||
Function<void()> on_ready_to_write;
|
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
int fd() const { return m_fd; }
|
int fd() const { return m_fd; }
|
||||||
unsigned event_mask() const { return m_event_mask; }
|
Type type() const { return m_type; }
|
||||||
void set_event_mask(unsigned event_mask) { m_event_mask = event_mask; }
|
void set_type(Type type) { m_type = type; }
|
||||||
|
|
||||||
void event(Core::Event&) override;
|
void event(Core::Event&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Notifier(int fd, unsigned event_mask, Object* parent = nullptr);
|
Notifier(int fd, Type type, Object* parent = nullptr);
|
||||||
|
|
||||||
int m_fd { -1 };
|
int m_fd { -1 };
|
||||||
unsigned m_event_mask { 0 };
|
Type m_type { Type::None };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,7 +186,7 @@ ErrorOr<void> PosixSocketHelper::set_receive_timeout(Time timeout)
|
||||||
void PosixSocketHelper::setup_notifier()
|
void PosixSocketHelper::setup_notifier()
|
||||||
{
|
{
|
||||||
if (!m_notifier)
|
if (!m_notifier)
|
||||||
m_notifier = Core::Notifier::construct(m_fd, Core::Notifier::Read);
|
m_notifier = Core::Notifier::construct(m_fd, Core::Notifier::Type::Read);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<NonnullOwnPtr<TCPSocket>> TCPSocket::connect(DeprecatedString const& host, u16 port)
|
ErrorOr<NonnullOwnPtr<TCPSocket>> TCPSocket::connect(DeprecatedString const& host, u16 port)
|
||||||
|
|
|
@ -204,7 +204,7 @@ private:
|
||||||
VERIFY(is_open());
|
VERIFY(is_open());
|
||||||
|
|
||||||
m_helper.setup_notifier();
|
m_helper.setup_notifier();
|
||||||
m_helper.notifier()->on_ready_to_read = [this] {
|
m_helper.notifier()->on_activation = [this] {
|
||||||
if (on_ready_to_read)
|
if (on_ready_to_read)
|
||||||
on_ready_to_read();
|
on_ready_to_read();
|
||||||
};
|
};
|
||||||
|
@ -278,7 +278,7 @@ private:
|
||||||
VERIFY(is_open());
|
VERIFY(is_open());
|
||||||
|
|
||||||
m_helper.setup_notifier();
|
m_helper.setup_notifier();
|
||||||
m_helper.notifier()->on_ready_to_read = [this] {
|
m_helper.notifier()->on_activation = [this] {
|
||||||
if (on_ready_to_read)
|
if (on_ready_to_read)
|
||||||
on_ready_to_read();
|
on_ready_to_read();
|
||||||
};
|
};
|
||||||
|
@ -352,7 +352,7 @@ private:
|
||||||
VERIFY(is_open());
|
VERIFY(is_open());
|
||||||
|
|
||||||
m_helper.setup_notifier();
|
m_helper.setup_notifier();
|
||||||
m_helper.notifier()->on_ready_to_read = [this] {
|
m_helper.notifier()->on_activation = [this] {
|
||||||
if (on_ready_to_read)
|
if (on_ready_to_read)
|
||||||
on_ready_to_read();
|
on_ready_to_read();
|
||||||
};
|
};
|
||||||
|
|
|
@ -57,8 +57,8 @@ ErrorOr<void> TCPServer::listen(IPv4Address const& address, u16 port, AllowAddre
|
||||||
TRY(Core::System::listen(m_fd, 5));
|
TRY(Core::System::listen(m_fd, 5));
|
||||||
m_listening = true;
|
m_listening = true;
|
||||||
|
|
||||||
m_notifier = Notifier::construct(m_fd, Notifier::Event::Read, this);
|
m_notifier = Notifier::construct(m_fd, Notifier::Type::Read, this);
|
||||||
m_notifier->on_ready_to_read = [this] {
|
m_notifier->on_activation = [this] {
|
||||||
if (on_ready_to_accept)
|
if (on_ready_to_accept)
|
||||||
on_ready_to_accept();
|
on_ready_to_accept();
|
||||||
};
|
};
|
||||||
|
|
|
@ -55,8 +55,8 @@ bool UDPServer::bind(IPv4Address const& address, u16 port)
|
||||||
|
|
||||||
m_bound = true;
|
m_bound = true;
|
||||||
|
|
||||||
m_notifier = Notifier::construct(m_fd, Notifier::Event::Read, this);
|
m_notifier = Notifier::construct(m_fd, Notifier::Type::Read, this);
|
||||||
m_notifier->on_ready_to_read = [this] {
|
m_notifier->on_activation = [this] {
|
||||||
if (on_ready_to_receive)
|
if (on_ready_to_receive)
|
||||||
on_ready_to_receive();
|
on_ready_to_receive();
|
||||||
};
|
};
|
||||||
|
|
|
@ -747,9 +747,9 @@ auto Editor::get_line(DeprecatedString const& prompt) -> Result<DeprecatedString
|
||||||
|
|
||||||
Core::EventLoop loop;
|
Core::EventLoop loop;
|
||||||
|
|
||||||
m_notifier = Core::Notifier::construct(STDIN_FILENO, Core::Notifier::Read);
|
m_notifier = Core::Notifier::construct(STDIN_FILENO, Core::Notifier::Type::Read);
|
||||||
|
|
||||||
m_notifier->on_ready_to_read = [&] {
|
m_notifier->on_activation = [&] {
|
||||||
if (try_update_once().is_error())
|
if (try_update_once().is_error())
|
||||||
loop.quit(Exit);
|
loop.quit(Exit);
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,7 +25,7 @@ void Request::stream_into(Stream& stream)
|
||||||
VERIFY(!m_internal_stream_data);
|
VERIFY(!m_internal_stream_data);
|
||||||
|
|
||||||
m_internal_stream_data = make<InternalStreamData>(MUST(Core::File::adopt_fd(fd(), Core::File::OpenMode::Read)));
|
m_internal_stream_data = make<InternalStreamData>(MUST(Core::File::adopt_fd(fd(), Core::File::OpenMode::Read)));
|
||||||
m_internal_stream_data->read_notifier = Core::Notifier::construct(fd(), Core::Notifier::Read);
|
m_internal_stream_data->read_notifier = Core::Notifier::construct(fd(), Core::Notifier::Type::Read);
|
||||||
|
|
||||||
auto user_on_finish = move(on_finish);
|
auto user_on_finish = move(on_finish);
|
||||||
on_finish = [this](auto success, auto total_size) {
|
on_finish = [this](auto success, auto total_size) {
|
||||||
|
@ -41,7 +41,7 @@ void Request::stream_into(Stream& stream)
|
||||||
user_on_finish(m_internal_stream_data->success, m_internal_stream_data->total_size);
|
user_on_finish(m_internal_stream_data->success, m_internal_stream_data->total_size);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
m_internal_stream_data->read_notifier->on_ready_to_read = [this, &stream] {
|
m_internal_stream_data->read_notifier->on_activation = [this, &stream] {
|
||||||
constexpr size_t buffer_size = 256 * KiB;
|
constexpr size_t buffer_size = 256 * KiB;
|
||||||
static char buf[buffer_size];
|
static char buf[buffer_size];
|
||||||
do {
|
do {
|
||||||
|
|
|
@ -47,8 +47,8 @@ void TerminalWidget::set_pty_master_fd(int fd)
|
||||||
m_notifier = nullptr;
|
m_notifier = nullptr;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_notifier = Core::Notifier::construct(m_ptm_fd, Core::Notifier::Read);
|
m_notifier = Core::Notifier::construct(m_ptm_fd, Core::Notifier::Type::Read);
|
||||||
m_notifier->on_ready_to_read = [this] {
|
m_notifier->on_activation = [this] {
|
||||||
u8 buffer[BUFSIZ];
|
u8 buffer[BUFSIZ];
|
||||||
ssize_t nread = read(m_ptm_fd, buffer, sizeof(buffer));
|
ssize_t nread = read(m_ptm_fd, buffer, sizeof(buffer));
|
||||||
if (nread < 0) {
|
if (nread < 0) {
|
||||||
|
|
|
@ -19,8 +19,8 @@ SpiceAgent::SpiceAgent(int fd, ConnectionToClipboardServer& connection)
|
||||||
: m_fd(fd)
|
: m_fd(fd)
|
||||||
, m_clipboard_connection(connection)
|
, m_clipboard_connection(connection)
|
||||||
{
|
{
|
||||||
m_notifier = Core::Notifier::construct(fd, Core::Notifier::Read);
|
m_notifier = Core::Notifier::construct(fd, Core::Notifier::Type::Read);
|
||||||
m_notifier->on_ready_to_read = [this] {
|
m_notifier->on_activation = [this] {
|
||||||
on_message_received();
|
on_message_received();
|
||||||
};
|
};
|
||||||
m_clipboard_connection.on_data_changed = [this] {
|
m_clipboard_connection.on_data_changed = [this] {
|
||||||
|
|
|
@ -82,8 +82,8 @@ void Service::setup_notifier()
|
||||||
VERIFY(m_sockets.size() == 1);
|
VERIFY(m_sockets.size() == 1);
|
||||||
VERIFY(!m_socket_notifier);
|
VERIFY(!m_socket_notifier);
|
||||||
|
|
||||||
m_socket_notifier = Core::Notifier::construct(m_sockets[0].fd, Core::Notifier::Event::Read, this);
|
m_socket_notifier = Core::Notifier::construct(m_sockets[0].fd, Core::Notifier::Type::Read, this);
|
||||||
m_socket_notifier->on_ready_to_read = [this] {
|
m_socket_notifier->on_activation = [this] {
|
||||||
if (auto result = handle_socket_connection(); result.is_error())
|
if (auto result = handle_socket_connection(); result.is_error())
|
||||||
dbgln("{}", result.release_error());
|
dbgln("{}", result.release_error());
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,7 +21,7 @@ Client::Client(int id, NonnullOwnPtr<Core::TCPSocket> socket, int ptm_fd)
|
||||||
: m_id(id)
|
: m_id(id)
|
||||||
, m_socket(move(socket))
|
, m_socket(move(socket))
|
||||||
, m_ptm_fd(ptm_fd)
|
, m_ptm_fd(ptm_fd)
|
||||||
, m_ptm_notifier(Core::Notifier::construct(ptm_fd, Core::Notifier::Read))
|
, m_ptm_notifier(Core::Notifier::construct(ptm_fd, Core::Notifier::Type::Read))
|
||||||
{
|
{
|
||||||
m_socket->on_ready_to_read = [this] {
|
m_socket->on_ready_to_read = [this] {
|
||||||
auto result = drain_socket();
|
auto result = drain_socket();
|
||||||
|
@ -31,7 +31,7 @@ Client::Client(int id, NonnullOwnPtr<Core::TCPSocket> socket, int ptm_fd)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
m_ptm_notifier->on_ready_to_read = [this] {
|
m_ptm_notifier->on_activation = [this] {
|
||||||
auto result = drain_pty();
|
auto result = drain_pty();
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
dbgln("Failed to drain the PTY: {}", result.error());
|
dbgln("Failed to drain the PTY: {}", result.error());
|
||||||
|
|
|
@ -27,15 +27,15 @@ EventLoop::EventLoop()
|
||||||
m_wm_server = MUST(IPC::MultiServer<WMConnectionFromClient>::try_create("/tmp/portal/wm"));
|
m_wm_server = MUST(IPC::MultiServer<WMConnectionFromClient>::try_create("/tmp/portal/wm"));
|
||||||
|
|
||||||
if (m_keyboard_fd >= 0) {
|
if (m_keyboard_fd >= 0) {
|
||||||
m_keyboard_notifier = Core::Notifier::construct(m_keyboard_fd, Core::Notifier::Read);
|
m_keyboard_notifier = Core::Notifier::construct(m_keyboard_fd, Core::Notifier::Type::Read);
|
||||||
m_keyboard_notifier->on_ready_to_read = [this] { drain_keyboard(); };
|
m_keyboard_notifier->on_activation = [this] { drain_keyboard(); };
|
||||||
} else {
|
} else {
|
||||||
dbgln("Couldn't open /dev/input/keyboard/0");
|
dbgln("Couldn't open /dev/input/keyboard/0");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_mouse_fd >= 0) {
|
if (m_mouse_fd >= 0) {
|
||||||
m_mouse_notifier = Core::Notifier::construct(m_mouse_fd, Core::Notifier::Read);
|
m_mouse_notifier = Core::Notifier::construct(m_mouse_fd, Core::Notifier::Type::Read);
|
||||||
m_mouse_notifier->on_ready_to_read = [this] { drain_mouse(); };
|
m_mouse_notifier->on_activation = [this] { drain_mouse(); };
|
||||||
} else {
|
} else {
|
||||||
dbgln("Couldn't open /dev/input/mouse/0");
|
dbgln("Couldn't open /dev/input/mouse/0");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1742,7 +1742,7 @@ ErrorOr<void> Execute::for_each_entry(RefPtr<Shell> shell, Function<ErrorOr<Iter
|
||||||
|
|
||||||
Core::EventLoop loop;
|
Core::EventLoop loop;
|
||||||
|
|
||||||
auto notifier = Core::Notifier::construct(pipefd[0], Core::Notifier::Read);
|
auto notifier = Core::Notifier::construct(pipefd[0], Core::Notifier::Type::Read);
|
||||||
AllocatingMemoryStream stream;
|
AllocatingMemoryStream stream;
|
||||||
|
|
||||||
enum CheckResult {
|
enum CheckResult {
|
||||||
|
@ -1788,18 +1788,18 @@ ErrorOr<void> Execute::for_each_entry(RefPtr<Shell> shell, Function<ErrorOr<Iter
|
||||||
return NothingLeft;
|
return NothingLeft;
|
||||||
};
|
};
|
||||||
|
|
||||||
notifier->on_ready_to_read = [&]() -> void {
|
notifier->on_activation = [&]() -> void {
|
||||||
constexpr static auto buffer_size = 16;
|
constexpr static auto buffer_size = 16;
|
||||||
u8 buffer[buffer_size];
|
u8 buffer[buffer_size];
|
||||||
size_t remaining_size = buffer_size;
|
size_t remaining_size = buffer_size;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
notifier->set_event_mask(Core::Notifier::None);
|
notifier->set_type(Core::Notifier::Type::None);
|
||||||
bool should_enable_notifier = false;
|
bool should_enable_notifier = false;
|
||||||
|
|
||||||
ScopeGuard notifier_enabler { [&] {
|
ScopeGuard notifier_enabler { [&] {
|
||||||
if (should_enable_notifier)
|
if (should_enable_notifier)
|
||||||
notifier->set_event_mask(Core::Notifier::Read);
|
notifier->set_type(Core::Notifier::Type::Read);
|
||||||
} };
|
} };
|
||||||
|
|
||||||
if (check_and_call().release_value_but_fixme_should_propagate_errors() == Break) {
|
if (check_and_call().release_value_but_fixme_should_propagate_errors() == Break) {
|
||||||
|
@ -1841,7 +1841,7 @@ ErrorOr<void> Execute::for_each_entry(RefPtr<Shell> shell, Function<ErrorOr<Iter
|
||||||
|
|
||||||
auto exit_reason = loop.exec();
|
auto exit_reason = loop.exec();
|
||||||
|
|
||||||
notifier->on_ready_to_read = nullptr;
|
notifier->on_activation = nullptr;
|
||||||
|
|
||||||
if (close(pipefd[0]) < 0) {
|
if (close(pipefd[0]) < 0) {
|
||||||
dbgln("close() failed: {}", strerror(errno));
|
dbgln("close() failed: {}", strerror(errno));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue