1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 12:17:35 +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:
Ben Wiederhake 2023-05-21 22:24:58 +02:00 committed by Andreas Kling
parent 6f8c2dc322
commit 62ebb78433
2 changed files with 16 additions and 0 deletions

View file

@ -182,4 +182,13 @@ ErrorOr<void> File::truncate(size_t 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);
}
}