Android-cuttlefish cvd tool
|
#include <shared_fd.h>
Public Member Functions | |
virtual | ~FileInstance () |
int | Bind (const struct sockaddr *addr, socklen_t addrlen) |
int | Connect (const struct sockaddr *addr, socklen_t addrlen) |
int | ConnectWithTimeout (const struct sockaddr *addr, socklen_t addrlen, struct timeval *timeout) |
void | Close () |
bool | Chmod (mode_t mode) |
bool | CopyFrom (FileInstance &in, size_t length, FileInstance *stop=nullptr) |
bool | CopyAllFrom (FileInstance &in, FileInstance *stop=nullptr) |
int | UNMANAGED_Dup () |
int | UNMANAGED_Dup2 (int newfd) |
int | Fchdir () |
int | Fcntl (int command, int value) |
int | Fsync () |
Result< void > | Flock (int operation) |
int | GetErrno () const |
int | GetSockName (struct sockaddr *addr, socklen_t *addrlen) |
int | Ioctl (int request, void *val=nullptr) |
bool | IsOpen () const |
bool | IsSet (fd_set *in) const |
bool | IsRegular () const |
int | LinkAtCwd (const std::string &path) |
int | Listen (int backlog) |
off_t | LSeek (off_t offset, int whence) |
ssize_t | Recv (void *buf, size_t len, int flags) |
ssize_t | RecvMsg (struct msghdr *msg, int flags) |
ssize_t | Read (void *buf, size_t count) |
ssize_t | Send (const void *buf, size_t len, int flags) |
ssize_t | SendMsg (const struct msghdr *msg, int flags) |
template<typename... Args> | |
ssize_t | SendFileDescriptors (const void *buf, size_t len, Args &&... sent_fds) |
int | Shutdown (int how) |
void | Set (fd_set *dest, int *max_index) const |
int | SetSockOpt (int level, int optname, const void *optval, socklen_t optlen) |
int | GetSockOpt (int level, int optname, void *optval, socklen_t *optlen) |
int | SetTerminalRaw () |
std::string | StrError () const |
ScopedMMap | MMap (void *addr, size_t length, int prot, int flags, off_t offset) |
ssize_t | Truncate (off_t length) |
ssize_t | Write (const void *buf, size_t count) |
bool | IsATTY () |
int | Futimens (const struct timespec times[2]) |
Result< std::string > | ProcFdLinkTarget () const |
int | InotifyAddWatch (const std::string &pathname, uint32_t mask) |
void | InotifyRmWatch (int watch) |
Static Public Member Functions | |
static std::shared_ptr< FileInstance > | ClosedInstance () |
static void | Log (const char *message) |
Private Member Functions | |
FileInstance (int fd, int in_errno) | |
FileInstance * | Accept (struct sockaddr *addr, socklen_t *addrlen) const |
Private Attributes | |
int | fd_ |
int | errno_ |
std::string | identity_ |
bool | is_regular_file_ |
Friends | |
class | SharedFD |
class | Epoll |
Tracks the lifetime of a file descriptor and provides methods to allow callers to use the file without knowledge of the underlying descriptor number.
FileInstances have two states: Open and Closed. They may start in either state. However, once a FileIntance enters the Closed state it cannot be reopened.
Construction of FileInstances is limited to select classes to avoid escaping file descriptors. At this point SharedFD is the only class that has access. We may eventually have ScopedFD and WeakFD.
|
inlinevirtual |
|
private |
|
private |
int cuttlefish::FileInstance::Bind | ( | const struct sockaddr * | addr, |
socklen_t | addrlen | ||
) |
bool cuttlefish::FileInstance::Chmod | ( | mode_t | mode | ) |
void cuttlefish::FileInstance::Close | ( | ) |
|
static |
int cuttlefish::FileInstance::Connect | ( | const struct sockaddr * | addr, |
socklen_t | addrlen | ||
) |
int cuttlefish::FileInstance::ConnectWithTimeout | ( | const struct sockaddr * | addr, |
socklen_t | addrlen, | ||
struct timeval * | timeout | ||
) |
bool cuttlefish::FileInstance::CopyAllFrom | ( | FileInstance & | in, |
FileInstance * | stop = nullptr |
||
) |
bool cuttlefish::FileInstance::CopyFrom | ( | FileInstance & | in, |
size_t | length, | ||
FileInstance * | stop = nullptr |
||
) |
int cuttlefish::FileInstance::Fchdir | ( | ) |
int cuttlefish::FileInstance::Fcntl | ( | int | command, |
int | value | ||
) |
Result< void > cuttlefish::FileInstance::Flock | ( | int | operation | ) |
int cuttlefish::FileInstance::Fsync | ( | ) |
int cuttlefish::FileInstance::Futimens | ( | const struct timespec | times[2] | ) |
|
inline |
int cuttlefish::FileInstance::GetSockName | ( | struct sockaddr * | addr, |
socklen_t * | addrlen | ||
) |
int cuttlefish::FileInstance::GetSockOpt | ( | int | level, |
int | optname, | ||
void * | optval, | ||
socklen_t * | optlen | ||
) |
int cuttlefish::FileInstance::InotifyAddWatch | ( | const std::string & | pathname, |
uint32_t | mask | ||
) |
void cuttlefish::FileInstance::InotifyRmWatch | ( | int | watch | ) |
int cuttlefish::FileInstance::Ioctl | ( | int | request, |
void * | val = nullptr |
||
) |
bool cuttlefish::FileInstance::IsATTY | ( | ) |
|
inline |
|
inline |
bool cuttlefish::FileInstance::IsSet | ( | fd_set * | in | ) | const |
int cuttlefish::FileInstance::LinkAtCwd | ( | const std::string & | path | ) |
Adds a hard link to a file descriptor, based on the current working directory of the process or to some absolute path.
https://www.man7.org/linux/man-pages/man2/linkat.2.html
Using this on a file opened with O_TMPFILE can link it into the filesystem.
int cuttlefish::FileInstance::Listen | ( | int | backlog | ) |
|
static |
off_t cuttlefish::FileInstance::LSeek | ( | off_t | offset, |
int | whence | ||
) |
ScopedMMap cuttlefish::FileInstance::MMap | ( | void * | addr, |
size_t | length, | ||
int | prot, | ||
int | flags, | ||
off_t | offset | ||
) |
Result< std::string > cuttlefish::FileInstance::ProcFdLinkTarget | ( | ) | const |
ssize_t cuttlefish::FileInstance::Read | ( | void * | buf, |
size_t | count | ||
) |
ssize_t cuttlefish::FileInstance::Recv | ( | void * | buf, |
size_t | len, | ||
int | flags | ||
) |
ssize_t cuttlefish::FileInstance::RecvMsg | ( | struct msghdr * | msg, |
int | flags | ||
) |
ssize_t cuttlefish::FileInstance::Send | ( | const void * | buf, |
size_t | len, | ||
int | flags | ||
) |
|
inline |
ssize_t cuttlefish::FileInstance::SendMsg | ( | const struct msghdr * | msg, |
int | flags | ||
) |
void cuttlefish::FileInstance::Set | ( | fd_set * | dest, |
int * | max_index | ||
) | const |
int cuttlefish::FileInstance::SetSockOpt | ( | int | level, |
int | optname, | ||
const void * | optval, | ||
socklen_t | optlen | ||
) |
int cuttlefish::FileInstance::SetTerminalRaw | ( | ) |
int cuttlefish::FileInstance::Shutdown | ( | int | how | ) |
std::string cuttlefish::FileInstance::StrError | ( | ) | const |
ssize_t cuttlefish::FileInstance::Truncate | ( | off_t | length | ) |
int cuttlefish::FileInstance::UNMANAGED_Dup | ( | ) |
int cuttlefish::FileInstance::UNMANAGED_Dup2 | ( | int | newfd | ) |
ssize_t cuttlefish::FileInstance::Write | ( | const void * | buf, |
size_t | count | ||
) |
|
friend |
|
friend |
|
private |
|
private |
|
private |
|
private |