2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_MEMOBJECT_H
10 #define SQUID_MEMOBJECT_H
14 #include "http/RequestMethod.h"
15 #include "RemovalPolicy.h"
17 #include "StoreIOBuffer.h"
18 #include "StoreIOState.h"
24 typedef void STMCB (void *data
, StoreIOBuffer wroteBuffer
);
32 MEMPROXY_CLASS(MemObject
);
35 static size_t inUseCount();
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
);
44 /// whether setUris() has been called
47 void write(const StoreIOBuffer
&buf
);
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;
59 int64_t lowestMemReaderOffset() const;
60 bool readAheadPolicyCanRead() const;
61 void addClient(store_client
*);
62 /* XXX belongs in MemObject::swapout, once swaphdrsz is managed
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
69 void trimUnSwappable();
70 bool isContiguous() const;
71 int mostBytesWanted(int max
, bool ignoreDelayPools
) const;
72 void setNoDelay(bool const newValue
);
74 DelayId
mostBytesAllowed() const;
77 #if URL_CHECKSUM_DEBUG
79 void checkUrlChecksum() const;
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(); }
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;
91 /// client request URI used for logging; storeId() by default
92 const char *logUri() const;
94 HttpRequestMethod method
;
99 /** \todo move into .cc or .cci */
100 size_t clientCount() const {return nclients
;}
102 bool clientIsFirst(void *sc
) const {return (clients
.head
&& sc
== clients
.head
->data
);}
110 int64_t queue_offset
; ///< number of bytes sent to SwapDir for writing
111 StoreIOState::Pointer sio
;
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
120 /// cache "I/O" direction and status
121 typedef enum { ioUndecided
, ioWriting
, ioReading
, ioDone
} Io
;
123 /// State of an entry with regards to the [shared] in-transit table.
127 XitTable(): index(-1), io(ioUndecided
) {}
129 int32_t index
; ///< entry position inside the in-transit table
130 Io io
; ///< current I/O state
132 XitTable xitTable
; ///< current [shared] memory caching state for the entry
134 /// State of an entry with regards to the [shared] memory caching.
138 MemCache(): index(-1), offset(0), io(ioUndecided
) {}
140 int32_t index
; ///< entry position inside the memory cache
141 int64_t offset
; ///< bytes written/read to/from the memory cache so far
143 Io io
; ///< current I/O state
145 MemCache memCache
; ///< current [shared] memory caching state for the entry
147 bool smpCollapsed
; ///< whether this entry gets data from another worker
149 /* Read only - this reply must be preserved by store clients */
150 /* The original reply. possibly with updated metadata. */
151 HttpRequest
*request
;
153 struct timeval start_ping
;
154 IRCB
*ping_reply_callback
;
161 RemovalPolicyNode repl
;
165 #if URL_CHECKSUM_DEBUG
170 const char *vary_headers
;
172 void delayRead(DeferredRead
const &);
178 mutable String storeId_
; ///< StoreId for our entry (usually request URI)
179 mutable String logUri_
; ///< URI used for logging (usually request URI)
181 DeferredReadManager deferredReads
;
184 /** global current memory removal policy */
185 extern RemovalPolicy
*mem_policy
;
187 #endif /* SQUID_MEMOBJECT_H */