unique_ptr-like wrapper for a file descriptor
More...
unique_ptr-like wrapper for a file descriptor
The UniqueFD is a wrapper that owns and manages the lifetime of a file descriptor. It is constructed from a numerical file descriptor, and takes over its ownership. The file descriptor is closed when the UniqueFD is destroyed, or when it is assigned another file descriptor with operator=() or reset().
◆ UniqueFD() [1/2]
libcamera::UniqueFD::UniqueFD |
( |
int | fd | ) |
|
|
inlineexplicit |
Construct a UniqueFD that owns fd.
- Parameters
-
[in] | fd | A file descriptor to manage |
◆ UniqueFD() [2/2]
libcamera::UniqueFD::UniqueFD |
( |
UniqueFD && | other | ) |
|
|
inline |
Move constructor, create a UniqueFD by taking over other.
- Parameters
-
Create a UniqueFD by transferring ownership of the file descriptor owned by other. Upon return, the other UniqueFD is invalid.
◆ ~UniqueFD()
libcamera::UniqueFD::~UniqueFD |
( |
| ) |
|
|
inline |
Destroy the UniqueFD instance.
If a file descriptor is owned, it is closed.
◆ get()
int libcamera::UniqueFD::get |
( |
| ) |
const |
|
inline |
Retrieve the managed file descriptor.
- Returns
- The managed file descriptor, or -1 if no file descriptor is owned
◆ isValid()
bool libcamera::UniqueFD::isValid |
( |
| ) |
const |
|
inline |
Check if the UniqueFD owns a valid file descriptor.
- Returns
- True if the UniqueFD owns a valid file descriptor, false otherwise
◆ operator=()
Move assignment operator, replace a UniqueFD by taking over other.
- Parameters
-
If this UniqueFD owns a file descriptor, the file descriptor is closed first. The file descriptor is then replaced by the one of other. Upon return, other is invalid.
- Returns
- A reference to this UniqueFD
◆ release()
int libcamera::UniqueFD::release |
( |
| ) |
|
|
inlinenodiscard |
Release ownership of the file descriptor without closing it.
This function releases and returns the owned file descriptor without closing it. The caller owns the returned value and must take care of handling its life time to avoid file descriptor leakages. Upon return this UniqueFD is invalid.
- Returns
- The managed file descriptor, or -1 if no file descriptor was owned
◆ reset()
void libcamera::UniqueFD::reset |
( |
int | fd = -1 | ) |
|
Replace the managed file descriptor.
- Parameters
-
[in] | fd | The new file descriptor to manage |
Close the managed file descriptor, if any, and replace it with the new fd.
Self-resetting (passing an fd already managed by this instance) is invalid and results in undefined behaviour.
◆ swap()
void libcamera::UniqueFD::swap |
( |
UniqueFD & | other | ) |
|
|
inline |
Swap the managed file descriptors with another UniqueFD.
- Parameters
-
[in] | other | Another UniqueFD to swap the file descriptor with |
The documentation for this class was generated from the following files:
- include/libcamera/base/unique_fd.h
- src/libcamera/base/unique_fd.cpp