]> git.ipfire.org Git - thirdparty/squid.git/blame - src/MemObject.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / MemObject.h
CommitLineData
528b2c61 1/*
bbc27441 2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
528b2c61 3 *
bbc27441
AJ
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.
528b2c61 7 */
8
9#ifndef SQUID_MEMOBJECT_H
10#define SQUID_MEMOBJECT_H
11
a46d2c0e 12#include "CommRead.h"
c6983ec7 13#include "dlink.h"
f35c0145 14#include "http/RequestMethod.h"
c6983ec7
FC
15#include "RemovalPolicy.h"
16#include "stmem.h"
17#include "StoreIOBuffer.h"
18#include "StoreIOState.h"
528b2c61 19
43ca19e0
FC
20#if USE_DELAY_POOLS
21#include "DelayId.h"
22#endif
23
528b2c61 24typedef void STMCB (void *data, StoreIOBuffer wroteBuffer);
25
26class store_client;
582c2af2 27class HttpRequest;
43ca19e0 28class HttpReply;
528b2c61 29
62e76326 30class MemObject
31{
741c2986 32 MEMPROXY_CLASS(MemObject);
62e76326 33
528b2c61 34public:
35 static size_t inUseCount();
62e76326 36
528b2c61 37 void dump() const;
c877c0bc 38 MemObject();
528b2c61 39 ~MemObject();
40
c877c0bc
AR
41 /// sets store ID, log URI, and request method; TODO: find a better name
42 void setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod);
9487bae9 43
c877c0bc
AR
44 /// whether setUris() has been called
45 bool hasUris() const;
9487bae9 46
55759ffb 47 void write(const StoreIOBuffer &buf);
528b2c61 48 void unlinkRequest();
49 HttpReply const *getReply() const;
4a56ee8d 50 void replaceHttpReply(HttpReply *newrep);
fcc35180 51 void stat (MemBuf * mb) const;
47f6e231 52 int64_t endOffset () const;
3756e5c0 53 void markEndOfReplyHeaders(); ///< sets _reply->hdr_sz to endOffset()
aa1a691e
AR
54 /// negative if unknown; otherwise, expected object_sz, expected endOffset
55 /// maximum, and stored reply headers+body size (all three are the same)
56 int64_t expectedReplySize() const;
47f6e231 57 int64_t size() const;
528b2c61 58 void reset();
47f6e231 59 int64_t lowestMemReaderOffset() const;
528b2c61 60 bool readAheadPolicyCanRead() const;
61 void addClient(store_client *);
62e76326 62 /* XXX belongs in MemObject::swapout, once swaphdrsz is managed
528b2c61 63 * better
64 */
47f6e231 65 int64_t objectBytesOnDisk() const;
10aeba1d 66 int64_t policyLowestOffsetToKeep(bool swap) const;
5b55f1f1 67 int64_t availableForSwapOut() const; ///< buffered bytes we have not swapped out yet
528b2c61 68 void trimSwappable();
69 void trimUnSwappable();
70 bool isContiguous() const;
384a7590 71 int mostBytesWanted(int max, bool ignoreDelayPools) const;
a46d2c0e 72 void setNoDelay(bool const newValue);
9a0a18de 73#if USE_DELAY_POOLS
b67e2c8c 74 DelayId mostBytesAllowed() const;
75#endif
528b2c61 76
528b2c61 77#if URL_CHECKSUM_DEBUG
62e76326 78
528b2c61 79 void checkUrlChecksum() const;
80#endif
81
c877c0bc
AR
82 /// Before StoreID, code assumed that MemObject stores Request URI.
83 /// After StoreID, some old code still incorrectly assumes that.
84 /// Use this method to mark that incorrect assumption.
85 const char *urlXXX() const { return storeId(); }
86
87 /// Entry StoreID (usually just Request URI); if a buggy code requests this
88 /// before the information is available, returns an "[unknown_URI]" string.
89 const char *storeId() const;
90
91 /// client request URI used for logging; storeId() by default
92 const char *logUri() const;
93
60745f24 94 HttpRequestMethod method;
528b2c61 95 mem_hdr data_hdr;
47f6e231 96 int64_t inmem_lo;
528b2c61 97 dlink_list clients;
63be0a78 98
99 /** \todo move into .cc or .cci */
0e3f3e0d 100 size_t clientCount() const {return nclients;}
101
102 bool clientIsFirst(void *sc) const {return (clients.head && sc == clients.head->data);}
103
528b2c61 104 int nclients;
62e76326 105
ecf22804 106 class SwapOut
62e76326 107 {
ecf22804 108
109 public:
aa1a691e 110 int64_t queue_offset; ///< number of bytes sent to SwapDir for writing
62e76326 111 StoreIOState::Pointer sio;
ddc9b32c
AR
112
113 /// Decision states for StoreEntry::swapoutPossible() and related code.
0e3b2ff0 114 typedef enum { swNeedsCheck = 0, swImpossible = -1, swPossible = +1, swStarted } Decision;
ddc9b32c 115 Decision decision; ///< current decision state
ecf22804 116 };
62e76326 117
ecf22804 118 SwapOut swapout;
63be0a78 119
99921d9d
AR
120 /// cache "I/O" direction and status
121 typedef enum { ioUndecided, ioWriting, ioReading, ioDone } Io;
122
4475555f 123 /// State of an entry with regards to the [shared] in-transit table.
9d4e9cfb
AR
124 class XitTable
125 {
4475555f 126 public:
99921d9d 127 XitTable(): index(-1), io(ioUndecided) {}
4475555f
AR
128
129 int32_t index; ///< entry position inside the in-transit table
99921d9d 130 Io io; ///< current I/O state
4475555f
AR
131 };
132 XitTable xitTable; ///< current [shared] memory caching state for the entry
133
134 /// State of an entry with regards to the [shared] memory caching.
9d4e9cfb
AR
135 class MemCache
136 {
4475555f
AR
137 public:
138 MemCache(): index(-1), offset(0), io(ioUndecided) {}
139
140 int32_t index; ///< entry position inside the memory cache
141 int64_t offset; ///< bytes written/read to/from the memory cache so far
9d4e9cfb 142
4475555f
AR
143 Io io; ///< current I/O state
144 };
145 MemCache memCache; ///< current [shared] memory caching state for the entry
146
147 bool smpCollapsed; ///< whether this entry gets data from another worker
148
528b2c61 149 /* Read only - this reply must be preserved by store clients */
150 /* The original reply. possibly with updated metadata. */
190154cf 151 HttpRequest *request;
62e76326 152
528b2c61 153 struct timeval start_ping;
154 IRCB *ping_reply_callback;
155 void *ircb_data;
62e76326 156
26ac0430 157 struct {
528b2c61 158 STABH *callback;
159 void *data;
2fadd50d 160 } abort;
528b2c61 161 RemovalPolicyNode repl;
162 int id;
47f6e231 163 int64_t object_sz;
528b2c61 164 size_t swap_hdr_sz;
165#if URL_CHECKSUM_DEBUG
62e76326 166
528b2c61 167 unsigned int chksum;
168#endif
62e76326 169
528b2c61 170 const char *vary_headers;
62e76326 171
a46d2c0e 172 void delayRead(DeferredRead const &);
173 void kickReads();
174
528b2c61 175private:
4a56ee8d 176 HttpReply *_reply;
4a56ee8d 177
c877c0bc
AR
178 mutable String storeId_; ///< StoreId for our entry (usually request URI)
179 mutable String logUri_; ///< URI used for logging (usually request URI)
180
a46d2c0e 181 DeferredReadManager deferredReads;
528b2c61 182};
183
63be0a78 184/** global current memory removal policy */
aa839030 185extern RemovalPolicy *mem_policy;
186
528b2c61 187#endif /* SQUID_MEMOBJECT_H */
f53969cc 188