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