]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/rock/RockIoState.h
merge from trunk
[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 /// forwards read data to the reader that initiated this I/O
35 void callReaderBack(const char *buf, int rlen);
36
37 /// called by SwapDir::writeCompleted() after the last write and on error
38 void finishedWriting(const int errFlag);
39
40 MEMPROXY_CLASS(IoState);
41
42 /* one and only one of these will be set and locked; access via *Anchor() */
43 const Ipc::StoreMapAnchor *readableAnchor_; ///< starting point for reading
44 Ipc::StoreMapAnchor *writeableAnchor_; ///< starting point for writing
45
46 SlotId sidCurrent; ///< ID of the db slot currently being read or written
47
48 private:
49 const Ipc::StoreMapAnchor &readAnchor() const;
50 Ipc::StoreMapAnchor &writeAnchor();
51 const Ipc::StoreMapSlice &currentReadableSlice() const;
52
53 void tryWrite(char const *buf, size_t size, off_t offset);
54 size_t writeToBuffer(char const *buf, size_t size);
55 void writeToDisk(const SlotId nextSlot);
56 void writeBufToDisk(const SlotId nextSlot, const bool eof);
57 SlotId reserveSlotForWriting();
58
59 void callBack(int errflag);
60
61 Rock::SwapDir::Pointer dir; ///< swap dir that initiated I/O
62 const size_t slotSize; ///< db cell size
63 int64_t objOffset; ///< object offset for current db slot
64
65 RefCount<DiskFile> theFile; // "file" responsible for this I/O
66 MemBlob theBuf; // use for write content accumulation only
67 };
68
69 MEMPROXY_CLASS_INLINE(IoState);
70
71 } // namespace Rock
72
73 #endif /* SQUID_FS_ROCK_IO_STATE_H */