Class upisnd::ValueFd#
Detailed Description#
Takes care of managing the lifetime of the fd.
You may retrieve the fd value using get() or take ownership of it using take(). If you take the ownership, the ValueFd object will immediately forget about the fd, and you'll be responsible to close
it yourself.
#include <value_fd.h>
Public Functions#
Type | Name |
---|---|
ValueFd () |
|
ValueFd (int fd) Creates a ValueFd from an existing fd, takes ownership of it, so it will close it in the destructor. |
|
~ValueFd () |
|
ValueFd (const ValueFd & rhs) Copy constructor, duplicates the fd using F_DUPFD_CLOEXEC fcntl call. |
|
ValueFd & | operator= (const ValueFd & rhs) Copy assignment operator, first it closes any valid fd it may have had, then duplicates the rhs fd using F_DUPFD_CLOEXEC fcntl call. |
ValueFd (ValueFd && rhs) Move constructor, moves take ownership of the fd. |
|
ValueFd & | operator= (ValueFd && rhs) Move assignment operator, first it closes any valid fd it may have had, then assumes ownership of the rhs fd, invalidating the rhs object. |
bool | isValid () const Returns true if the object holds a valid fd. |
int | take () Returns the fd value, and won't close it in the destructor, transferring ownership. |
int | get () const Returns the fd value for your use, but keeps ownership, and will close it upon destruction. |
int | close () Closes the fd and forgets about it. |
int | write (int value) Outputs a decimal number to the fd. |
int | read (int * err=NULL) const |
ValueFd [1/4]#
upisnd::ValueFd::ValueFd ()
ValueFd [2/4]#
Creates a ValueFd from an existing fd, takes ownership of it, so it will close it in the destructor.
explicit upisnd::ValueFd::ValueFd (
int fd
)
~ValueFd#
upisnd::ValueFd::~ValueFd ()
ValueFd [3/4]#
Copy constructor, duplicates the fd using F_DUPFD_CLOEXEC fcntl call.
upisnd::ValueFd::ValueFd (
const ValueFd & rhs
)
operator=#
Copy assignment operator, first it closes any valid fd it may have had, then duplicates the rhs fd using F_DUPFD_CLOEXEC fcntl call.
ValueFd & upisnd::ValueFd::operator= (
const ValueFd & rhs
)
ValueFd [4/4]#
Move constructor, moves take ownership of the fd.
upisnd::ValueFd::ValueFd (
ValueFd && rhs
)
operator=#
Move assignment operator, first it closes any valid fd it may have had, then assumes ownership of the rhs fd, invalidating the rhs object.
ValueFd & upisnd::ValueFd::operator= (
ValueFd && rhs
)
isValid#
Returns true if the object holds a valid fd.
bool upisnd::ValueFd::isValid () const
take#
Returns the fd value, and won't close it in the destructor, transferring ownership.
int upisnd::ValueFd::take ()
get#
Returns the fd value for your use, but keeps ownership, and will close it upon destruction.
int upisnd::ValueFd::get () const
close#
Closes the fd and forgets about it.
int upisnd::ValueFd::close ()
write#
Outputs a decimal number to the fd.
int upisnd::ValueFd::write (
int value
)
read#
int upisnd::ValueFd::read (
int * err=NULL
) const
Reads a decimal number from the fd and returns it as integer.
Parameters:
err
If not NULL, will be set to theerrno
value if the read failed, 0 otherwise.