io/FileDescriptor: add method SetPipeCapacity()

This commit is contained in:
Max Kellermann 2024-08-29 08:52:50 +02:00 committed by Max Kellermann
parent f535ccf9bf
commit ebfc83dac5
2 changed files with 24 additions and 0 deletions

View File

@ -213,6 +213,21 @@ FileDescriptor::DisableCloseOnExec() const noexcept
fcntl(fd, F_SETFD, old_flags & ~FD_CLOEXEC); fcntl(fd, F_SETFD, old_flags & ~FD_CLOEXEC);
} }
#ifdef __linux__
void
FileDescriptor::SetPipeCapacity(unsigned capacity) const noexcept
{
/* the canonical type for buffer sizes is "size_t", but since
F_SETPIPE_SZ expects an "int" parameter, "size_t" would
have the wrong size; "unsigned" is always the same size as
"int", but using a signed integer would suggest that
negative values are okay when they're not */
fcntl(fd, F_SETPIPE_SZ, capacity);
}
#endif
UniqueFileDescriptor UniqueFileDescriptor
FileDescriptor::Duplicate() const noexcept FileDescriptor::Duplicate() const noexcept
{ {

View File

@ -163,6 +163,15 @@ public:
*/ */
void DisableCloseOnExec() const noexcept; void DisableCloseOnExec() const noexcept;
#ifdef __linux__
/**
* Set the capacity of the pipe.
*
* This method ignores errors.
*/
void SetPipeCapacity(unsigned capacity) const noexcept;
#endif
/** /**
* Duplicate this file descriptor. * Duplicate this file descriptor.
* *