|
static SharedFD | Accept (const FileInstance &listener, struct sockaddr *addr, socklen_t *addrlen) |
|
static SharedFD | Accept (const FileInstance &listener) |
|
static SharedFD | Dup (int unmanaged_fd) |
|
static SharedFD | Open (const char *pathname, int flags, mode_t mode=0) |
|
static SharedFD | Open (const std::string &pathname, int flags, mode_t mode=0) |
|
static SharedFD | InotifyFd () |
|
static SharedFD | Creat (const std::string &pathname, mode_t mode) |
|
static int | Fchdir (SharedFD) |
|
static Result< SharedFD > | Fifo (const std::string &pathname, mode_t mode) |
|
static bool | Pipe (SharedFD *fd0, SharedFD *fd1) |
|
static SharedFD | MemfdCreate (const std::string &name, unsigned int flags=0) |
|
static SharedFD | MemfdCreateWithData (const std::string &name, const std::string &data, unsigned int flags=0) |
|
static SharedFD | Mkstemp (std::string *path) |
|
static Result< std::pair< SharedFD, std::string > > | Mkostemp (std::string_view path, int flags=O_CLOEXEC) |
|
static int | Poll (PollSharedFd *fds, size_t num_fds, int timeout) |
|
static int | Poll (std::vector< PollSharedFd > &fds, int timeout) |
|
static bool | SocketPair (int domain, int type, int protocol, SharedFD *fd0, SharedFD *fd1) |
|
static Result< std::pair< SharedFD, SharedFD > > | SocketPair (int domain, int type, int protocol) |
|
static SharedFD | Socket (int domain, int socket_type, int protocol) |
|
static SharedFD | SocketLocalClient (const std::string &name, bool is_abstract, int in_type) |
|
static SharedFD | SocketLocalClient (const std::string &name, bool is_abstract, int in_type, int timeout_seconds) |
|
static SharedFD | SocketLocalClient (int port, int type) |
|
static SharedFD | SocketClient (const std::string &host, int port, int type, std::chrono::seconds timeout=std::chrono::seconds(0)) |
|
static SharedFD | Socket6Client (const std::string &host, const std::string &interface, int port, int type, std::chrono::seconds timeout=std::chrono::seconds(0)) |
|
static SharedFD | SocketLocalServer (const std::string &name, bool is_abstract, int in_type, mode_t mode) |
|
static SharedFD | SocketLocalServer (int port, int type) |
|
Counted reference to a FileInstance.
This is also the place where most new FileInstances are created. The creation methods correspond to the underlying POSIX calls.
SharedFDs can be compared and stored in STL containers. The semantics are slightly different from POSIX file descriptors:
o The value of the SharedFD is the identity of its underlying FileInstance.
o Each newly created SharedFD has a unique, closed FileInstance: SharedFD a, b; assert (a != b); a = b; assert(a == b);
o The identity of the FileInstance is not affected by closing the file: SharedFD a, b; set<SharedFD> s; s.insert(a); assert(s.count(a) == 1); assert(s.count(b) == 0); a->Close(); assert(s.count(a) == 1); assert(s.count(b) == 0);
o FileInstances are never visibly recycled.
o If all of the SharedFDs referring to a FileInstance go out of scope the file is closed and the FileInstance is recycled.
Creation methods must ensure that no references to the new file descriptor escape. The underlying FileInstance should have the only reference to the file descriptor. Any method that needs to know the fd must be in either SharedFD or FileInstance.
SharedFDs always have an underlying FileInstance, so all of the method calls are safe in accordance with the null object pattern.
Errors on system calls that create new FileInstances, such as Open, are reported with a new, closed FileInstance with the errno set.