LibIPC: Actually yield to the event loop when EMSGSIZE or EAGAIN

Previously this just yielded the time slice, which blocked the event
loop until the other side read some data from the socket.
This "fixed" impl is still equally bad, but at least it doesn't block
the event loop.
This commit is contained in:
Ali Mohammad Pur 2024-06-13 13:42:28 +02:00 committed by Ali Mohammad Pur
parent ba54c9adb2
commit 30c41835e6

View file

@ -5,6 +5,7 @@
*/
#include <AK/Checked.h>
#include <LibCore/EventLoop.h>
#include <LibCore/Socket.h>
#include <LibIPC/Message.h>
#include <sched.h>
@ -75,8 +76,8 @@ ErrorOr<void> MessageBuffer::transfer_message(Core::LocalSocket& socket)
if (auto error = maybe_nwritten.release_error(); error.is_errno()) {
// FIXME: This is a hacky way to at least not crash on large messages
// The limit of 100 writes is arbitrary, and there to prevent indefinite spinning on the EventLoop
if (error.code() == EAGAIN && writes_done < 100) {
sched_yield();
if ((error.code() == EAGAIN || error.code() == EMSGSIZE) && writes_done < 100) {
Core::EventLoop::current().pump();
continue;
}