Squid Web Cache master
Loading...
Searching...
No Matches
StoreClient.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9#ifndef SQUID_SRC_STORECLIENT_H
10#define SQUID_SRC_STORECLIENT_H
11
12#include "acl/ChecklistFiller.h"
13#include "base/AsyncCall.h"
14#include "base/forward.h"
15#include "dlink.h"
16#include "store/ParsingBuffer.h"
17#include "StoreIOBuffer.h"
18#include "StoreIOState.h"
19
32using STCB = void (void *, StoreIOBuffer);
33
34class StoreEntry;
36class LogTags;
37
38// TODO: Merge store_client into StoreClient.
41{
42
43public:
44 ~StoreClient () override {}
45
47 virtual LogTags *loggingTags() const = 0;
48
49protected:
53 bool startCollapsingOn(const StoreEntry &, const bool doingRevalidation) const;
54
55 // These methods only interpret Squid configuration. Their allowances are
56 // provisional -- other factors may prevent collapsed forwarding. The first
57 // two exist primarily to distinguish two major CF cases in callers code.
59 bool mayInitiateCollapsing() const { return onCollapsingPath(); }
61 bool onCollapsingPath() const;
62
64 mutable bool didCollapse = false;
65};
66
67#if USE_DELAY_POOLS
68#include "DelayId.h"
69#endif
70
71/* keep track each client receiving data from that particular StoreEntry */
72
74{
76
77public:
78 explicit store_client(StoreEntry *);
80
82 auto discardableHttpEnd() const { return discardableHttpEnd_; }
83
84 int getType() const;
85
89 void noteSwapInDone(bool error);
90
91 void doCopy (StoreEntry *e);
92 void readHeader(const char *buf, ssize_t len);
93 void readBody(const char *buf, ssize_t len);
94
97 void copy(StoreEntry *, StoreIOBuffer, STCB *, void *);
98
99 void dumpStats(MemBuf * output, int clientNumber) const;
100
101 // TODO: When STCB gets a dedicated Answer type, move this info there.
106 bool atEof() const { return atEof_; }
107
108#if STORE_CLIENT_LIST_DEBUG
109
110 void *owner;
111#endif
112
113 StoreEntry *entry; /* ptr to the parent StoreEntry, argh! */
115
116 struct {
119 // TODO: a better name reflecting the 'in' scope of the flag
121
126
127#if USE_DELAY_POOLS
129
134 int bytesWanted() const;
135
136 void setDelayId(DelayId delay_id);
137#endif
138
140
141private:
142 bool moreToRead() const;
143 bool canReadFromMemory() const;
144 bool answeredOnce() const { return answers >= 1; }
145 bool sendingHttpHeaders() const;
146 int64_t nextHttpReadOffset() const;
147
148 void fileRead();
149 void scheduleDiskRead();
150 void readFromMemory();
152 bool startSwapin();
153 void handleBodyFromDisk();
155
159
160 void fail();
161 void callback(ssize_t);
162 void noteCopiedBytes(size_t);
163 void noteNews();
164 void finishCallback();
165 static void FinishCallback(store_client *);
166
167 int type;
169
171 bool atEof_;
172
180
181 // TODO: Convert to uint64_t after fixing mem_hdr::endOffset() and friends.
184
186 uint64_t answers;
187
192 std::optional<Store::ParsingBuffer> parsingBuffer;
193
195
196 /* Until we finish stuffing code into store_client */
197
198public:
199
217};
218
230
232int storeUnregister(store_client * sc, StoreEntry * e, void *data);
233int storePendingNClients(const StoreEntry * e);
234int storeClientIsThisAClient(store_client * sc, void *someClient);
235
236#endif /* SQUID_SRC_STORECLIENT_H */
237
int storeUnregister(store_client *sc, StoreEntry *e, void *data)
void(void *, StoreIOBuffer) STCB
Definition StoreClient.h:32
int storeClientIsThisAClient(store_client *sc, void *someClient)
int storePendingNClients(const StoreEntry *e)
void storeClientCopy(store_client *, StoreEntry *, StoreIOBuffer, STCB *, void *)
store_client * storeClientListAdd(StoreEntry *e, void *data)
void error(char *format,...)
#define CBDATA_CLASS(type)
Definition cbdata.h:289
an interface for those capable of configuring an ACLFilledChecklist object
an old-style void* callback parameter
Definition cbdata.h:384
a storeGetPublic*() caller
Definition StoreClient.h:41
bool onCollapsingPath() const
whether Squid configuration allows collapsing for this transaction
bool didCollapse
whether startCollapsingOn() was called and returned true
Definition StoreClient.h:64
virtual LogTags * loggingTags() const =0
bool mayInitiateCollapsing() const
whether Squid configuration allows us to become a CF initiator
Definition StoreClient.h:59
bool startCollapsingOn(const StoreEntry &, const bool doingRevalidation) const
~StoreClient() override
Definition StoreClient.h:44
int getType() const
bool sendingHttpHeaders() const
void readHeader(const char *buf, ssize_t len)
void skipHttpHeadersFromDisk()
skips HTTP header bytes previously loaded from disk
void handleBodyFromDisk()
de-serializes HTTP response (partially) read from disk storage
void setDelayId(DelayId delay_id)
std::optional< Store::ParsingBuffer > parsingBuffer
void scheduleDiskRead()
bool startSwapin()
opens the swapin "file" if possible; otherwise, fail()s and returns false
bool answeredOnce() const
void noteNews()
if necessary and possible, informs the Store reader about copy() result
bool parseHttpHeadersFromDisk()
void readFromMemory()
bool moreToRead() const
Whether Store has (or possibly will have) more entry data for us.
void noteSwapInDone(bool error)
int64_t discardableHttpEnd_
the client will not use HTTP response bytes with lower offsets (if any)
void scheduleRead()
StoreIOBuffer lastDiskRead
buffer used for the last storeRead() call
auto discardableHttpEnd() const
the client will not use HTTP response bytes with lower offsets (if any)
Definition StoreClient.h:82
void readBody(const char *buf, ssize_t len)
DelayId delayId
int64_t nextHttpReadOffset() const
The offset of the next stored HTTP response byte wanted by the client.
StoreEntry * entry
struct store_client::@122 flags
void copy(StoreEntry *, StoreIOBuffer, STCB *, void *)
int bytesWanted() const
bool tryParsingHttpHeaders()
void doCopy(StoreEntry *e)
void noteCopiedBytes(size_t)
void maybeWriteFromDiskToMemory(const StoreIOBuffer &)
bool canReadFromMemory() const
whether at least one byte wanted by the client is in memory
struct store_client::Callback _callback
StoreIOBuffer copyInto
bool atEof() const
void finishCallback()
finishes a copy()-STCB sequence by synchronously calling STCB
bool disk_io_pending
static void FinishCallback(store_client *)
finishCallback() wrapper; TODO: Add NullaryMemFunT for non-jobs.
dlink_node node
uint64_t answers
the total number of finishCallback() calls
StoreIOState::Pointer swapin_sio
void dumpStats(MemBuf *output, int clientNumber) const
void callback(ssize_t)
CodeContextPointer codeContext
Store client context.
CallbackData cbData
the first STCB callback parameter
STCB * callback_handler
where to deliver the answer
AsyncCall::Pointer notifier
a scheduled asynchronous finishCallback() call (or nil)