Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Posix_File.h
Go to the documentation of this file.
1#ifndef joedb_Posix_File_declared
2#define joedb_Posix_File_declared
3
5
6#include <fcntl.h>
7
8#ifndef F_OFD_SETLK
9#define JOEDB_HAS_BROKEN_POSIX_LOCKING
10#endif
11
12namespace joedb
13{
14 ////////////////////////////////////////////////////////////////////////////
15 class Posix_FD: public Buffered_File
16 ////////////////////////////////////////////////////////////////////////////
17 {
18 private:
19 int fd;
20 int lock(int command, short type, int64_t start, int64_t size);
21
22 protected:
23 bool try_exclusive_lock(int64_t start, int64_t size);
24
25 public:
26 static void throw_last_error(const char *action, const char *file_name);
27
28 Posix_FD(int fd, Open_Mode mode):
29 Buffered_File(mode),
30 fd(fd)
31 {
32 }
33
34 Posix_FD(const char *file_name, Open_Mode mode);
35
36 Posix_FD(const Posix_FD &) = delete;
37 Posix_FD &operator=(const Posix_FD &) = delete;
38
39 int64_t get_size() const override;
40 size_t pread(char *buffer, size_t size, int64_t offset) const override;
41 void pwrite(const char *buffer, size_t size, int64_t offset) override;
42
43 void sync() override;
44
45 void shared_lock(int64_t start, int64_t size) override;
46 void exclusive_lock(int64_t start, int64_t size) override;
47 void unlock(int64_t start, int64_t size) noexcept override;
48
49 ~Posix_FD() override;
50 };
51
52 /// @ingroup journal
53 class Posix_File: public Posix_FD
54 {
55 public:
56 inline static constexpr bool lockable = true;
57
58 Posix_File(int fd, Open_Mode mode):
59 Posix_FD(fd, mode)
60 {
61 }
62
63 Posix_File(const char *file_name, Open_Mode mode);
64
65 Posix_File(const std::string &file_name, Open_Mode mode):
67 {
68 }
69 };
70}
71
72#endif
~Posix_FD() override
size_t pread(char *buffer, size_t size, int64_t offset) const override
static void throw_last_error(const char *action, const char *file_name)
void pwrite(const char *buffer, size_t size, int64_t offset) override
Posix_FD & operator=(const Posix_FD &)=delete
bool try_exclusive_lock(int64_t start, int64_t size)
int64_t get_size() const override
void sync() override
void unlock(int64_t start, int64_t size) noexcept override
void shared_lock(int64_t start, int64_t size) override
void exclusive_lock(int64_t start, int64_t size) override
Posix_FD(const Posix_FD &)=delete
Posix_FD(int fd, Open_Mode mode)
Definition Posix_File.h:28
Posix_File(const std::string &file_name, Open_Mode mode)
Definition Posix_File.h:65
static constexpr bool lockable
Definition Posix_File.h:56
Posix_File(int fd, Open_Mode mode)
Definition Posix_File.h:58
Open_Mode
Definition Open_Mode.h:8
Definition Blob.h:7