]>
Commit | Line | Data |
---|---|---|
528b2c61 | 1 | /* |
ef57eb7b | 2 | * Copyright (C) 1996-2016 The Squid Software Foundation and contributors |
528b2c61 | 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. | |
528b2c61 | 7 | */ |
8 | ||
9 | #ifndef SQUID_MEMOBJECT_H | |
10 | #define SQUID_MEMOBJECT_H | |
11 | ||
a46d2c0e | 12 | #include "CommRead.h" |
c6983ec7 | 13 | #include "dlink.h" |
f35c0145 | 14 | #include "http/RequestMethod.h" |
c6983ec7 | 15 | #include "RemovalPolicy.h" |
90ab8f20 | 16 | #include "sbuf/SBuf.h" |
0d1c9fe8 | 17 | #include "SquidString.h" |
c6983ec7 FC |
18 | #include "stmem.h" |
19 | #include "StoreIOBuffer.h" | |
20 | #include "StoreIOState.h" | |
e1ba42a4 | 21 | #include "typedefs.h" //for IRCB |
528b2c61 | 22 | |
43ca19e0 FC |
23 | #if USE_DELAY_POOLS |
24 | #include "DelayId.h" | |
25 | #endif | |
26 | ||
528b2c61 | 27 | typedef void STMCB (void *data, StoreIOBuffer wroteBuffer); |
95beee34 | 28 | typedef void STABH(void *); |
528b2c61 | 29 | |
30 | class store_client; | |
582c2af2 | 31 | class HttpRequest; |
43ca19e0 | 32 | class HttpReply; |
528b2c61 | 33 | |
62e76326 | 34 | class MemObject |
35 | { | |
741c2986 | 36 | MEMPROXY_CLASS(MemObject); |
62e76326 | 37 | |
528b2c61 | 38 | public: |
39 | static size_t inUseCount(); | |
62e76326 | 40 | |
528b2c61 | 41 | void dump() const; |
c877c0bc | 42 | MemObject(); |
528b2c61 | 43 | ~MemObject(); |
44 | ||
c877c0bc AR |
45 | /// sets store ID, log URI, and request method; TODO: find a better name |
46 | void setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod); | |
9487bae9 | 47 | |
c877c0bc AR |
48 | /// whether setUris() has been called |
49 | bool hasUris() const; | |
9487bae9 | 50 | |
55759ffb | 51 | void write(const StoreIOBuffer &buf); |
528b2c61 | 52 | void unlinkRequest(); |
53 | HttpReply const *getReply() const; | |
4a56ee8d | 54 | void replaceHttpReply(HttpReply *newrep); |
fcc35180 | 55 | void stat (MemBuf * mb) const; |
47f6e231 | 56 | int64_t endOffset () const; |
3756e5c0 | 57 | void markEndOfReplyHeaders(); ///< sets _reply->hdr_sz to endOffset() |
aa1a691e AR |
58 | /// negative if unknown; otherwise, expected object_sz, expected endOffset |
59 | /// maximum, and stored reply headers+body size (all three are the same) | |
60 | int64_t expectedReplySize() const; | |
47f6e231 | 61 | int64_t size() const; |
528b2c61 | 62 | void reset(); |
47f6e231 | 63 | int64_t lowestMemReaderOffset() const; |
528b2c61 | 64 | bool readAheadPolicyCanRead() const; |
65 | void addClient(store_client *); | |
62e76326 | 66 | /* XXX belongs in MemObject::swapout, once swaphdrsz is managed |
528b2c61 | 67 | * better |
68 | */ | |
47f6e231 | 69 | int64_t objectBytesOnDisk() const; |
10aeba1d | 70 | int64_t policyLowestOffsetToKeep(bool swap) const; |
5b55f1f1 | 71 | int64_t availableForSwapOut() const; ///< buffered bytes we have not swapped out yet |
528b2c61 | 72 | void trimSwappable(); |
73 | void trimUnSwappable(); | |
74 | bool isContiguous() const; | |
384a7590 | 75 | int mostBytesWanted(int max, bool ignoreDelayPools) const; |
a46d2c0e | 76 | void setNoDelay(bool const newValue); |
9a0a18de | 77 | #if USE_DELAY_POOLS |
b67e2c8c | 78 | DelayId mostBytesAllowed() const; |
79 | #endif | |
528b2c61 | 80 | |
528b2c61 | 81 | #if URL_CHECKSUM_DEBUG |
62e76326 | 82 | |
528b2c61 | 83 | void checkUrlChecksum() const; |
84 | #endif | |
85 | ||
c877c0bc AR |
86 | /// Before StoreID, code assumed that MemObject stores Request URI. |
87 | /// After StoreID, some old code still incorrectly assumes that. | |
88 | /// Use this method to mark that incorrect assumption. | |
89 | const char *urlXXX() const { return storeId(); } | |
90 | ||
91 | /// Entry StoreID (usually just Request URI); if a buggy code requests this | |
92 | /// before the information is available, returns an "[unknown_URI]" string. | |
93 | const char *storeId() const; | |
94 | ||
95 | /// client request URI used for logging; storeId() by default | |
96 | const char *logUri() const; | |
97 | ||
60745f24 | 98 | HttpRequestMethod method; |
528b2c61 | 99 | mem_hdr data_hdr; |
47f6e231 | 100 | int64_t inmem_lo; |
528b2c61 | 101 | dlink_list clients; |
63be0a78 | 102 | |
0e3f3e0d | 103 | size_t clientCount() const {return nclients;} |
104 | ||
105 | bool clientIsFirst(void *sc) const {return (clients.head && sc == clients.head->data);} | |
106 | ||
528b2c61 | 107 | int nclients; |
62e76326 | 108 | |
ecf22804 | 109 | class SwapOut |
62e76326 | 110 | { |
ecf22804 | 111 | public: |
cc8c4af2 AJ |
112 | SwapOut() : queue_offset(0), decision(swNeedsCheck) {} |
113 | ||
aa1a691e | 114 | int64_t queue_offset; ///< number of bytes sent to SwapDir for writing |
62e76326 | 115 | StoreIOState::Pointer sio; |
ddc9b32c AR |
116 | |
117 | /// Decision states for StoreEntry::swapoutPossible() and related code. | |
0e3b2ff0 | 118 | typedef enum { swNeedsCheck = 0, swImpossible = -1, swPossible = +1, swStarted } Decision; |
ddc9b32c | 119 | Decision decision; ///< current decision state |
ecf22804 | 120 | }; |
62e76326 | 121 | |
ecf22804 | 122 | SwapOut swapout; |
63be0a78 | 123 | |
99921d9d AR |
124 | /// cache "I/O" direction and status |
125 | typedef enum { ioUndecided, ioWriting, ioReading, ioDone } Io; | |
126 | ||
4475555f | 127 | /// State of an entry with regards to the [shared] in-transit table. |
9d4e9cfb AR |
128 | class XitTable |
129 | { | |
4475555f | 130 | public: |
99921d9d | 131 | XitTable(): index(-1), io(ioUndecided) {} |
4475555f AR |
132 | |
133 | int32_t index; ///< entry position inside the in-transit table | |
99921d9d | 134 | Io io; ///< current I/O state |
4475555f AR |
135 | }; |
136 | XitTable xitTable; ///< current [shared] memory caching state for the entry | |
137 | ||
138 | /// State of an entry with regards to the [shared] memory caching. | |
9d4e9cfb AR |
139 | class MemCache |
140 | { | |
4475555f AR |
141 | public: |
142 | MemCache(): index(-1), offset(0), io(ioUndecided) {} | |
143 | ||
144 | int32_t index; ///< entry position inside the memory cache | |
145 | int64_t offset; ///< bytes written/read to/from the memory cache so far | |
9d4e9cfb | 146 | |
4475555f AR |
147 | Io io; ///< current I/O state |
148 | }; | |
149 | MemCache memCache; ///< current [shared] memory caching state for the entry | |
150 | ||
151 | bool smpCollapsed; ///< whether this entry gets data from another worker | |
152 | ||
528b2c61 | 153 | /* Read only - this reply must be preserved by store clients */ |
154 | /* The original reply. possibly with updated metadata. */ | |
190154cf | 155 | HttpRequest *request; |
62e76326 | 156 | |
528b2c61 | 157 | struct timeval start_ping; |
158 | IRCB *ping_reply_callback; | |
159 | void *ircb_data; | |
62e76326 | 160 | |
26ac0430 | 161 | struct { |
528b2c61 | 162 | STABH *callback; |
163 | void *data; | |
2fadd50d | 164 | } abort; |
528b2c61 | 165 | RemovalPolicyNode repl; |
166 | int id; | |
47f6e231 | 167 | int64_t object_sz; |
528b2c61 | 168 | size_t swap_hdr_sz; |
169 | #if URL_CHECKSUM_DEBUG | |
62e76326 | 170 | |
528b2c61 | 171 | unsigned int chksum; |
172 | #endif | |
62e76326 | 173 | |
90ab8f20 | 174 | SBuf vary_headers; |
62e76326 | 175 | |
a46d2c0e | 176 | void delayRead(DeferredRead const &); |
177 | void kickReads(); | |
178 | ||
528b2c61 | 179 | private: |
4a56ee8d | 180 | HttpReply *_reply; |
4a56ee8d | 181 | |
c877c0bc AR |
182 | mutable String storeId_; ///< StoreId for our entry (usually request URI) |
183 | mutable String logUri_; ///< URI used for logging (usually request URI) | |
184 | ||
a46d2c0e | 185 | DeferredReadManager deferredReads; |
528b2c61 | 186 | }; |
187 | ||
63be0a78 | 188 | /** global current memory removal policy */ |
aa839030 | 189 | extern RemovalPolicy *mem_policy; |
190 | ||
528b2c61 | 191 | #endif /* SQUID_MEMOBJECT_H */ |
f53969cc | 192 |