mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:57:45 +00:00
AK: Enable Core::File to switch blocking-mode during use
This closely mirrors Socket::set_blocking. Note that it does not make sense to make this a virtual method on a base class, since SeekableStream and FixedMemoryStream cannot possible be anything except than blocking.
This commit is contained in:
parent
6f8c2dc322
commit
62ebb78433
2 changed files with 16 additions and 0 deletions
|
@ -182,4 +182,13 @@ ErrorOr<void> File::truncate(size_t length)
|
||||||
return System::ftruncate(m_fd, length);
|
return System::ftruncate(m_fd, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> File::set_blocking(bool enabled)
|
||||||
|
{
|
||||||
|
// NOTE: This works fine on Serenity, but some systems out there don't support changing the blocking state of certain POSIX objects (message queues, pipes, etc) after their creation.
|
||||||
|
// Therefore, this method shouldn't be used in Lagom.
|
||||||
|
// https://github.com/SerenityOS/serenity/pull/18965#discussion_r1207951840
|
||||||
|
int value = enabled ? 0 : 1;
|
||||||
|
return System::ioctl(fd(), FIONBIO, &value);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,13 @@ public:
|
||||||
virtual ErrorOr<size_t> seek(i64 offset, SeekMode) override;
|
virtual ErrorOr<size_t> seek(i64 offset, SeekMode) override;
|
||||||
virtual ErrorOr<void> truncate(size_t length) override;
|
virtual ErrorOr<void> truncate(size_t length) override;
|
||||||
|
|
||||||
|
// Sets the blocking mode of the file. If blocking mode is disabled, reads
|
||||||
|
// will fail with EAGAIN when there's no data available to read, and writes
|
||||||
|
// will fail with EAGAIN when the data cannot be written without blocking
|
||||||
|
// (due to the send buffer being full, for example).
|
||||||
|
// See also Socket::set_blocking.
|
||||||
|
ErrorOr<void> set_blocking(bool enabled);
|
||||||
|
|
||||||
template<OneOf<::IPC::File, ::Core::MappedFile> VIP>
|
template<OneOf<::IPC::File, ::Core::MappedFile> VIP>
|
||||||
int leak_fd(Badge<VIP>)
|
int leak_fd(Badge<VIP>)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue