]> git.ipfire.org Git - thirdparty/squid.git/blob - src/DiskIO/Mmapped/MmappedFile.h
Maintenance: Consistent use of C++11 "override" specifier (#1224)
[thirdparty/squid.git] / src / DiskIO / Mmapped / MmappedFile.h
1 /*
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_MMAPPEDFILE_H
10 #define SQUID_MMAPPEDFILE_H
11
12 #include "cbdata.h"
13 #include "DiskIO/DiskFile.h"
14 #include "DiskIO/IORequestor.h"
15
16 class MmappedFile : public DiskFile
17 {
18 CBDATA_CLASS(MmappedFile);
19
20 public:
21 MmappedFile(char const *path);
22 ~MmappedFile() override;
23 void open(int flags, mode_t mode, RefCount<IORequestor> callback) override;
24 void create(int flags, mode_t mode, RefCount<IORequestor> callback) override;
25 void read(ReadRequest *) override;
26 void write(WriteRequest *) override;
27 void close() override;
28 bool error() const override;
29 int getFD() const override { return fd;}
30
31 bool canRead() const override;
32 bool canWrite() const override;
33 bool ioInProgress() const override;
34
35 private:
36 char const *path_;
37 RefCount<IORequestor> ioRequestor;
38 //RefCount<ReadRequest> readRequest;
39 //RefCount<WriteRequest> writeRequest;
40 int fd;
41
42 // mmapped memory leads to SEGV and bus errors if it maps beyond file
43 int64_t minOffset; ///< enforced if not negative (to preserve file headers)
44 int64_t maxOffset; ///< enforced if not negative (to avoid crashes)
45
46 bool error_;
47
48 void doClose();
49 };
50
51 #endif /* SQUID_MMAPPEDFILE_H */
52