|
| 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 bool | Pipe (SharedFD *fd0, SharedFD *fd1) |
| |
| static SharedFD | MemfdCreateWithData (const std::string &name, const std::string &data, unsigned int flags=0) |
| |
| 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 Fd.
This is also the place where most new Fds 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 Fd.
o Each newly created SharedFD has a unique, closed Fd: SharedFD a, b; assert (a != b); a = b; assert(a == b);
o The identity of the Fd 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 Fds are never visibly recycled.
o If all of the SharedFDs referring to a Fd go out of scope the file is closed and the Fd is recycled.
Creation methods must ensure that no references to the new file descriptor escape. The underlying Fd should have the only reference to the file descriptor. Any method that needs to know the fd must be in either SharedFD or Fd.
SharedFDs always have an underlying Fd, so all of the method calls are safe in accordance with the null object pattern.
Errors on system calls that create new Fds, such as Open, are reported with a new, closed Fd with the errno set.