2 * Copyright (C) 1996-2017 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 *);
33 MEMPROXY_CLASS(MemObject
);
36 static size_t inUseCount();
42 /// Sets store ID, log URI, and request method (unless already set). Does
43 /// not clobber the method so that, say, a HEAD hit for a GET entry keeps
44 /// the GET method that matches the entry key. Same for the other parts of
45 /// the trio because the entry filling code may expect them to be constant.
46 /// XXX: Avoid this method. We plan to remove it and make the trio constant
47 /// after addressing the XXX in MemStore::get().
48 void setUris(char const *aStoreId
, char const *aLogUri
, const HttpRequestMethod
&aMethod
);
50 /// whether setUris() has been called
53 void write(const StoreIOBuffer
&buf
);
54 void unlinkRequest() { request
= nullptr; }
55 const HttpReplyPointer
&getReply() const { return reply_
; }
56 void replaceReply(const HttpReplyPointer
&r
) { reply_
= r
; }
57 void stat (MemBuf
* mb
) const;
58 int64_t endOffset () const;
59 void markEndOfReplyHeaders(); ///< sets reply_->hdr_sz to endOffset()
60 /// negative if unknown; otherwise, expected object_sz, expected endOffset
61 /// maximum, and stored reply headers+body size (all three are the same)
62 int64_t expectedReplySize() const;
65 int64_t lowestMemReaderOffset() const;
66 bool readAheadPolicyCanRead() const;
67 void addClient(store_client
*);
68 /* XXX belongs in MemObject::swapout, once swaphdrsz is managed
71 int64_t objectBytesOnDisk() const;
72 int64_t policyLowestOffsetToKeep(bool swap
) const;
73 int64_t availableForSwapOut() const; ///< buffered bytes we have not swapped out yet
75 void trimUnSwappable();
76 bool isContiguous() const;
77 int mostBytesWanted(int max
, bool ignoreDelayPools
) const;
78 void setNoDelay(bool const newValue
);
80 DelayId
mostBytesAllowed() const;
83 #if URL_CHECKSUM_DEBUG
85 void checkUrlChecksum() const;
88 /// Before StoreID, code assumed that MemObject stores Request URI.
89 /// After StoreID, some old code still incorrectly assumes that.
90 /// Use this method to mark that incorrect assumption.
91 const char *urlXXX() const { return storeId(); }
93 /// Entry StoreID (usually just Request URI); if a buggy code requests this
94 /// before the information is available, returns an "[unknown_URI]" string.
95 const char *storeId() const;
97 /// client request URI used for logging; storeId() by default
98 const char *logUri() const;
100 HttpRequestMethod method
;
105 size_t clientCount() const {return nclients
;}
107 bool clientIsFirst(void *sc
) const {return (clients
.head
&& sc
== clients
.head
->data
);}
114 SwapOut() : queue_offset(0), decision(swNeedsCheck
) {}
116 int64_t queue_offset
; ///< number of bytes sent to SwapDir for writing
117 StoreIOState::Pointer sio
;
119 /// Decision states for StoreEntry::swapoutPossible() and related code.
120 typedef enum { swNeedsCheck
= 0, swImpossible
= -1, swPossible
= +1, swStarted
} Decision
;
121 Decision decision
; ///< current decision state
126 /// cache "I/O" direction and status
127 typedef enum { ioUndecided
, ioWriting
, ioReading
, ioDone
} Io
;
129 /// State of an entry with regards to the [shared] in-transit table.
133 XitTable(): index(-1), io(ioUndecided
) {}
135 int32_t index
; ///< entry position inside the in-transit table
136 Io io
; ///< current I/O state
138 XitTable xitTable
; ///< current [shared] memory caching state for the entry
140 /// State of an entry with regards to the [shared] memory caching.
144 MemCache(): index(-1), offset(0), io(ioUndecided
) {}
146 int32_t index
; ///< entry position inside the memory cache
147 int64_t offset
; ///< bytes written/read to/from the memory cache so far
149 Io io
; ///< current I/O state
151 MemCache memCache
; ///< current [shared] memory caching state for the entry
153 bool smpCollapsed
; ///< whether this entry gets data from another worker
155 /* Read only - this reply must be preserved by store clients */
156 /* The original reply. possibly with updated metadata. */
157 HttpRequestPointer request
;
159 struct timeval start_ping
;
160 IRCB
*ping_reply_callback
;
167 RemovalPolicyNode repl
;
171 #if URL_CHECKSUM_DEBUG
178 void delayRead(DeferredRead
const &);
182 HttpReplyPointer reply_
;
184 mutable String storeId_
; ///< StoreId for our entry (usually request URI)
185 mutable String logUri_
; ///< URI used for logging (usually request URI)
187 DeferredReadManager deferredReads
;
190 /** global current memory removal policy */
191 extern RemovalPolicy
*mem_policy
;
193 #endif /* SQUID_MEMOBJECT_H */