]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
5b74111a | 2 | * Copyright (C) 1996-2018 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 | ||
50dc81ec | 12 | #include "fs/rock/RockSwapDir.h" |
65e41a45 | 13 | #include "sbuf/MemBlob.h" |
e2851fe7 AR |
14 | |
15 | class DiskFile; | |
16 | ||
9199139f AR |
17 | namespace Rock |
18 | { | |
e2851fe7 | 19 | |
93910d5c | 20 | class DbCellHeader; |
e2851fe7 AR |
21 | class SwapDir; |
22 | ||
23 | /// \ingroup Rock | |
24 | class IoState: public ::StoreIOState | |
25 | { | |
741c2986 AJ |
26 | MEMPROXY_CLASS(IoState); |
27 | ||
e2851fe7 AR |
28 | public: |
29 | typedef RefCount<IoState> Pointer; | |
30 | ||
50dc81ec | 31 | IoState(Rock::SwapDir::Pointer &aDir, StoreEntry *e, StoreIOState::STFNCB *cbFile, StoreIOState::STIOCB *cbIo, void *data); |
e2851fe7 AR |
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); | |
50dc81ec | 38 | virtual bool write(char const *buf, size_t size, off_t offset, FREE * free_func); |
c728b6f9 | 39 | virtual void close(int how); |
e2851fe7 | 40 | |
50dc81ec AR |
41 | /// whether we are still waiting for the I/O results (i.e., not closed) |
42 | bool stillWaiting() const { return theFile != NULL; } | |
e2851fe7 | 43 | |
5296bbd9 AR |
44 | /// forwards read data to the reader that initiated this I/O |
45 | void callReaderBack(const char *buf, int rlen); | |
46 | ||
50dc81ec AR |
47 | /// called by SwapDir::writeCompleted() after the last write and on error |
48 | void finishedWriting(const int errFlag); | |
e2851fe7 | 49 | |
50dc81ec AR |
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 | ||
abf396ec AR |
54 | /// the last db slot successfully read or written |
55 | SlotId splicingPoint; | |
56 | /// when reading, this is the next slot we are going to read (if asked) | |
57 | /// when writing, this is the next slot to use after the last fresh slot | |
58 | SlotId staleSplicingPointNext; | |
50dc81ec | 59 | |
e2851fe7 | 60 | private: |
50dc81ec AR |
61 | const Ipc::StoreMapAnchor &readAnchor() const; |
62 | Ipc::StoreMapAnchor &writeAnchor(); | |
63 | const Ipc::StoreMapSlice ¤tReadableSlice() const; | |
64 | ||
65 | void tryWrite(char const *buf, size_t size, off_t offset); | |
66 | size_t writeToBuffer(char const *buf, size_t size); | |
67 | void writeToDisk(const SlotId nextSlot); | |
abf396ec | 68 | void writeBufToDisk(const SlotId nextSlot, const bool eof, const bool lastWrite); |
50dc81ec | 69 | SlotId reserveSlotForWriting(); |
9d4e9cfb | 70 | |
e2851fe7 AR |
71 | void callBack(int errflag); |
72 | ||
50dc81ec | 73 | Rock::SwapDir::Pointer dir; ///< swap dir that initiated I/O |
93910d5c AR |
74 | const size_t slotSize; ///< db cell size |
75 | int64_t objOffset; ///< object offset for current db slot | |
abf396ec | 76 | SlotId sidCurrent; ///< ID of the db slot currently being read or written |
93910d5c | 77 | |
e2851fe7 | 78 | RefCount<DiskFile> theFile; // "file" responsible for this I/O |
50dc81ec | 79 | MemBlob theBuf; // use for write content accumulation only |
e2851fe7 AR |
80 | }; |
81 | ||
e2851fe7 AR |
82 | } // namespace Rock |
83 | ||
84 | #endif /* SQUID_FS_ROCK_IO_STATE_H */ | |
f53969cc | 85 |