1#ifndef joedb_Posix_File_declared
2#define joedb_Posix_File_declared
11#define JOEDB_HAS_BROKEN_POSIX_LOCKING
39 std::string file_name;
40 bool created_durably =
false;
42 int lock(
int command,
short type, int64_t start, int64_t size);
43 bool try_exclusive_lock(int64_t start, int64_t size);
44 void throw_last_error(
const char *action)
const;
48#ifdef JOEDB_HAS_BROKEN_POSIX_LOCKING
68 size_t pread(
char *buffer,
size_t size, int64_t offset)
const override;
69 void pwrite(
const char *buffer,
size_t size, int64_t offset)
override;
72#if _POSIX_SYNCHRONIZED_IO > 0
76 void shared_lock(int64_t start, int64_t size)
override;
78 void unlock(int64_t start, int64_t size)
noexcept override;
Abstract_File(Open_Mode mode)
virtual void datasync()
Write data durably (no file-size change).
Posix_FD & operator=(const Posix_FD &)=delete
Posix_FD(const Posix_FD &)=delete
Posix_File(const std::string &file_name, Open_Mode mode)
size_t pread(char *buffer, size_t size, int64_t offset) const override
Read a range of bytes.
void unlock(int64_t start, int64_t size) noexcept override
Remove a lock. The range should match the range of a corresponding lock.
void pwrite(const char *buffer, size_t size, int64_t offset) override
Write a range of bytes. Extend file size if necessary.
void exclusive_lock(int64_t start, int64_t size) override
Lock a range of bytes for writing (prevents both writes and reads).
void shared_lock(int64_t start, int64_t size) override
Lock a range of bytes for reading (prevents writes, not reads).
void sync() override
Write data durably (including file-size change).
static constexpr bool lockable
Posix_File(int fd, Open_Mode mode)
int64_t get_size() const override
Get the size of the file, or -1 if it is unknown.
static constexpr bool has_broken_posix_locking