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