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"
17 #include "StoreIOBuffer.h"
18 #include "StoreIOState.h"
19 #include "typedefs.h" //for IRCB
25 typedef void STMCB (void *data
, StoreIOBuffer wroteBuffer
);
26 typedef void STABH(void *);
34 MEMPROXY_CLASS(MemObject
);
37 static size_t inUseCount();
43 /// sets store ID, log URI, and request method; TODO: find a better name
44 void setUris(char const *aStoreId
, char const *aLogUri
, const HttpRequestMethod
&aMethod
);
46 /// whether setUris() has been called
49 void write(const StoreIOBuffer
&buf
);
51 HttpReply
const *getReply() const;
52 void replaceHttpReply(HttpReply
*newrep
);
53 void stat (MemBuf
* mb
) const;
54 int64_t endOffset () const;
55 void markEndOfReplyHeaders(); ///< sets _reply->hdr_sz to endOffset()
56 /// negative if unknown; otherwise, expected object_sz, expected endOffset
57 /// maximum, and stored reply headers+body size (all three are the same)
58 int64_t expectedReplySize() const;
61 int64_t lowestMemReaderOffset() const;
62 bool readAheadPolicyCanRead() const;
63 void addClient(store_client
*);
64 /* XXX belongs in MemObject::swapout, once swaphdrsz is managed
67 int64_t objectBytesOnDisk() const;
68 int64_t policyLowestOffsetToKeep(bool swap
) const;
69 int64_t availableForSwapOut() const; ///< buffered bytes we have not swapped out yet
71 void trimUnSwappable();
72 bool isContiguous() const;
73 int mostBytesWanted(int max
, bool ignoreDelayPools
) const;
74 void setNoDelay(bool const newValue
);
76 DelayId
mostBytesAllowed() const;
79 #if URL_CHECKSUM_DEBUG
81 void checkUrlChecksum() const;
84 /// Before StoreID, code assumed that MemObject stores Request URI.
85 /// After StoreID, some old code still incorrectly assumes that.
86 /// Use this method to mark that incorrect assumption.
87 const char *urlXXX() const { return storeId(); }
89 /// Entry StoreID (usually just Request URI); if a buggy code requests this
90 /// before the information is available, returns an "[unknown_URI]" string.
91 const char *storeId() const;
93 /// client request URI used for logging; storeId() by default
94 const char *logUri() const;
96 HttpRequestMethod method
;
101 size_t clientCount() const {return nclients
;}
103 bool clientIsFirst(void *sc
) const {return (clients
.head
&& sc
== clients
.head
->data
);}
110 SwapOut() : queue_offset(0), decision(swNeedsCheck
) {}
112 int64_t queue_offset
; ///< number of bytes sent to SwapDir for writing
113 StoreIOState::Pointer sio
;
115 /// Decision states for StoreEntry::swapoutPossible() and related code.
116 typedef enum { swNeedsCheck
= 0, swImpossible
= -1, swPossible
= +1, swStarted
} Decision
;
117 Decision decision
; ///< current decision state
122 /// cache "I/O" direction and status
123 typedef enum { ioUndecided
, ioWriting
, ioReading
, ioDone
} Io
;
125 /// State of an entry with regards to the [shared] in-transit table.
129 XitTable(): index(-1), io(ioUndecided
) {}
131 int32_t index
; ///< entry position inside the in-transit table
132 Io io
; ///< current I/O state
134 XitTable xitTable
; ///< current [shared] memory caching state for the entry
136 /// State of an entry with regards to the [shared] memory caching.
140 MemCache(): index(-1), offset(0), io(ioUndecided
) {}
142 int32_t index
; ///< entry position inside the memory cache
143 int64_t offset
; ///< bytes written/read to/from the memory cache so far
145 Io io
; ///< current I/O state
147 MemCache memCache
; ///< current [shared] memory caching state for the entry
149 bool smpCollapsed
; ///< whether this entry gets data from another worker
151 /* Read only - this reply must be preserved by store clients */
152 /* The original reply. possibly with updated metadata. */
153 HttpRequest
*request
;
155 struct timeval start_ping
;
156 IRCB
*ping_reply_callback
;
163 RemovalPolicyNode repl
;
167 #if URL_CHECKSUM_DEBUG
172 const char *vary_headers
;
174 void delayRead(DeferredRead
const &);
180 mutable String storeId_
; ///< StoreId for our entry (usually request URI)
181 mutable String logUri_
; ///< URI used for logging (usually request URI)
183 DeferredReadManager deferredReads
;
186 /** global current memory removal policy */
187 extern RemovalPolicy
*mem_policy
;
189 #endif /* SQUID_MEMOBJECT_H */