LocalSocket: Make recvfrom() return 0 to signal EOF when peer is gone

Once the peer has disconnected, recvfrom() should always return 0 once
the socket buffer has been drained.
This commit is contained in:
Andreas Kling 2019-08-17 11:04:45 +02:00
parent 17670ae725
commit 910fab564e
Notes: sideshowbarker 2024-07-19 12:39:54 +09:00

View File

@ -234,16 +234,24 @@ ssize_t LocalSocket::recvfrom(FileDescription& description, void* buffer, size_t
auto role = this->role(description);
if (role == Role::Accepted) {
if (!description.is_blocking()) {
if (m_for_server.is_empty())
if (m_for_server.is_empty()) {
if (!has_attached_peer(description))
return 0;
return -EAGAIN;
}
}
ASSERT(!m_for_server.is_empty());
return m_for_server.read((u8*)buffer, buffer_size);
}
if (role == Role::Connected) {
if (!description.is_blocking()) {
if (m_for_client.is_empty())
if (m_for_client.is_empty()) {
if (!has_attached_peer(description))
return 0;
return -EAGAIN;
}
}
ASSERT(!m_for_client.is_empty());
return m_for_client.read((u8*)buffer, buffer_size);
}
ASSERT_NOT_REACHED();