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