]> git.ipfire.org Git - thirdparty/squid.git/blame - src/fs/rock/RockIoState.h
Maintenance: Removed most NULLs using modernize-use-nullptr (#1075)
[thirdparty/squid.git] / src / fs / rock / RockIoState.h
CommitLineData
bbc27441 1/*
bf95c10a 2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
bbc27441
AJ
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
e2851fe7
AR
9#ifndef SQUID_FS_ROCK_IO_STATE_H
10#define SQUID_FS_ROCK_IO_STATE_H
11
18102f7d 12#include "fs/rock/forward.h"
50dc81ec 13#include "fs/rock/RockSwapDir.h"
65e41a45 14#include "sbuf/MemBlob.h"
e2851fe7
AR
15
16class DiskFile;
17
9199139f
AR
18namespace Rock
19{
e2851fe7 20
93910d5c 21class DbCellHeader;
e2851fe7
AR
22class SwapDir;
23
24/// \ingroup Rock
25class IoState: public ::StoreIOState
26{
741c2986
AJ
27 MEMPROXY_CLASS(IoState);
28
e2851fe7
AR
29public:
30 typedef RefCount<IoState> Pointer;
31
50dc81ec 32 IoState(Rock::SwapDir::Pointer &aDir, StoreEntry *e, StoreIOState::STFNCB *cbFile, StoreIOState::STIOCB *cbIo, void *data);
e2851fe7
AR
33 virtual ~IoState();
34
35 void file(const RefCount<DiskFile> &aFile);
36
37 // ::StoreIOState API
38 virtual void read_(char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data);
50dc81ec 39 virtual bool write(char const *buf, size_t size, off_t offset, FREE * free_func);
c728b6f9 40 virtual void close(int how);
e2851fe7 41
50dc81ec 42 /// whether we are still waiting for the I/O results (i.e., not closed)
aee3523a 43 bool stillWaiting() const { return theFile != nullptr; }
e2851fe7 44
18102f7d
EB
45 /// forwards read data (or an error) to the reader that initiated this I/O
46 void handleReadCompletion(Rock::ReadRequest &request, const int rlen, const int errFlag);
5296bbd9 47
50dc81ec
AR
48 /// called by SwapDir::writeCompleted() after the last write and on error
49 void finishedWriting(const int errFlag);
e2851fe7 50
18102f7d
EB
51 /// notes that the disker has satisfied the given I/O request
52 /// \returns whether all earlier I/O requests have been satisfied already
53 bool expectedReply(const IoXactionId receivedId);
54
50dc81ec
AR
55 /* one and only one of these will be set and locked; access via *Anchor() */
56 const Ipc::StoreMapAnchor *readableAnchor_; ///< starting point for reading
57 Ipc::StoreMapAnchor *writeableAnchor_; ///< starting point for writing
58
abf396ec
AR
59 /// the last db slot successfully read or written
60 SlotId splicingPoint;
61 /// when reading, this is the next slot we are going to read (if asked)
62 /// when writing, this is the next slot to use after the last fresh slot
63 SlotId staleSplicingPointNext;
50dc81ec 64
e2851fe7 65private:
50dc81ec
AR
66 const Ipc::StoreMapAnchor &readAnchor() const;
67 Ipc::StoreMapAnchor &writeAnchor();
68 const Ipc::StoreMapSlice &currentReadableSlice() const;
69
70 void tryWrite(char const *buf, size_t size, off_t offset);
71 size_t writeToBuffer(char const *buf, size_t size);
18102f7d 72 void writeToDisk();
9d4e9cfb 73
18102f7d 74 void callReaderBack(const char *buf, int rlen);
e2851fe7
AR
75 void callBack(int errflag);
76
50dc81ec 77 Rock::SwapDir::Pointer dir; ///< swap dir that initiated I/O
93910d5c
AR
78 const size_t slotSize; ///< db cell size
79 int64_t objOffset; ///< object offset for current db slot
18102f7d
EB
80
81 /// The very first entry slot. Usually the same as anchor.first,
82 /// but writers set anchor.first only after the first write is done.
83 SlotId sidFirst;
84
85 /// Unused by readers.
86 /// For writers, the slot pointing (via .next) to sidCurrent.
87 SlotId sidPrevious;
88
89 /// For readers, the db slot currently being read from disk.
90 /// For writers, the reserved db slot currently being filled (to be written).
91 SlotId sidCurrent;
92
93 /// Unused by readers.
94 /// For writers, the reserved db slot that sidCurrent.next will point to.
95 SlotId sidNext;
96
97 /// the number of read or write requests we sent to theFile
98 uint64_t requestsSent;
99
100 /// the number of successful responses we received from theFile
101 uint64_t repliesReceived;
93910d5c 102
e2851fe7 103 RefCount<DiskFile> theFile; // "file" responsible for this I/O
50dc81ec 104 MemBlob theBuf; // use for write content accumulation only
e2851fe7
AR
105};
106
e2851fe7
AR
107} // namespace Rock
108
109#endif /* SQUID_FS_ROCK_IO_STATE_H */
f53969cc 110