]> git.ipfire.org Git - thirdparty/squid.git/blob - src/MemObject.h
Merge 3p2-rock.
[thirdparty/squid.git] / src / MemObject.h
1 /*
2 * $Id$
3 *
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 */
32
33 #ifndef SQUID_MEMOBJECT_H
34 #define SQUID_MEMOBJECT_H
35
36 #include "StoreIOBuffer.h"
37 #include "StoreIOState.h"
38 #include "stmem.h"
39 #include "CommRead.h"
40 #include "RemovalPolicy.h"
41 #include "HttpRequestMethod.h"
42
43 typedef void STMCB (void *data, StoreIOBuffer wroteBuffer);
44
45 class store_client;
46 #if USE_DELAY_POOLS
47 #include "DelayId.h"
48 #endif
49
50 class MemObject
51 {
52
53 public:
54 static size_t inUseCount();
55 MEMPROXY_CLASS(MemObject);
56
57 void dump() const;
58 MemObject(char const *, char const *);
59 ~MemObject();
60
61 void write(StoreIOBuffer, STMCB *, void *);
62 void unlinkRequest();
63 HttpReply const *getReply() const;
64 void replaceHttpReply(HttpReply *newrep);
65 void stat (MemBuf * mb) const;
66 int64_t endOffset () const;
67 /// negative if unknown; otherwise, expected object_sz, expected endOffset
68 /// maximum, and stored reply headers+body size (all three are the same)
69 int64_t expectedReplySize() const;
70 int64_t size() const;
71 void reset();
72 int64_t lowestMemReaderOffset() const;
73 bool readAheadPolicyCanRead() const;
74 void addClient(store_client *);
75 /* XXX belongs in MemObject::swapout, once swaphdrsz is managed
76 * better
77 */
78 int64_t objectBytesOnDisk() const;
79 int64_t policyLowestOffsetToKeep(bool swap) const;
80 void trimSwappable();
81 void trimUnSwappable();
82 bool isContiguous() const;
83 int mostBytesWanted(int max) const;
84 void setNoDelay(bool const newValue);
85 #if USE_DELAY_POOLS
86 DelayId mostBytesAllowed() const;
87 #endif
88
89
90 #if URL_CHECKSUM_DEBUG
91
92 void checkUrlChecksum() const;
93 #endif
94
95 HttpRequestMethod method;
96 char *url;
97 mem_hdr data_hdr;
98 int64_t inmem_lo;
99 dlink_list clients;
100
101 /** \todo move into .cc or .cci */
102 size_t clientCount() const {return nclients;}
103
104 bool clientIsFirst(void *sc) const {return (clients.head && sc == clients.head->data);}
105
106 int nclients;
107
108 class SwapOut
109 {
110
111 public:
112 int64_t queue_offset; ///< number of bytes sent to SwapDir for writing
113 StoreIOState::Pointer sio;
114 };
115
116 SwapOut swapout;
117
118 /* Read only - this reply must be preserved by store clients */
119 /* The original reply. possibly with updated metadata. */
120 HttpRequest *request;
121
122 struct timeval start_ping;
123 IRCB *ping_reply_callback;
124 void *ircb_data;
125
126 struct {
127 STABH *callback;
128 void *data;
129 } abort;
130 char *log_url;
131 RemovalPolicyNode repl;
132 int id;
133 int64_t object_sz;
134 size_t swap_hdr_sz;
135 #if URL_CHECKSUM_DEBUG
136
137 unsigned int chksum;
138 #endif
139
140 const char *vary_headers;
141
142 void delayRead(DeferredRead const &);
143 void kickReads();
144
145 private:
146 HttpReply *_reply;
147
148 DeferredReadManager deferredReads;
149 };
150
151 MEMPROXY_CLASS_INLINE(MemObject);
152
153 /** global current memory removal policy */
154 extern RemovalPolicy *mem_policy;
155
156 #endif /* SQUID_MEMOBJECT_H */