diff --git a/Libraries/LibCore/CoreIPCClient.h b/Libraries/LibCore/CoreIPCClient.h index a16ca22821..d5f93ee7c5 100644 --- a/Libraries/LibCore/CoreIPCClient.h +++ b/Libraries/LibCore/CoreIPCClient.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -145,10 +146,19 @@ namespace Client { ++iov_count; } - int nwritten = writev(m_connection->fd(), iov, iov_count); - if (nwritten < 0) { - perror("writev"); - ASSERT_NOT_REACHED(); + int nwritten; + + for (;;) { + nwritten = writev(m_connection->fd(), iov, iov_count); + if (nwritten < 0) { + if (errno == EAGAIN) { + sched_yield(); + continue; + } + perror("writev"); + ASSERT_NOT_REACHED(); + } + break; } ASSERT((size_t)nwritten == sizeof(message) + extra_data.size()); diff --git a/Libraries/LibCore/CoreIPCServer.h b/Libraries/LibCore/CoreIPCServer.h index 73b3130379..d5d67619b9 100644 --- a/Libraries/LibCore/CoreIPCServer.h +++ b/Libraries/LibCore/CoreIPCServer.h @@ -8,8 +8,8 @@ #include #include #include - #include +#include #include #include #include @@ -104,21 +104,26 @@ namespace Server { ++iov_count; } - int nwritten = writev(m_socket->fd(), iov, iov_count); - if (nwritten < 0) { - switch (errno) { - case EPIPE: - dbgprintf("Connection::post_message: Disconnected from peer.\n"); - shutdown(); - return; - case EAGAIN: - dbgprintf("Connection::post_message: Client buffer overflowed.\n"); - did_misbehave(); - return; - default: - perror("Connection::post_message writev"); - ASSERT_NOT_REACHED(); + int nwritten = 0; + for (;;) { + nwritten = writev(m_socket->fd(), iov, iov_count); + if (nwritten < 0) { + switch (errno) { + case EPIPE: + dbgprintf("Connection::post_message: Disconnected from peer.\n"); + shutdown(); + return; + case EAGAIN: + // FIXME: It would be better to push these onto a queue so we can go back + // to servicing other clients. + sched_yield(); + continue; + default: + perror("Connection::post_message writev"); + ASSERT_NOT_REACHED(); + } } + break; } ASSERT(nwritten == (int)(sizeof(message) + extra_data.size()));