throw TexcHere(sysCallError("fsync", savedErrno));
}
#endif
-}
+ }
/// calls lockOnce() as many times as necessary (including zero)
-void
-File::lock(const FileOpeningConfig &cfg)
-{
- unsigned int attemptsLeft = cfg.lockAttempts;
- while (attemptsLeft) {
- try {
- --attemptsLeft;
- return lockOnce(cfg);
- } catch (const std::exception &ex) {
- if (!attemptsLeft)
- throw;
- debugs(54, 4, "sleeping and then trying up to " << attemptsLeft <<
- " more time(s) after a failure: " << ex.what());
+ void
+ File::lock(const FileOpeningConfig &cfg)
+ {
+ unsigned int attemptsLeft = cfg.lockAttempts;
+ while (attemptsLeft) {
+ try {
+ --attemptsLeft;
+ return lockOnce(cfg);
+ } catch (const std::exception &ex) {
+ if (!attemptsLeft)
+ throw;
+ debugs(54, 4, "sleeping and then trying up to " << attemptsLeft <<
+ " more time(s) after a failure: " << ex.what());
+ }
+ Must(attemptsLeft); // the catch statement handles the last attempt
+ xusleep(cfg.RetryGapUsec);
}
- Must(attemptsLeft); // the catch statement handles the last attempt
- xusleep(cfg.RetryGapUsec);
+ debugs(54, 9, "disabled");
}
- debugs(54, 9, "disabled");
-}
/// locks, blocking or returning immediately depending on the lock waiting mode
-void
-File::lockOnce(const FileOpeningConfig &cfg)
-{
+ void
+ File::lockOnce(const FileOpeningConfig &cfg)
+ {
#if _SQUID_WINDOWS_
- if (!LockFileEx(fd_, cfg.lockFlags, 0, 0, 1, 0)) {
- const auto savedError = GetLastError();
- throw TexcHere(sysCallFailure("LockFileEx", WindowsErrorMessage(savedError).c_str()));
- }
+ if (!LockFileEx(fd_, cfg.lockFlags, 0, 0, 1, 0)) {
+ const auto savedError = GetLastError();
+ throw TexcHere(sysCallFailure("LockFileEx", WindowsErrorMessage(savedError).c_str()));
+ }
#elif _SQUID_SOLARIS_
- if (fcntlLock(fd_, cfg.lockType) != 0) {
- const auto savedErrno = errno;
- throw TexcHere(sysCallError("fcntl(flock)", savedErrno));
- }
+ if (fcntlLock(fd_, cfg.lockType) != 0) {
+ const auto savedErrno = errno;
+ throw TexcHere(sysCallError("fcntl(flock)", savedErrno));
+ }
#else
- if (::flock(fd_, cfg.flockMode) != 0) {
- const auto savedErrno = errno;
- throw TexcHere(sysCallError("flock", savedErrno));
- }
+ if (::flock(fd_, cfg.flockMode) != 0) {
+ const auto savedErrno = errno;
+ throw TexcHere(sysCallError("flock", savedErrno));
+ }
#endif
- debugs(54, 3, "succeeded for " << name_);
-}
+ debugs(54, 3, "succeeded for " << name_);
+ }
-bool
-File::isOpen() const
-{
+ bool
+ File::isOpen() const
+ {
#if _SQUID_WINDOWS_
- return fd_ != InvalidHandle;
+ return fd_ != InvalidHandle;
#else
- return fd_ >= 0;
+ return fd_ >= 0;
#endif
-}
+ }
/// \returns a description a system call-related failure
-SBuf
-File::sysCallFailure(const char *callName, const char *error) const
-{
- return ToSBuf("failed to ", callName, ' ', name_, ": ", error);
-}
+ SBuf
+ File::sysCallFailure(const char *callName, const char *error) const
+ {
+ return ToSBuf("failed to ", callName, ' ', name_, ": ", error);
+ }
/// \returns a description of an errno-based system call failure
-SBuf
-File::sysCallError(const char *callName, const int savedErrno) const
-{
- return sysCallFailure(callName, xstrerr(savedErrno));
-}
+ SBuf
+ File::sysCallError(const char *callName, const int savedErrno) const
+ {
+ return sysCallFailure(callName, xstrerr(savedErrno));
+ }