2 * Copyright (C) 1996-2016 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"
16 #include "SquidString.h"
18 #include "StoreIOBuffer.h"
19 #include "StoreIOState.h"
20 #include "typedefs.h" //for IRCB
26 typedef void STMCB (void *data
, StoreIOBuffer wroteBuffer
);
27 typedef void STABH(void *);
35 MEMPROXY_CLASS(MemObject
);
38 static size_t inUseCount();
44 /// sets store ID, log URI, and request method; TODO: find a better name
45 void setUris(char const *aStoreId
, char const *aLogUri
, const HttpRequestMethod
&aMethod
);
47 /// whether setUris() has been called
50 void write(const StoreIOBuffer
&buf
);
52 HttpReply
const *getReply() const;
53 void replaceHttpReply(HttpReply
*newrep
);
54 void stat (MemBuf
* mb
) const;
55 int64_t endOffset () const;
56 void markEndOfReplyHeaders(); ///< sets _reply->hdr_sz to endOffset()
57 /// negative if unknown; otherwise, expected object_sz, expected endOffset
58 /// maximum, and stored reply headers+body size (all three are the same)
59 int64_t expectedReplySize() const;
62 int64_t lowestMemReaderOffset() const;
63 bool readAheadPolicyCanRead() const;
64 void addClient(store_client
*);
65 /* XXX belongs in MemObject::swapout, once swaphdrsz is managed
68 int64_t objectBytesOnDisk() const;
69 int64_t policyLowestOffsetToKeep(bool swap
) const;
70 int64_t availableForSwapOut() const; ///< buffered bytes we have not swapped out yet
72 void trimUnSwappable();
73 bool isContiguous() const;
74 int mostBytesWanted(int max
, bool ignoreDelayPools
) const;
75 void setNoDelay(bool const newValue
);
77 DelayId
mostBytesAllowed() const;
80 #if URL_CHECKSUM_DEBUG
82 void checkUrlChecksum() const;
85 /// Before StoreID, code assumed that MemObject stores Request URI.
86 /// After StoreID, some old code still incorrectly assumes that.
87 /// Use this method to mark that incorrect assumption.
88 const char *urlXXX() const { return storeId(); }
90 /// Entry StoreID (usually just Request URI); if a buggy code requests this
91 /// before the information is available, returns an "[unknown_URI]" string.
92 const char *storeId() const;
94 /// client request URI used for logging; storeId() by default
95 const char *logUri() const;
97 HttpRequestMethod method
;
102 size_t clientCount() const {return nclients
;}
104 bool clientIsFirst(void *sc
) const {return (clients
.head
&& sc
== clients
.head
->data
);}
111 SwapOut() : queue_offset(0), decision(swNeedsCheck
) {}
113 int64_t queue_offset
; ///< number of bytes sent to SwapDir for writing
114 StoreIOState::Pointer sio
;
116 /// Decision states for StoreEntry::swapoutPossible() and related code.
117 typedef enum { swNeedsCheck
= 0, swImpossible
= -1, swPossible
= +1, swStarted
} Decision
;
118 Decision decision
; ///< current decision state
123 /// cache "I/O" direction and status
124 typedef enum { ioUndecided
, ioWriting
, ioReading
, ioDone
} Io
;
126 /// State of an entry with regards to the [shared] in-transit table.
130 XitTable(): index(-1), io(ioUndecided
) {}
132 int32_t index
; ///< entry position inside the in-transit table
133 Io io
; ///< current I/O state
135 XitTable xitTable
; ///< current [shared] memory caching state for the entry
137 /// State of an entry with regards to the [shared] memory caching.
141 MemCache(): index(-1), offset(0), io(ioUndecided
) {}
143 int32_t index
; ///< entry position inside the memory cache
144 int64_t offset
; ///< bytes written/read to/from the memory cache so far
146 Io io
; ///< current I/O state
148 MemCache memCache
; ///< current [shared] memory caching state for the entry
150 bool smpCollapsed
; ///< whether this entry gets data from another worker
152 /* Read only - this reply must be preserved by store clients */
153 /* The original reply. possibly with updated metadata. */
154 HttpRequest
*request
;
156 struct timeval start_ping
;
157 IRCB
*ping_reply_callback
;
164 RemovalPolicyNode repl
;
168 #if URL_CHECKSUM_DEBUG
173 const char *vary_headers
;
175 void delayRead(DeferredRead
const &);
181 mutable String storeId_
; ///< StoreId for our entry (usually request URI)
182 mutable String logUri_
; ///< URI used for logging (usually request URI)
184 DeferredReadManager deferredReads
;
187 /** global current memory removal policy */
188 extern RemovalPolicy
*mem_policy
;
190 #endif /* SQUID_MEMOBJECT_H */