3 * SQUID Web Proxy Cache http://www.squid-cache.org/
4 * ----------------------------------------------------------
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.
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.
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.
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.
31 #ifndef SQUID_MEMOBJECT_H
32 #define SQUID_MEMOBJECT_H
36 #include "HttpRequestMethod.h"
37 #include "RemovalPolicy.h"
39 #include "StoreIOBuffer.h"
40 #include "StoreIOState.h"
46 typedef void STMCB (void *data
, StoreIOBuffer wroteBuffer
);
56 static size_t inUseCount();
57 MEMPROXY_CLASS(MemObject
);
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
);
66 /// whether setUris() has been called
69 void write(const StoreIOBuffer
&buf
);
71 HttpReply
const *getReply() const;
72 void replaceHttpReply(HttpReply
*newrep
);
73 void stat (MemBuf
* mb
) const;
74 int64_t endOffset () const;
75 void markEndOfReplyHeaders(); ///< sets _reply->hdr_sz to endOffset()
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;
81 int64_t lowestMemReaderOffset() const;
82 bool readAheadPolicyCanRead() const;
83 void addClient(store_client
*);
84 /* XXX belongs in MemObject::swapout, once swaphdrsz is managed
87 int64_t objectBytesOnDisk() const;
88 int64_t policyLowestOffsetToKeep(bool swap
) const;
89 int64_t availableForSwapOut() const; ///< buffered bytes we have not swapped out yet
91 void trimUnSwappable();
92 bool isContiguous() const;
93 int mostBytesWanted(int max
, bool ignoreDelayPools
) const;
94 void setNoDelay(bool const newValue
);
96 DelayId
mostBytesAllowed() const;
99 #if URL_CHECKSUM_DEBUG
101 void checkUrlChecksum() const;
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(); }
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;
113 /// client request URI used for logging; storeId() by default
114 const char *logUri() const;
116 HttpRequestMethod method
;
121 /** \todo move into .cc or .cci */
122 size_t clientCount() const {return nclients
;}
124 bool clientIsFirst(void *sc
) const {return (clients
.head
&& sc
== clients
.head
->data
);}
132 int64_t queue_offset
; ///< number of bytes sent to SwapDir for writing
133 StoreIOState::Pointer sio
;
135 /// Decision states for StoreEntry::swapoutPossible() and related code.
136 typedef enum { swNeedsCheck
= 0, swImpossible
= -1, swPossible
= +1, swStarted
} Decision
;
137 Decision decision
; ///< current decision state
142 /// cache "I/O" direction and status
143 typedef enum { ioUndecided
, ioWriting
, ioReading
, ioDone
} Io
;
145 /// State of an entry with regards to the [shared] in-transit table.
148 XitTable(): index(-1), io(ioUndecided
) {}
150 int32_t index
; ///< entry position inside the in-transit table
151 Io io
; ///< current I/O state
153 XitTable xitTable
; ///< current [shared] memory caching state for the entry
155 /// State of an entry with regards to the [shared] memory caching.
158 MemCache(): index(-1), offset(0), io(ioUndecided
) {}
160 int32_t index
; ///< entry position inside the memory cache
161 int64_t offset
; ///< bytes written/read to/from the memory cache so far
163 Io io
; ///< current I/O state
165 MemCache memCache
; ///< current [shared] memory caching state for the entry
167 bool smpCollapsed
; ///< whether this entry gets data from another worker
169 /* Read only - this reply must be preserved by store clients */
170 /* The original reply. possibly with updated metadata. */
171 HttpRequest
*request
;
173 struct timeval start_ping
;
174 IRCB
*ping_reply_callback
;
181 RemovalPolicyNode repl
;
185 #if URL_CHECKSUM_DEBUG
190 const char *vary_headers
;
192 void delayRead(DeferredRead
const &);
198 mutable String storeId_
; ///< StoreId for our entry (usually request URI)
199 mutable String logUri_
; ///< URI used for logging (usually request URI)
201 DeferredReadManager deferredReads
;
204 MEMPROXY_CLASS_INLINE(MemObject
);
206 /** global current memory removal policy */
207 extern RemovalPolicy
*mem_policy
;
209 #endif /* SQUID_MEMOBJECT_H */