StoreClient.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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_STORECLIENT_H
10#define SQUID_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
40{
41
42public:
43 ~StoreClient () override {}
44
46 virtual LogTags *loggingTags() const = 0;
47
48protected:
52 bool startCollapsingOn(const StoreEntry &, const bool doingRevalidation) const;
53
54 // These methods only interpret Squid configuration. Their allowances are
55 // provisional -- other factors may prevent collapsed forwarding. The first
56 // two exist primarily to distinguish two major CF cases in callers code.
58 bool mayInitiateCollapsing() const { return onCollapsingPath(); }
60 bool onCollapsingPath() const;
61};
62
63#if USE_DELAY_POOLS
64#include "DelayId.h"
65#endif
66
67/* keep track each client receiving data from that particular StoreEntry */
68
70{
72
73public:
74 explicit store_client(StoreEntry *);
76
83 // TODO: Callers do not expect negative offset. Verify that the return
84 // value cannot be negative and convert to unsigned in this case.
85 int64_t readOffset() const { return copyInto.offset; }
86
87 int getType() const;
88
92 void noteSwapInDone(bool error);
93
94 void doCopy (StoreEntry *e);
95 void readHeader(const char *buf, ssize_t len);
96 void readBody(const char *buf, ssize_t len);
97
100 void copy(StoreEntry *, StoreIOBuffer, STCB *, void *);
101
102 void dumpStats(MemBuf * output, int clientNumber) const;
103
104 // TODO: When STCB gets a dedicated Answer type, move this info there.
109 bool atEof() const { return atEof_; }
110
111#if STORE_CLIENT_LIST_DEBUG
112
113 void *owner;
114#endif
115
116 StoreEntry *entry; /* ptr to the parent StoreEntry, argh! */
118
119 struct {
122 // TODO: a better name reflecting the 'in' scope of the flag
124
129
130#if USE_DELAY_POOLS
132
137 int bytesWanted() const;
138
139 void setDelayId(DelayId delay_id);
140#endif
141
143
144private:
145 bool moreToRead() const;
146 bool canReadFromMemory() const;
147 bool answeredOnce() const { return answers >= 1; }
148 bool sendingHttpHeaders() const;
149 int64_t nextHttpReadOffset() const;
150
151 void fileRead();
152 void scheduleDiskRead();
153 void readFromMemory();
155 bool startSwapin();
156 void handleBodyFromDisk();
158
162
163 void fail();
164 void callback(ssize_t);
165 void noteCopiedBytes(size_t);
166 void noteNews();
167 void finishCallback();
168 static void FinishCallback(store_client *);
169
170 int type;
172
174 bool atEof_;
175
179
181 uint64_t answers;
182
187 std::optional<Store::ParsingBuffer> parsingBuffer;
188
190
191 /* Until we finish stuffing code into store_client */
192
193public:
194
195 struct Callback {
196 Callback() = default;
197
198 Callback (STCB *, void *);
199
203 bool pending() const;
204
208
212};
213
225
227int storeUnregister(store_client * sc, StoreEntry * e, void *data);
228int storePendingNClients(const StoreEntry * e);
229int storeClientIsThisAClient(store_client * sc, void *someClient);
230
231#endif /* SQUID_STORECLIENT_H */
232
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:379
Definition: MemBuf.h:24
a storeGetPublic*() caller
Definition: StoreClient.h:40
bool onCollapsingPath() const
whether Squid configuration allows collapsing for this transaction
Definition: store_client.cc:52
virtual LogTags * loggingTags() const =0
bool mayInitiateCollapsing() const
whether Squid configuration allows us to become a CF initiator
Definition: StoreClient.h:58
bool startCollapsingOn(const StoreEntry &, const bool doingRevalidation) const
Definition: store_client.cc:66
~StoreClient() override
Definition: StoreClient.h:43
int64_t offset
Definition: StoreIOBuffer.h:58
int getType() const
Definition: store_client.cc:90
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)
struct store_client::@140 flags
std::optional< Store::ParsingBuffer > parsingBuffer
Definition: StoreClient.h:187
void scheduleDiskRead()
bool startSwapin()
opens the swapin "file" if possible; otherwise, fail()s and returns false
bool answeredOnce() const
Definition: StoreClient.h:147
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)
void scheduleRead()
StoreIOBuffer lastDiskRead
buffer used for the last storeRead() call
Definition: StoreClient.h:189
void readBody(const char *buf, ssize_t len)
DelayId delayId
Definition: StoreClient.h:131
int64_t nextHttpReadOffset() const
The offset of the next stored HTTP response byte wanted by the client.
StoreEntry * entry
Definition: StoreClient.h:116
void copy(StoreEntry *, StoreIOBuffer, STCB *, void *)
int bytesWanted() const
bool tryParsingHttpHeaders()
void doCopy(StoreEntry *e)
void noteCopiedBytes(size_t)
bool store_copying
Definition: StoreClient.h:127
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
Definition: StoreClient.h:178
bool atEof() const
Definition: StoreClient.h:109
void finishCallback()
finishes a copy()-STCB sequence by synchronously calling STCB
bool disk_io_pending
Definition: StoreClient.h:123
store_client(StoreEntry *)
static void FinishCallback(store_client *)
finishCallback() wrapper; TODO: Add NullaryMemFunT for non-jobs.
dlink_node node
Definition: StoreClient.h:142
int64_t readOffset() const
Definition: StoreClient.h:85
uint64_t answers
the total number of finishCallback() calls
Definition: StoreClient.h:181
StoreIOState::Pointer swapin_sio
Definition: StoreClient.h:117
void dumpStats(MemBuf *output, int clientNumber) const
void callback(ssize_t)
static int sc[16]
Definition: smbdes.c:121
CodeContextPointer codeContext
Store client context.
Definition: StoreClient.h:207
CallbackData cbData
the first STCB callback parameter
Definition: StoreClient.h:206
STCB * callback_handler
where to deliver the answer
Definition: StoreClient.h:205
AsyncCall::Pointer notifier
a scheduled asynchronous finishCallback() call (or nil)
Definition: StoreClient.h:210

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors