mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 17:49:40 +00:00
LibCore: Move PosixSocketHelper's read EOF handling to a helper
We'll call this from upcoming LocalSocket methods directly
This commit is contained in:
parent
1e749d023a
commit
0e699743c4
Notes:
sideshowbarker
2024-07-17 01:46:43 +09:00
Author: https://github.com/ADKaster
Commit: 0e699743c4
Pull-request: https://github.com/SerenityOS/serenity/pull/24025
Issue: https://github.com/SerenityOS/serenity/issues/22357
Reviewed-by: https://github.com/trflynn89 ✅
2 changed files with 11 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue