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 "sbuf/SBuf.h"
17 #include "SquidString.h"
19 #include "StoreIOBuffer.h"
20 #include "StoreIOState.h"
21 #include "typedefs.h" //for IRCB
27 typedef void STMCB (void *data
, StoreIOBuffer wroteBuffer
);
28 typedef void STABH(void *);
36 MEMPROXY_CLASS(MemObject
);
39 static size_t inUseCount();
45 /// sets store ID, log URI, and request method; TODO: find a better name
46 void setUris(char const *aStoreId
, char const *aLogUri
, const HttpRequestMethod
&aMethod
);
48 /// whether setUris() has been called
51 void write(const StoreIOBuffer
&buf
);
53 HttpReply
const *getReply() const;
54 void replaceHttpReply(HttpReply
*newrep
);
55 void stat (MemBuf
* mb
) const;
56 int64_t endOffset () const;
57 void markEndOfReplyHeaders(); ///< sets _reply->hdr_sz to endOffset()
58 /// negative if unknown; otherwise, expected object_sz, expected endOffset
59 /// maximum, and stored reply headers+body size (all three are the same)
60 int64_t expectedReplySize() const;
63 int64_t lowestMemReaderOffset() const;
64 bool readAheadPolicyCanRead() const;
65 void addClient(store_client
*);
66 /* XXX belongs in MemObject::swapout, once swaphdrsz is managed
69 int64_t objectBytesOnDisk() const;
70 int64_t policyLowestOffsetToKeep(bool swap
) const;
71 int64_t availableForSwapOut() const; ///< buffered bytes we have not swapped out yet
73 void trimUnSwappable();
74 bool isContiguous() const;
75 int mostBytesWanted(int max
, bool ignoreDelayPools
) const;
76 void setNoDelay(bool const newValue
);
78 DelayId
mostBytesAllowed() const;
81 #if URL_CHECKSUM_DEBUG
83 void checkUrlChecksum() const;
86 /// Before StoreID, code assumed that MemObject stores Request URI.
87 /// After StoreID, some old code still incorrectly assumes that.
88 /// Use this method to mark that incorrect assumption.
89 const char *urlXXX() const { return storeId(); }
91 /// Entry StoreID (usually just Request URI); if a buggy code requests this
92 /// before the information is available, returns an "[unknown_URI]" string.
93 const char *storeId() const;
95 /// client request URI used for logging; storeId() by default
96 const char *logUri() const;
98 HttpRequestMethod method
;
103 size_t clientCount() const {return nclients
;}
105 bool clientIsFirst(void *sc
) const {return (clients
.head
&& sc
== clients
.head
->data
);}
112 SwapOut() : queue_offset(0), decision(swNeedsCheck
) {}
114 int64_t queue_offset
; ///< number of bytes sent to SwapDir for writing
115 StoreIOState::Pointer sio
;
117 /// Decision states for StoreEntry::swapoutPossible() and related code.
118 typedef enum { swNeedsCheck
= 0, swImpossible
= -1, swPossible
= +1, swStarted
} Decision
;
119 Decision decision
; ///< current decision state
124 /// cache "I/O" direction and status
125 typedef enum { ioUndecided
, ioWriting
, ioReading
, ioDone
} Io
;
127 /// State of an entry with regards to the [shared] in-transit table.
131 XitTable(): index(-1), io(ioUndecided
) {}
133 int32_t index
; ///< entry position inside the in-transit table
134 Io io
; ///< current I/O state
136 XitTable xitTable
; ///< current [shared] memory caching state for the entry
138 /// State of an entry with regards to the [shared] memory caching.
142 MemCache(): index(-1), offset(0), io(ioUndecided
) {}
144 int32_t index
; ///< entry position inside the memory cache
145 int64_t offset
; ///< bytes written/read to/from the memory cache so far
147 Io io
; ///< current I/O state
149 MemCache memCache
; ///< current [shared] memory caching state for the entry
151 bool smpCollapsed
; ///< whether this entry gets data from another worker
153 /* Read only - this reply must be preserved by store clients */
154 /* The original reply. possibly with updated metadata. */
155 HttpRequest
*request
;
157 struct timeval start_ping
;
158 IRCB
*ping_reply_callback
;
165 RemovalPolicyNode repl
;
169 #if URL_CHECKSUM_DEBUG
176 void delayRead(DeferredRead
const &);
182 mutable String storeId_
; ///< StoreId for our entry (usually request URI)
183 mutable String logUri_
; ///< URI used for logging (usually request URI)
185 DeferredReadManager deferredReads
;
188 /** global current memory removal policy */
189 extern RemovalPolicy
*mem_policy
;
191 #endif /* SQUID_MEMOBJECT_H */