]> git.ipfire.org Git - thirdparty/squid.git/blame - src/MemObject.h
Prep for 3.3.12 and 3.4.4
[thirdparty/squid.git] / src / MemObject.h
CommitLineData
528b2c61 1/*
528b2c61 2 *
3 * SQUID Web Proxy Cache http://www.squid-cache.org/
4 * ----------------------------------------------------------
5 *
6 * Squid is the result of efforts by numerous individuals from
7 * the Internet community; see the CONTRIBUTORS file for full
8 * details. Many organizations have provided support for Squid's
9 * development; see the SPONSORS file for full details. Squid is
10 * Copyrighted (C) 2001 by the Regents of the University of
11 * California; see the COPYRIGHT file for full details. Squid
12 * incorporates software developed and/or copyrighted by other
13 * sources; see the CREDITS file for full details.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
26ac0430 19 *
528b2c61 20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
26ac0430 24 *
528b2c61 25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
28 *
29 */
30
31#ifndef SQUID_MEMOBJECT_H
32#define SQUID_MEMOBJECT_H
33
a46d2c0e 34#include "CommRead.h"
c6983ec7 35#include "dlink.h"
75cb38cb 36#include "HttpRequestMethod.h"
c6983ec7
FC
37#include "RemovalPolicy.h"
38#include "stmem.h"
39#include "StoreIOBuffer.h"
40#include "StoreIOState.h"
528b2c61 41
43ca19e0
FC
42#if USE_DELAY_POOLS
43#include "DelayId.h"
44#endif
45
528b2c61 46typedef void STMCB (void *data, StoreIOBuffer wroteBuffer);
47
48class store_client;
582c2af2 49class HttpRequest;
43ca19e0 50class HttpReply;
528b2c61 51
62e76326 52class MemObject
53{
54
528b2c61 55public:
56 static size_t inUseCount();
b001e822 57 MEMPROXY_CLASS(MemObject);
62e76326 58
528b2c61 59 void dump() const;
c877c0bc 60 MemObject();
528b2c61 61 ~MemObject();
62
c877c0bc
AR
63 /// sets store ID, log URI, and request method; TODO: find a better name
64 void setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod);
65
66 /// whether setUris() has been called
67 bool hasUris() const;
9487bae9 68
55759ffb 69 void write(const StoreIOBuffer &buf);
528b2c61 70 void unlinkRequest();
71 HttpReply const *getReply() const;
4a56ee8d 72 void replaceHttpReply(HttpReply *newrep);
fcc35180 73 void stat (MemBuf * mb) const;
47f6e231 74 int64_t endOffset () const;
3756e5c0 75 void markEndOfReplyHeaders(); ///< sets _reply->hdr_sz to endOffset()
aa1a691e
AR
76 /// negative if unknown; otherwise, expected object_sz, expected endOffset
77 /// maximum, and stored reply headers+body size (all three are the same)
78 int64_t expectedReplySize() const;
47f6e231 79 int64_t size() const;
528b2c61 80 void reset();
47f6e231 81 int64_t lowestMemReaderOffset() const;
528b2c61 82 bool readAheadPolicyCanRead() const;
83 void addClient(store_client *);
62e76326 84 /* XXX belongs in MemObject::swapout, once swaphdrsz is managed
528b2c61 85 * better
86 */
47f6e231 87 int64_t objectBytesOnDisk() const;
10aeba1d 88 int64_t policyLowestOffsetToKeep(bool swap) const;
5b55f1f1 89 int64_t availableForSwapOut() const; ///< buffered bytes we have not swapped out yet
528b2c61 90 void trimSwappable();
91 void trimUnSwappable();
92 bool isContiguous() const;
384a7590 93 int mostBytesWanted(int max, bool ignoreDelayPools) const;
a46d2c0e 94 void setNoDelay(bool const newValue);
9a0a18de 95#if USE_DELAY_POOLS
b67e2c8c 96 DelayId mostBytesAllowed() const;
97#endif
528b2c61 98
528b2c61 99#if URL_CHECKSUM_DEBUG
62e76326 100
528b2c61 101 void checkUrlChecksum() const;
102#endif
103
c877c0bc
AR
104 /// Before StoreID, code assumed that MemObject stores Request URI.
105 /// After StoreID, some old code still incorrectly assumes that.
106 /// Use this method to mark that incorrect assumption.
107 const char *urlXXX() const { return storeId(); }
108
109 /// Entry StoreID (usually just Request URI); if a buggy code requests this
110 /// before the information is available, returns an "[unknown_URI]" string.
111 const char *storeId() const;
112
113 /// client request URI used for logging; storeId() by default
114 const char *logUri() const;
115
60745f24 116 HttpRequestMethod method;
528b2c61 117 mem_hdr data_hdr;
47f6e231 118 int64_t inmem_lo;
528b2c61 119 dlink_list clients;
63be0a78 120
121 /** \todo move into .cc or .cci */
0e3f3e0d 122 size_t clientCount() const {return nclients;}
123
124 bool clientIsFirst(void *sc) const {return (clients.head && sc == clients.head->data);}
125
528b2c61 126 int nclients;
62e76326 127
ecf22804 128 class SwapOut
62e76326 129 {
ecf22804 130
131 public:
aa1a691e 132 int64_t queue_offset; ///< number of bytes sent to SwapDir for writing
62e76326 133 StoreIOState::Pointer sio;
ddc9b32c
AR
134
135 /// Decision states for StoreEntry::swapoutPossible() and related code.
0e3b2ff0 136 typedef enum { swNeedsCheck = 0, swImpossible = -1, swPossible = +1, swStarted } Decision;
ddc9b32c 137 Decision decision; ///< current decision state
ecf22804 138 };
62e76326 139
ecf22804 140 SwapOut swapout;
63be0a78 141
99921d9d
AR
142 /// cache "I/O" direction and status
143 typedef enum { ioUndecided, ioWriting, ioReading, ioDone } Io;
144
4475555f 145 /// State of an entry with regards to the [shared] in-transit table.
9d4e9cfb
AR
146 class XitTable
147 {
4475555f 148 public:
99921d9d 149 XitTable(): index(-1), io(ioUndecided) {}
4475555f
AR
150
151 int32_t index; ///< entry position inside the in-transit table
99921d9d 152 Io io; ///< current I/O state
4475555f
AR
153 };
154 XitTable xitTable; ///< current [shared] memory caching state for the entry
155
156 /// State of an entry with regards to the [shared] memory caching.
9d4e9cfb
AR
157 class MemCache
158 {
4475555f
AR
159 public:
160 MemCache(): index(-1), offset(0), io(ioUndecided) {}
161
162 int32_t index; ///< entry position inside the memory cache
163 int64_t offset; ///< bytes written/read to/from the memory cache so far
9d4e9cfb 164
4475555f
AR
165 Io io; ///< current I/O state
166 };
167 MemCache memCache; ///< current [shared] memory caching state for the entry
168
169 bool smpCollapsed; ///< whether this entry gets data from another worker
170
528b2c61 171 /* Read only - this reply must be preserved by store clients */
172 /* The original reply. possibly with updated metadata. */
190154cf 173 HttpRequest *request;
62e76326 174
528b2c61 175 struct timeval start_ping;
176 IRCB *ping_reply_callback;
177 void *ircb_data;
62e76326 178
26ac0430 179 struct {
528b2c61 180 STABH *callback;
181 void *data;
2fadd50d 182 } abort;
528b2c61 183 RemovalPolicyNode repl;
184 int id;
47f6e231 185 int64_t object_sz;
528b2c61 186 size_t swap_hdr_sz;
187#if URL_CHECKSUM_DEBUG
62e76326 188
528b2c61 189 unsigned int chksum;
190#endif
62e76326 191
528b2c61 192 const char *vary_headers;
62e76326 193
a46d2c0e 194 void delayRead(DeferredRead const &);
195 void kickReads();
196
528b2c61 197private:
4a56ee8d 198 HttpReply *_reply;
4a56ee8d 199
c877c0bc
AR
200 mutable String storeId_; ///< StoreId for our entry (usually request URI)
201 mutable String logUri_; ///< URI used for logging (usually request URI)
202
a46d2c0e 203 DeferredReadManager deferredReads;
528b2c61 204};
205
d85b8894 206MEMPROXY_CLASS_INLINE(MemObject);
b001e822 207
63be0a78 208/** global current memory removal policy */
aa839030 209extern RemovalPolicy *mem_policy;
210
528b2c61 211#endif /* SQUID_MEMOBJECT_H */