]> git.ipfire.org Git - thirdparty/squid.git/blob - src/MemObject.h
Merged from trunk
[thirdparty/squid.git] / src / MemObject.h
1 /*
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.
19 *
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.
24 *
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
34 #include "CommRead.h"
35 #include "dlink.h"
36 #include "HttpRequestMethod.h"
37 #include "RemovalPolicy.h"
38 #include "stmem.h"
39 #include "StoreIOBuffer.h"
40 #include "StoreIOState.h"
41
42 #if USE_DELAY_POOLS
43 #include "DelayId.h"
44 #endif
45
46 typedef void STMCB (void *data, StoreIOBuffer wroteBuffer);
47
48 class store_client;
49 class HttpRequest;
50 class HttpReply;
51
52 class MemObject
53 {
54
55 public:
56 static size_t inUseCount();
57 MEMPROXY_CLASS(MemObject);
58
59 void dump() const;
60 MemObject(char const *, char const *);
61 ~MemObject();
62
63 /// replaces construction-time URLs with correct ones; see hidden_mem_obj
64 void resetUrls(char const *aUrl, char const *aLog_url);
65
66 void write(StoreIOBuffer, STMCB *, void *);
67 void unlinkRequest();
68 HttpReply const *getReply() const;
69 void replaceHttpReply(HttpReply *newrep);
70 void stat (MemBuf * mb) const;
71 int64_t endOffset () const;
72 void markEndOfReplyHeaders(); ///< sets _reply->hdr_sz to endOffset()
73 /// negative if unknown; otherwise, expected object_sz, expected endOffset
74 /// maximum, and stored reply headers+body size (all three are the same)
75 int64_t expectedReplySize() const;
76 int64_t size() const;
77 void reset();
78 int64_t lowestMemReaderOffset() const;
79 bool readAheadPolicyCanRead() const;
80 void addClient(store_client *);
81 /* XXX belongs in MemObject::swapout, once swaphdrsz is managed
82 * better
83 */
84 int64_t objectBytesOnDisk() const;
85 int64_t policyLowestOffsetToKeep(bool swap) const;
86 int64_t availableForSwapOut() const; ///< buffered bytes we have not swapped out yet
87 void trimSwappable();
88 void trimUnSwappable();
89 bool isContiguous() const;
90 int mostBytesWanted(int max, bool ignoreDelayPools) const;
91 void setNoDelay(bool const newValue);
92 #if USE_DELAY_POOLS
93 DelayId mostBytesAllowed() const;
94 #endif
95
96 #if URL_CHECKSUM_DEBUG
97
98 void checkUrlChecksum() const;
99 #endif
100
101 HttpRequestMethod method;
102 char *url;
103 mem_hdr data_hdr;
104 int64_t inmem_lo;
105 dlink_list clients;
106
107 /** \todo move into .cc or .cci */
108 size_t clientCount() const {return nclients;}
109
110 bool clientIsFirst(void *sc) const {return (clients.head && sc == clients.head->data);}
111
112 int nclients;
113
114 class SwapOut
115 {
116
117 public:
118 int64_t queue_offset; ///< number of bytes sent to SwapDir for writing
119 StoreIOState::Pointer sio;
120
121 /// Decision states for StoreEntry::swapoutPossible() and related code.
122 typedef enum { swNeedsCheck = 0, swImpossible = -1, swPossible = +1 } Decision;
123 Decision decision; ///< current decision state
124 };
125
126 SwapOut swapout;
127
128 /* Read only - this reply must be preserved by store clients */
129 /* The original reply. possibly with updated metadata. */
130 HttpRequest *request;
131
132 struct timeval start_ping;
133 IRCB *ping_reply_callback;
134 void *ircb_data;
135
136 struct {
137 STABH *callback;
138 void *data;
139 } abort;
140 char *log_url;
141 RemovalPolicyNode repl;
142 int id;
143 int64_t object_sz;
144 size_t swap_hdr_sz;
145 #if URL_CHECKSUM_DEBUG
146
147 unsigned int chksum;
148 #endif
149
150 const char *vary_headers;
151
152 void delayRead(DeferredRead const &);
153 void kickReads();
154
155 private:
156 HttpReply *_reply;
157
158 DeferredReadManager deferredReads;
159 };
160
161 MEMPROXY_CLASS_INLINE(MemObject);
162
163 /** global current memory removal policy */
164 extern RemovalPolicy *mem_policy;
165
166 #endif /* SQUID_MEMOBJECT_H */