LibCore: Move PosixSocketHelper's read EOF handling to a helper

We'll call this from upcoming LocalSocket methods directly
This commit is contained in:
Andrew Kaster 2024-04-17 16:39:57 -06:00 committed by Tim Flynn
commit 0e699743c4
Notes: sideshowbarker 2024-07-17 01:46:43 +09:00
2 changed files with 11 additions and 4 deletions

View file

@ -105,15 +105,21 @@ ErrorOr<Bytes> PosixSocketHelper::read(Bytes buffer, int flags)
}
ssize_t nread = TRY(System::recv(m_fd, buffer.data(), buffer.size(), flags));
m_last_read_was_eof = nread == 0;
if (nread == 0)
did_reach_eof_on_read();
return buffer.trim(nread);
}
void PosixSocketHelper::did_reach_eof_on_read()
{
m_last_read_was_eof = true;
// If a socket read is EOF, then no more data can be read from it because
// the protocol has disconnected. In this case, we can just disable the
// notifier if we have one.
if (m_last_read_was_eof && m_notifier)
if (m_notifier)
m_notifier->set_enabled(false);
return buffer.trim(nread);
}
ErrorOr<size_t> PosixSocketHelper::write(ReadonlyBytes buffer, int flags)