|
Squid Web Cache v8/master
|
a portable locking-aware exception-friendly file (with RAII API) More...
#include <File.h>
Public Types | |
| typedef FileOpeningConfig | Be |
| convenient shorthand for File() callers | |
Public Member Functions | |
| File (const SBuf &aFilename, const FileOpeningConfig &cfg) | |
| opens | |
| ~File () | |
| closes | |
| File (const File &)=delete | |
| File & | operator= (const File &)=delete |
| File (File &&other) | |
| File & | operator= (File &&other) |
| const SBuf & | name () const |
| void | truncate () |
| makes the file size (and the current I/O offset) zero | |
| SBuf | readSmall (SBuf::size_type minBytes, SBuf::size_type maxBytes) |
| read(2) for small files | |
| void | writeAll (const SBuf &data) |
| write(2) with a "wrote everything" check | |
| void | synchronize () |
| fsync(2) | |
Static Public Member Functions | |
| static File * | Optional (const SBuf &aName, const FileOpeningConfig &cfg) |
Protected Member Functions | |
| bool | isOpen () const |
| void | open (const FileOpeningConfig &cfg) |
| opens (or creates) the file | |
| void | lock (const FileOpeningConfig &cfg) |
| calls lockOnce() as many times as necessary (including zero) | |
| void | lockOnce (const FileOpeningConfig &cfg) |
| locks, blocking or returning immediately depending on the lock waiting mode | |
| void | close () |
| SBuf | sysCallFailure (const char *callName, const SBuf &error) const |
| SBuf | sysCallError (const char *callName, const int savedErrno) const |
Private Types | |
| typedef int | Handle |
Private Attributes | |
| SBuf | name_ |
| location on disk | |
| Handle | fd_ = InvalidHandle |
| OS-specific file handle. | |
Static Private Attributes | |
| static const Handle | InvalidHandle = -1 |
| typedef FileOpeningConfig File::Be |
|
private |
| File::File | ( | const SBuf & | aFilename, |
| const FileOpeningConfig & | cfg | ||
| ) |
|
delete |
|
protected |
Definition at line 195 of file File.cc.
References DBG_IMPORTANT, debugs, fd_, isOpen(), sysCallError(), sysCallFailure(), and xclose().
|
inlineprotected |
|
protected |
Definition at line 320 of file File.cc.
References debugs, FileOpeningConfig::lockAttempts, lockOnce(), Must, and FileOpeningConfig::retryGapUsec.
Referenced by File().
|
protected |
Definition at line 341 of file File.cc.
References debugs, fd_, FileOpeningConfig::flockMode, name_, sysCallError(), sysCallFailure(), and TexcHere.
Referenced by lock().
|
protected |
Definition at line 170 of file File.cc.
References SBuf::c_str(), FileOpeningConfig::creationMask, enter_suid(), fd_, InvalidHandle, leave_suid(), name_, FileOpeningConfig::openFlags, FileOpeningConfig::openMode, sysCallError(), sysCallFailure(), TexcHere, and xopen().
Referenced by File().
|
static |
| SBuf File::readSmall | ( | SBuf::size_type | minBytes, |
| SBuf::size_type | maxBytes | ||
| ) |
Definition at line 240 of file File.cc.
References assert, fd_, SBuf::length(), Must, SBuf::rawAppendFinish(), SBuf::rawAppendStart(), sysCallError(), sysCallFailure(), TexcHere, and xread().
Referenced by GetOtherPid().
| void File::synchronize | ( | ) |
Definition at line 303 of file File.cc.
References fd_, sysCallError(), sysCallFailure(), and TexcHere.
Referenced by Instance::WriteOurPid().
Definition at line 371 of file File.cc.
References sysCallFailure(), and xstrerr().
Referenced by close(), lockOnce(), open(), readSmall(), synchronize(), truncate(), and writeAll().
Definition at line 364 of file File.cc.
References error(), name_, and ToSBuf().
Referenced by close(), lockOnce(), open(), readSmall(), synchronize(), sysCallError(), truncate(), and writeAll().
| void File::truncate | ( | ) |
Definition at line 214 of file File.cc.
References fd_, sysCallError(), sysCallFailure(), and TexcHere.
Referenced by Instance::WriteOurPid().
| void File::writeAll | ( | const SBuf & | data | ) |
Definition at line 279 of file File.cc.
References fd_, SBuf::length(), SBuf::rawContent(), sysCallError(), sysCallFailure(), TexcHere, and xwrite().
Referenced by Instance::WriteOurPid().
|
private |
Definition at line 123 of file File.h.
Referenced by close(), isOpen(), lockOnce(), open(), operator=(), readSmall(), synchronize(), truncate(), and writeAll().
|
staticprivate |
|
private |
Definition at line 113 of file File.h.
Referenced by File(), ~File(), lockOnce(), name(), open(), and sysCallFailure().