2 * Copyright (C) 1996-2018 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 "store/forward.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 *);
35 MEMPROXY_CLASS(MemObject
);
38 static size_t inUseCount();
44 /// Sets store ID, log URI, and request method (unless already set). Does
45 /// not clobber the method so that, say, a HEAD hit for a GET entry keeps
46 /// the GET method that matches the entry key. Same for the other parts of
47 /// the trio because the entry filling code may expect them to be constant.
48 /// XXX: Avoid this method. We plan to remove it and make the trio constant
49 /// after addressing the XXX in MemStore::get().
50 void setUris(char const *aStoreId
, char const *aLogUri
, const HttpRequestMethod
&aMethod
);
52 /// whether setUris() has been called
55 void write(const StoreIOBuffer
&buf
);
56 void unlinkRequest() { request
= nullptr; }
57 const HttpReplyPointer
&getReply() const { return reply_
; }
58 void replaceReply(const HttpReplyPointer
&r
) { reply_
= r
; }
59 void stat (MemBuf
* mb
) const;
60 int64_t endOffset () const;
61 void markEndOfReplyHeaders(); ///< sets reply_->hdr_sz to endOffset()
62 /// negative if unknown; otherwise, expected object_sz, expected endOffset
63 /// maximum, and stored reply headers+body size (all three are the same)
64 int64_t expectedReplySize() const;
67 int64_t lowestMemReaderOffset() const;
68 bool readAheadPolicyCanRead() const;
69 void addClient(store_client
*);
70 /* XXX belongs in MemObject::swapout, once swaphdrsz is managed
73 int64_t objectBytesOnDisk() const;
74 int64_t policyLowestOffsetToKeep(bool swap
) const;
75 int64_t availableForSwapOut() const; ///< buffered bytes we have not swapped out yet
77 void trimUnSwappable();
78 bool isContiguous() const;
79 int mostBytesWanted(int max
, bool ignoreDelayPools
) const;
80 void setNoDelay(bool const newValue
);
82 DelayId
mostBytesAllowed() const;
85 #if URL_CHECKSUM_DEBUG
87 void checkUrlChecksum() const;
90 /// Before StoreID, code assumed that MemObject stores Request URI.
91 /// After StoreID, some old code still incorrectly assumes that.
92 /// Use this method to mark that incorrect assumption.
93 const char *urlXXX() const { return storeId(); }
95 /// Entry StoreID (usually just Request URI); if a buggy code requests this
96 /// before the information is available, returns an "[unknown_URI]" string.
97 const char *storeId() const;
99 /// client request URI used for logging; storeId() by default
100 const char *logUri() const;
102 HttpRequestMethod method
;
107 size_t clientCount() const {return nclients
;}
109 bool clientIsFirst(void *sc
) const {return (clients
.head
&& sc
== clients
.head
->data
);}
116 SwapOut() : queue_offset(0), decision(swNeedsCheck
) {}
118 int64_t queue_offset
; ///< number of bytes sent to SwapDir for writing
119 StoreIOState::Pointer sio
;
121 /// Decision states for StoreEntry::swapoutPossible() and related code.
122 typedef enum { swNeedsCheck
= 0, swImpossible
= -1, swPossible
= +1, swStarted
} Decision
;
123 Decision decision
; ///< current decision state
128 /* TODO: Remove this change-minimizing hack */
129 using Io
= Store::IoStatus
;
130 static constexpr Io ioUndecided
= Store::ioUndecided
;
131 static constexpr Io ioReading
= Store::ioReading
;
132 static constexpr Io ioWriting
= Store::ioWriting
;
133 static constexpr Io ioDone
= Store::ioDone
;
135 /// State of an entry with regards to the [shared] in-transit table.
139 XitTable(): index(-1), io(ioUndecided
) {}
141 int32_t index
; ///< entry position inside the in-transit table
142 Io io
; ///< current I/O state
144 XitTable xitTable
; ///< current [shared] memory caching state for the entry
146 /// State of an entry with regards to the [shared] memory caching.
150 MemCache(): index(-1), offset(0), io(ioUndecided
) {}
152 int32_t index
; ///< entry position inside the memory cache
153 int64_t offset
; ///< bytes written/read to/from the memory cache so far
155 Io io
; ///< current I/O state
157 MemCache memCache
; ///< current [shared] memory caching state for the entry
159 /* Read only - this reply must be preserved by store clients */
160 /* The original reply. possibly with updated metadata. */
161 HttpRequestPointer request
;
163 struct timeval start_ping
;
164 IRCB
*ping_reply_callback
;
165 PeerSelector
*ircb_data
;
171 RemovalPolicyNode repl
;
175 #if URL_CHECKSUM_DEBUG
182 void delayRead(DeferredRead
const &);
186 HttpReplyPointer reply_
;
188 mutable String storeId_
; ///< StoreId for our entry (usually request URI)
189 mutable String logUri_
; ///< URI used for logging (usually request URI)
191 DeferredReadManager deferredReads
;
194 /** global current memory removal policy */
195 extern RemovalPolicy
*mem_policy
;
197 #endif /* SQUID_MEMOBJECT_H */