1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:47:34 +00:00

LibChess: Allow UCIEndpoint to handle unexpected disconnections

This commit is contained in:
Tim Ledbetter 2023-04-02 21:02:17 +01:00 committed by Sam Atkins
parent bf320e4826
commit 680d4e34d5
2 changed files with 18 additions and 0 deletions

View file

@ -56,14 +56,27 @@ void Endpoint::event(Core::Event& event)
case Command::Type::Quit:
return handle_quit();
default:
Object::event(event);
break;
}
}
void Endpoint::custom_event(Core::CustomEvent& custom_event)
{
if (custom_event.custom_type() == EndpointEventType::UnexpectedEof)
handle_unexpected_eof();
}
void Endpoint::set_in_notifier()
{
m_in_notifier = Core::Notifier::construct(m_in->fd(), Core::Notifier::Read);
m_in_notifier->on_ready_to_read = [this] {
if (!m_in->can_read_line()) {
Core::EventLoop::current().post_event(*this, make<Core::CustomEvent>(EndpointEventType::UnexpectedEof));
m_in_notifier->set_enabled(false);
return;
}
while (m_in->can_read_line())
Core::EventLoop::current().post_event(*this, read_command());
};