Android-cuttlefish cvd tool
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
cuttlefish::FileInstance Class Reference

#include <shared_fd.h>

Collaboration diagram for cuttlefish::FileInstance:
Collaboration graph
[legend]

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< FileInstanceClosedInstance ()
 
static void Log (const char *message)
 

Private Member Functions

 FileInstance (int fd, int in_errno)
 
FileInstanceAccept (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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ~FileInstance()

virtual cuttlefish::FileInstance::~FileInstance ( )
inlinevirtual

◆ FileInstance()

cuttlefish::FileInstance::FileInstance ( int  fd,
int  in_errno 
)
private

Member Function Documentation

◆ Accept()

FileInstance * cuttlefish::FileInstance::Accept ( struct sockaddr *  addr,
socklen_t *  addrlen 
) const
private

◆ Bind()

int cuttlefish::FileInstance::Bind ( const struct sockaddr *  addr,
socklen_t  addrlen 
)

◆ Chmod()

bool cuttlefish::FileInstance::Chmod ( mode_t  mode)

◆ Close()

void cuttlefish::FileInstance::Close ( )

◆ ClosedInstance()

std::shared_ptr< FileInstance > cuttlefish::FileInstance::ClosedInstance ( )
static

◆ Connect()

int cuttlefish::FileInstance::Connect ( const struct sockaddr *  addr,
socklen_t  addrlen 
)

◆ ConnectWithTimeout()

int cuttlefish::FileInstance::ConnectWithTimeout ( const struct sockaddr *  addr,
socklen_t  addrlen,
struct timeval *  timeout 
)

◆ CopyAllFrom()

bool cuttlefish::FileInstance::CopyAllFrom ( FileInstance in,
FileInstance stop = nullptr 
)

◆ CopyFrom()

bool cuttlefish::FileInstance::CopyFrom ( FileInstance in,
size_t  length,
FileInstance stop = nullptr 
)

◆ Fchdir()

int cuttlefish::FileInstance::Fchdir ( )

◆ Fcntl()

int cuttlefish::FileInstance::Fcntl ( int  command,
int  value 
)

◆ Flock()

Result< void > cuttlefish::FileInstance::Flock ( int  operation)

◆ Fsync()

int cuttlefish::FileInstance::Fsync ( )

◆ Futimens()

int cuttlefish::FileInstance::Futimens ( const struct timespec  times[2])

◆ GetErrno()

int cuttlefish::FileInstance::GetErrno ( ) const
inline

◆ GetSockName()

int cuttlefish::FileInstance::GetSockName ( struct sockaddr *  addr,
socklen_t *  addrlen 
)

◆ GetSockOpt()

int cuttlefish::FileInstance::GetSockOpt ( int  level,
int  optname,
void *  optval,
socklen_t *  optlen 
)

◆ InotifyAddWatch()

int cuttlefish::FileInstance::InotifyAddWatch ( const std::string &  pathname,
uint32_t  mask 
)

◆ InotifyRmWatch()

void cuttlefish::FileInstance::InotifyRmWatch ( int  watch)

◆ Ioctl()

int cuttlefish::FileInstance::Ioctl ( int  request,
void *  val = nullptr 
)

◆ IsATTY()

bool cuttlefish::FileInstance::IsATTY ( )

◆ IsOpen()

bool cuttlefish::FileInstance::IsOpen ( ) const
inline

◆ IsRegular()

bool cuttlefish::FileInstance::IsRegular ( ) const
inline

◆ IsSet()

bool cuttlefish::FileInstance::IsSet ( fd_set *  in) const

◆ LinkAtCwd()

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.

◆ Listen()

int cuttlefish::FileInstance::Listen ( int  backlog)

◆ Log()

void cuttlefish::FileInstance::Log ( const char *  message)
static

◆ LSeek()

off_t cuttlefish::FileInstance::LSeek ( off_t  offset,
int  whence 
)

◆ MMap()

ScopedMMap cuttlefish::FileInstance::MMap ( void *  addr,
size_t  length,
int  prot,
int  flags,
off_t  offset 
)

◆ ProcFdLinkTarget()

Result< std::string > cuttlefish::FileInstance::ProcFdLinkTarget ( ) const

◆ Read()

ssize_t cuttlefish::FileInstance::Read ( void *  buf,
size_t  count 
)

◆ Recv()

ssize_t cuttlefish::FileInstance::Recv ( void *  buf,
size_t  len,
int  flags 
)

◆ RecvMsg()

ssize_t cuttlefish::FileInstance::RecvMsg ( struct msghdr *  msg,
int  flags 
)

◆ Send()

ssize_t cuttlefish::FileInstance::Send ( const void *  buf,
size_t  len,
int  flags 
)

◆ SendFileDescriptors()

template<typename... Args>
ssize_t cuttlefish::FileInstance::SendFileDescriptors ( const void *  buf,
size_t  len,
Args &&...  sent_fds 
)
inline

◆ SendMsg()

ssize_t cuttlefish::FileInstance::SendMsg ( const struct msghdr *  msg,
int  flags 
)

◆ Set()

void cuttlefish::FileInstance::Set ( fd_set *  dest,
int *  max_index 
) const

◆ SetSockOpt()

int cuttlefish::FileInstance::SetSockOpt ( int  level,
int  optname,
const void *  optval,
socklen_t  optlen 
)

◆ SetTerminalRaw()

int cuttlefish::FileInstance::SetTerminalRaw ( )

◆ Shutdown()

int cuttlefish::FileInstance::Shutdown ( int  how)

◆ StrError()

std::string cuttlefish::FileInstance::StrError ( ) const

◆ Truncate()

ssize_t cuttlefish::FileInstance::Truncate ( off_t  length)

◆ UNMANAGED_Dup()

int cuttlefish::FileInstance::UNMANAGED_Dup ( )

◆ UNMANAGED_Dup2()

int cuttlefish::FileInstance::UNMANAGED_Dup2 ( int  newfd)

◆ Write()

ssize_t cuttlefish::FileInstance::Write ( const void *  buf,
size_t  count 
)

Friends And Related Function Documentation

◆ Epoll

friend class Epoll
friend

◆ SharedFD

friend class SharedFD
friend

Member Data Documentation

◆ errno_

int cuttlefish::FileInstance::errno_
private

◆ fd_

int cuttlefish::FileInstance::fd_
private

◆ identity_

std::string cuttlefish::FileInstance::identity_
private

◆ is_regular_file_

bool cuttlefish::FileInstance::is_regular_file_
private

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