io/UniqueFileDescriptor: add method Release()

This commit is contained in:
Max Kellermann 2020-10-14 20:37:29 +02:00
parent 48afb68f3a
commit 1c079e554b
1 changed files with 8 additions and 0 deletions

View File

@ -64,6 +64,14 @@ public:
return *this; return *this;
} }
/**
* Release ownership and return the descriptor as an unmanaged
* #FileDescriptor instance.
*/
FileDescriptor Release() noexcept {
return std::exchange(*(FileDescriptor *)this, Undefined());
}
protected: protected:
void Set(int _fd) noexcept { void Set(int _fd) noexcept {
assert(!IsDefined()); assert(!IsDefined());