]>
Commit | Line | Data |
---|---|---|
d3b3ab85 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
d3b3ab85 | 3 | * |
bbc27441 AJ |
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. | |
d3b3ab85 | 7 | */ |
8 | ||
ff9d9458 FC |
9 | #ifndef SQUID_SRC_STOREIOSTATE_H |
10 | #define SQUID_SRC_STOREIOSTATE_H | |
d3b3ab85 | 11 | |
8bf217bd | 12 | #include "base/RefCount.h" |
aa839030 | 13 | #include "cbdata.h" |
effdd841 | 14 | #include "mem/forward.h" |
2745fea5 | 15 | #include "store/forward.h" |
62e76326 | 16 | |
e877aaac | 17 | class StoreIOState : public RefCountable |
62e76326 | 18 | { |
19 | ||
d3b3ab85 | 20 | public: |
e877aaac | 21 | typedef RefCount<StoreIOState> Pointer; |
d3b3ab85 | 22 | |
4fcc8876 | 23 | /* |
24 | * STRCB is the "store read callback". STRCB functions are | |
25 | * passed to storeRead(). Examples of STRCB callbacks are: | |
26 | * storeClientReadBody | |
27 | * storeClientReadHeader | |
28 | */ | |
e5de8b13 | 29 | typedef void STRCB(void *their_data, const char *buf, ssize_t len, StoreIOState::Pointer self); |
4fcc8876 | 30 | |
4fcc8876 | 31 | /* |
32 | * STIOCB is the "store close callback" for store files. It | |
33 | * is called when the store file is closed. STIOCB functions | |
34 | * are passed to storeCreate() and storeOpen(). Examples of | |
35 | * STIOCB callbacks are: | |
36 | * storeSwapOutFileClosed | |
37 | * storeSwapInFileClosed | |
38 | */ | |
e5de8b13 | 39 | typedef void STIOCB(void *their_data, int errflag, StoreIOState::Pointer self); |
4fcc8876 | 40 | |
e877aaac | 41 | /* StoreIOState does not get mempooled - it's children do */ |
d3b3ab85 | 42 | void *operator new (size_t amount); |
43 | void operator delete (void *address); | |
d3b3ab85 | 44 | |
be42c788 | 45 | StoreIOState(StoreIOState::STIOCB *, void *cbData); |
337b9aa4 | 46 | ~StoreIOState() override; |
d3b3ab85 | 47 | |
cc8c4af2 | 48 | off_t offset() const {return offset_;} |
d3b3ab85 | 49 | |
50 | virtual void read_(char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data) = 0; | |
90e8b325 AR |
51 | /** write the given buffer and free it when it is no longer needed |
52 | * \param offset zero for the very first write and -1 for all other writes | |
53 | * \retval false if write failed (callback has been or will be called) | |
54 | */ | |
55 | virtual bool write(char const *buf, size_t size, off_t offset, FREE * free_func) = 0; | |
aa1a691e AR |
56 | |
57 | typedef enum { | |
9199139f AR |
58 | wroteAll, ///< success: caller supplied all data it wanted to swap out |
59 | writerGone, ///< failure: caller left before swapping out everything | |
60 | readerDone ///< success or failure: either way, stop swapping in | |
aa1a691e AR |
61 | } CloseHow; |
62 | virtual void close(int how) = 0; ///< finish or abort swapping per CloseHow | |
62e76326 | 63 | |
abf396ec AR |
64 | // Tests whether we are working with the primary/public StoreEntry chain. |
65 | // Reads start reading the primary chain, but it may become secondary. | |
66 | // There are two store write kinds: | |
67 | // * regular writes that change (usually append) the entry visible to all and | |
68 | // * header updates that create a fresh chain (while keeping the stale one usable). | |
69 | bool touchingStoreEntry() const; | |
70 | ||
d3b3ab85 | 71 | sdirno swap_dirn; |
72 | sfileno swap_filen; | |
f53969cc | 73 | StoreEntry *e; /* Need this so the FS layers can play god */ |
d3b3ab85 | 74 | mode_t mode; |
aa1a691e | 75 | off_t offset_; ///< number of bytes written or read for this entry so far |
d3b3ab85 | 76 | STIOCB *callback; |
77 | void *callback_data; | |
62e76326 | 78 | |
26ac0430 | 79 | struct { |
62e76326 | 80 | STRCB *callback; |
81 | void *callback_data; | |
2fadd50d | 82 | } read; |
62e76326 | 83 | |
26ac0430 | 84 | struct { |
f53969cc | 85 | bool closing; /* debugging aid */ |
2fadd50d | 86 | } flags; |
d3b3ab85 | 87 | }; |
88 | ||
be42c788 AR |
89 | StoreIOState::Pointer storeCreate(StoreEntry *, StoreIOState::STIOCB *, void *); |
90 | StoreIOState::Pointer storeOpen(StoreEntry *, StoreIOState::STIOCB *, void *); | |
d9c252f2 FC |
91 | void storeClose(StoreIOState::Pointer, int how); |
92 | void storeRead(StoreIOState::Pointer, char *, size_t, off_t, StoreIOState::STRCB *, void *); | |
93 | void storeIOWrite(StoreIOState::Pointer, char const *, size_t, off_t, FREE *); | |
d3b3ab85 | 94 | |
ff9d9458 | 95 | #endif /* SQUID_SRC_STOREIOSTATE_H */ |
f53969cc | 96 |