dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
dfx::FdWatch::OwnedFd Class Reference

Owning RAII wrapper around a file descriptor. More...

#include <dfx-fdwatch/OwnedFd.hpp>

Public Member Functions

 OwnedFd () noexcept
 Create an invalid OwnedFd.
 OwnedFd (int fd) noexcept
 Take ownership of a file descriptor.
 OwnedFd (OwnedFd &&other) noexcept
 Move constructor.
 DISABLE_COPY (OwnedFd)
 ~OwnedFd ()
 Destroy the OwnedFd and close the file descriptor if valid.
OwnedFdoperator= (OwnedFd &&other) noexcept
 Move assignment operator.
bool operator== (OwnedFd const &) const noexcept=delete
bool operator!= (OwnedFd const &) const noexcept=delete
bool operator== (int fd) const noexcept
bool operator== (BorrowedFd const &fd) const noexcept
void swap (OwnedFd &other) noexcept
bool isValid () const noexcept
 Check if this object owns a valid file descriptor.
int get () const noexcept
 Get the owned file descriptor.
void close () noexcept
 Close the owned file descriptor.
int release () noexcept
 Release ownership of the file descriptor.
void reset (int newFd=-1) noexcept
 Replace the owned file descriptor.
BorrowedFd borrow () const noexcept
 Create a non-owning view of the owned file descriptor.

Detailed Description

Owning RAII wrapper around a file descriptor.

OwnedFd uniquely owns a file descriptor and is responsible for closing it. The descriptor is closed on destruction unless ownership has been released.

This type is move-only. Copying is disabled to enforce unique ownership.

An invalid OwnedFd is represented by a value of -1.

Ownership can be transferred via move construction or move assignment. Ownership can be explicitly released using release().

See also
BorrowedFd

Constructor & Destructor Documentation

◆ OwnedFd() [1/3]

dfx::FdWatch::OwnedFd::OwnedFd ( )
noexcept

Create an invalid OwnedFd.

◆ OwnedFd() [2/3]

dfx::FdWatch::OwnedFd::OwnedFd ( int fd)
explicitnoexcept

Take ownership of a file descriptor.

Parameters
fdFile descriptor to own
Note
This object becomes responsible for closing fd.

◆ OwnedFd() [3/3]

dfx::FdWatch::OwnedFd::OwnedFd ( OwnedFd && other)
noexcept

Move constructor.

Note
Transfers ownership from other. other becomes invalid.

◆ ~OwnedFd()

dfx::FdWatch::OwnedFd::~OwnedFd ( )

Destroy the OwnedFd and close the file descriptor if valid.

Member Function Documentation

◆ borrow()

BorrowedFd dfx::FdWatch::OwnedFd::borrow ( ) const
inlinenodiscardnoexcept

Create a non-owning view of the owned file descriptor.

Returns
A BorrowedFd referring to the same descriptor
Note
The returned BorrowedFd is only valid as long as this OwnedFd remains valid.

◆ close()

void dfx::FdWatch::OwnedFd::close ( )
noexcept

Close the owned file descriptor.

Note
After this call, the object becomes invalid.

◆ get()

int dfx::FdWatch::OwnedFd::get ( ) const
inlinenoexcept

Get the owned file descriptor.

Returns
The file descriptor, or -1 if invalid

◆ isValid()

bool dfx::FdWatch::OwnedFd::isValid ( ) const
inlinenoexcept

Check if this object owns a valid file descriptor.

◆ operator=()

OwnedFd & dfx::FdWatch::OwnedFd::operator= ( OwnedFd && other)
noexcept

Move assignment operator.

Note
Closes the currently owned descriptor (if any) and takes ownership from other. other becomes invalid.

◆ release()

int dfx::FdWatch::OwnedFd::release ( )
noexcept

Release ownership of the file descriptor.

Returns
The owned file descriptor, or -1 if invalid
Note
The caller becomes responsible for closing the returned descriptor.

◆ reset()

void dfx::FdWatch::OwnedFd::reset ( int newFd = -1)
noexcept

Replace the owned file descriptor.

Parameters
newFdNew file descriptor to own, or -1 to invalidate
Note
Closes the currently owned descriptor if valid.

The documentation for this class was generated from the following file: