|
proxygen
|
#include <File.h>
Public Member Functions | |
| File () noexcept | |
| File (int fd, bool ownsFd=false) noexcept | |
| File (const char *name, int flags=O_RDONLY, mode_t mode=0666) | |
| File (const std::string &name, int flags=O_RDONLY, mode_t mode=0666) | |
| File (StringPiece name, int flags=O_RDONLY, mode_t mode=0666) | |
| ~File () | |
| int | fd () const |
| operator bool () const | |
| File | dup () const |
| void | close () |
| bool | closeNoThrow () |
| int | release () noexcept |
| void | swap (File &other) noexcept |
| File (File &&) noexcept | |
| File & | operator= (File &&) |
| void | lock () |
| bool | try_lock () |
| void | unlock () |
| void | lock_shared () |
| bool | try_lock_shared () |
| void | unlock_shared () |
Static Public Member Functions | |
| template<typename... Args> | |
| static Expected< File, exception_wrapper > | makeFile (Args &&...args) noexcept |
| static File | temporary () |
Private Member Functions | |
| void | doLock (int op) |
| bool | doTryLock (int op) |
| File (const File &)=delete | |
| File & | operator= (const File &)=delete |
Private Attributes | |
| int | fd_ |
| bool | ownsFd_ |
|
noexcept |
Creates an empty File object, for late initialization.
Definition at line 33 of file File.cpp.
Referenced by dup(), makeFile(), operator bool(), and temporary().
|
explicitnoexcept |
|
explicit |
Open and create a file object. Throws on error. Owns the file descriptor implicitly.
Definition at line 40 of file File.cpp.
References fd_, folly::format(), ownsFd_, and folly::throwSystemError().
|
explicit |
|
explicit |
| folly::File::~File | ( | ) |
Definition at line 66 of file File.cpp.
References closeNoThrow(), fd(), and fd_.
Referenced by makeFile().
|
privatedelete |
| void folly::File::close | ( | ) |
If we own the file descriptor, close the file and throw on error. Otherwise, do nothing.
Definition at line 117 of file File.cpp.
References closeNoThrow(), and folly::throwSystemError().
Referenced by closeNoThrow(), folly::gen::detail::FileWriter::compose(), operator bool(), and TEST().
| bool folly::File::closeNoThrow | ( | ) |
Closes the file (if owned). Returns true on success, false (and sets errno) on error.
Definition at line 123 of file File.cpp.
References close(), fd_, ownsFd_, and release().
Referenced by close(), operator bool(), operator=(), and ~File().
|
private |
Definition at line 142 of file File.cpp.
References folly::checkUnixError(), fd_, and folly::flockNoInt().
Referenced by lock(), lock_shared(), and operator bool().
|
private |
Definition at line 146 of file File.cpp.
References folly::checkUnixError(), fd_, and folly::flockNoInt().
Referenced by operator bool(), try_lock(), and try_lock_shared().
| File folly::File::dup | ( | ) | const |
Duplicate file descriptor and return File that owns it.
Definition at line 106 of file File.cpp.
References folly::checkUnixError(), fd(), fd_, and File().
Referenced by operator bool(), and temporary().
|
inline |
Return the file descriptor, or -1 if the file was closed.
Definition at line 85 of file File.h.
References fd_.
Referenced by folly::gen::detail::FileReader::apply(), folly::ShutdownSocketSet::doShutdown(), dup(), folly::MemoryMapping::fd(), File(), folly::MemoryMapping::init(), folly::AsyncFileWriter::onIoError(), folly::AsyncFileWriter::performIO(), folly::test::CaptureFD::readIncremental(), folly::RecordIOWriter::RecordIOWriter(), temporary(), folly::TEST(), TEST(), folly::test::TEST(), folly::ImmediateFileWriter::ttyOutput(), folly::AsyncFileWriter::ttyOutput(), folly::RecordIOWriter::write(), folly::gen::detail::FileWriter::write(), folly::ImmediateFileWriter::writeMessage(), and ~File().
| void folly::File::lock | ( | ) |
| void folly::File::lock_shared | ( | ) |
|
inlinestaticnoexcept |
All the constructors that are not noexcept can throw std::system_error. This is a helper method to use folly::Expected to chain a file open event to something else you want to do with the open fd.
Definition at line 67 of file File.h.
References File(), folly::makeUnexpected(), temporary(), and ~File().
Referenced by TEST().
|
inlineexplicit |
Returns 'true' iff the file was successfully opened.
Definition at line 92 of file File.h.
References close(), closeNoThrow(), doLock(), doTryLock(), dup(), fd_, File(), lock(), lock_shared(), folly::pushmi::__adl::noexcept(), operator=(), release(), swap(), try_lock(), try_lock_shared(), unlock(), and unlock_shared().
Definition at line 60 of file File.cpp.
References closeNoThrow(), and swap().
Referenced by operator bool().
|
noexcept |
Returns and releases the file descriptor; no longer owned by this File. Returns -1 if the File object didn't wrap a file.
Definition at line 89 of file File.cpp.
Referenced by closeNoThrow(), operator bool(), and TEST().
|
noexcept |
Swap this File with another.
Definition at line 96 of file File.cpp.
References fd_, ownsFd_, and folly::swap().
Referenced by operator bool(), and operator=().
|
static |
Create and return a temporary, owned file (uses tmpfile()).
Definition at line 75 of file File.cpp.
References folly::checkFopenError(), folly::checkUnixError(), dup(), fd(), FILE, File(), and SCOPE_EXIT.
Referenced by makeFile(), folly::TEST(), and TEST().
| bool folly::File::try_lock | ( | ) |
Definition at line 132 of file File.cpp.
References doTryLock().
Referenced by main(), and operator bool().
| bool folly::File::try_lock_shared | ( | ) |
Definition at line 138 of file File.cpp.
References doTryLock().
Referenced by main(), and operator bool().
| void folly::File::unlock | ( | ) |
Definition at line 156 of file File.cpp.
References folly::checkUnixError(), fd_, and folly::flockNoInt().
Referenced by operator bool(), and unlock_shared().
| void folly::File::unlock_shared | ( | ) |
|
private |
Definition at line 152 of file File.h.
Referenced by closeNoThrow(), doLock(), doTryLock(), dup(), fd(), File(), operator bool(), release(), swap(), unlock(), and ~File().
|
private |