mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
Kernel: Properly handle non-blocking I/O on pipes
Previously, non-blocking read operations on pipes returned EOF instead of EAGAIN and non-blocking write operations blocked. This fixes pkgsrc's bmake "eof on job pipe!" error message when running in non-compatibility mode.
This commit is contained in:
parent
b7dae4f90e
commit
4c4b8ea443
Notes:
sideshowbarker
2024-07-18 07:09:09 +09:00
Author: https://github.com/boricj Commit: https://github.com/SerenityOS/serenity/commit/4c4b8ea443b Pull-request: https://github.com/SerenityOS/serenity/pull/9330 Reviewed-by: https://github.com/gunnarbeutner ✅
1 changed files with 10 additions and 4 deletions
|
@ -131,19 +131,25 @@ bool FIFO::can_write(const FileDescription&, size_t) const
|
|||
return m_buffer->space_for_writing() || !m_readers;
|
||||
}
|
||||
|
||||
KResultOr<size_t> FIFO::read(FileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
|
||||
KResultOr<size_t> FIFO::read(FileDescription& fd, u64, UserOrKernelBuffer& buffer, size_t size)
|
||||
{
|
||||
if (!m_writers && m_buffer->is_empty())
|
||||
return 0;
|
||||
if (m_buffer->is_empty()) {
|
||||
if (!m_writers)
|
||||
return 0;
|
||||
if (m_writers && !fd.is_blocking())
|
||||
return EAGAIN;
|
||||
}
|
||||
return m_buffer->read(buffer, size);
|
||||
}
|
||||
|
||||
KResultOr<size_t> FIFO::write(FileDescription&, u64, const UserOrKernelBuffer& buffer, size_t size)
|
||||
KResultOr<size_t> FIFO::write(FileDescription& fd, u64, const UserOrKernelBuffer& buffer, size_t size)
|
||||
{
|
||||
if (!m_readers) {
|
||||
Thread::current()->send_signal(SIGPIPE, Process::current());
|
||||
return EPIPE;
|
||||
}
|
||||
if (!fd.is_blocking() && m_buffer->space_for_writing() == 0)
|
||||
return EAGAIN;
|
||||
|
||||
return m_buffer->write(buffer, size);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue