]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/rock/RockIoState.h
Merged from trunk (r12732, v3.3.3+).
[thirdparty/squid.git] / src / fs / rock / RockIoState.h
1 #ifndef SQUID_FS_ROCK_IO_STATE_H
2 #define SQUID_FS_ROCK_IO_STATE_H
3
4 #include "fs/rock/RockSwapDir.h"
5 #include "MemBlob.h"
6
7 class DiskFile;
8
9 namespace Rock
10 {
11
12 class DbCellHeader;
13 class SwapDir;
14
15 /// \ingroup Rock
16 class IoState: public ::StoreIOState
17 {
18 public:
19 typedef RefCount<IoState> Pointer;
20
21 IoState(Rock::SwapDir::Pointer &aDir, StoreEntry *e, StoreIOState::STFNCB *cbFile, StoreIOState::STIOCB *cbIo, void *data);
22 virtual ~IoState();
23
24 void file(const RefCount<DiskFile> &aFile);
25
26 // ::StoreIOState API
27 virtual void read_(char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data);
28 virtual bool write(char const *buf, size_t size, off_t offset, FREE * free_func);
29 virtual void close(int how);
30
31 /// whether we are still waiting for the I/O results (i.e., not closed)
32 bool stillWaiting() const { return theFile != NULL; }
33
34 /// called by SwapDir::writeCompleted() after the last write and on error
35 void finishedWriting(const int errFlag);
36
37 MEMPROXY_CLASS(IoState);
38
39 /* one and only one of these will be set and locked; access via *Anchor() */
40 const Ipc::StoreMapAnchor *readableAnchor_; ///< starting point for reading
41 Ipc::StoreMapAnchor *writeableAnchor_; ///< starting point for writing
42
43 SlotId sidCurrent; ///< ID of the db slot currently being read or written
44
45 private:
46 const Ipc::StoreMapAnchor &readAnchor() const;
47 Ipc::StoreMapAnchor &writeAnchor();
48 const Ipc::StoreMapSlice &currentReadableSlice() const;
49
50 void tryWrite(char const *buf, size_t size, off_t offset);
51 size_t writeToBuffer(char const *buf, size_t size);
52 void writeToDisk(const SlotId nextSlot);
53 SlotId reserveSlotForWriting();
54
55 void callBack(int errflag);
56
57 Rock::SwapDir::Pointer dir; ///< swap dir that initiated I/O
58 const size_t slotSize; ///< db cell size
59 int64_t objOffset; ///< object offset for current db slot
60
61 RefCount<DiskFile> theFile; // "file" responsible for this I/O
62 MemBlob theBuf; // use for write content accumulation only
63 };
64
65 MEMPROXY_CLASS_INLINE(IoState);
66
67 } // namespace Rock
68
69 #endif /* SQUID_FS_ROCK_IO_STATE_H */