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_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 
32 using STCB = void (void *, StoreIOBuffer);
33 
34 class StoreEntry;
35 class ACLFilledChecklist;
36 class LogTags;
37 
38 // TODO: Merge store_client into StoreClient.
41 {
42 
43 public:
44  ~StoreClient () override {}
45 
47  virtual LogTags *loggingTags() const = 0;
48 
49 protected:
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 
77 public:
78  explicit store_client(StoreEntry *);
79  ~store_client();
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 
125  } flags;
126 
127 #if USE_DELAY_POOLS
129 
134  int bytesWanted() const;
135 
136  void setDelayId(DelayId delay_id);
137 #endif
138 
140 
141 private:
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();
151  void scheduleRead();
152  bool startSwapin();
153  void handleBodyFromDisk();
155 
157  bool tryParsingHttpHeaders();
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;
168  bool object_ok;
169 
171  bool atEof_;
172 
180 
181  // TODO: Convert to uint64_t after fixing mem_hdr::endOffset() and friends.
183  int64_t discardableHttpEnd_ = 0;
184 
186  uint64_t answers;
187 
192  std::optional<Store::ParsingBuffer> parsingBuffer;
193 
195 
196  /* Until we finish stuffing code into store_client */
197 
198 public:
199 
200  struct Callback {
201  Callback() = default;
202 
203  Callback (STCB *, void *);
204 
208  bool pending() const;
209 
210  STCB *callback_handler = nullptr;
213 
216  } _callback;
217 };
218 
230 
231 store_client* storeClientListAdd(StoreEntry * e, void *data);
232 int storeUnregister(store_client * sc, StoreEntry * e, void *data);
233 int storePendingNClients(const StoreEntry * e);
234 int storeClientIsThisAClient(store_client * sc, void *someClient);
235 
236 #endif /* SQUID_SRC_STORECLIENT_H */
237 
an old-style void* callback parameter
Definition: cbdata.h:383
static void FinishCallback(store_client *)
finishCallback() wrapper; TODO: Add NullaryMemFunT for non-jobs.
struct store_client::Callback _callback
int storeClientIsThisAClient(store_client *sc, void *someClient)
bool tryParsingHttpHeaders()
StoreEntry * entry
Definition: StoreClient.h:113
STCB * callback_handler
where to deliver the answer
Definition: StoreClient.h:210
void readFromMemory()
void maybeWriteFromDiskToMemory(const StoreIOBuffer &)
void readHeader(const char *buf, ssize_t len)
void noteSwapInDone(bool error)
void noteNews()
if necessary and possible, informs the Store reader about copy() result
void callback(ssize_t)
bool disk_io_pending
Definition: StoreClient.h:120
~StoreClient() override
Definition: StoreClient.h:44
bool canReadFromMemory() const
whether at least one byte wanted by the client is in memory
void error(char *format,...)
#define CBDATA_CLASS(type)
Definition: cbdata.h:289
int storePendingNClients(const StoreEntry *e)
void noteCopiedBytes(size_t)
bool store_copying
Definition: StoreClient.h:124
void storeClientCopy(store_client *, StoreEntry *, StoreIOBuffer, STCB *, void *)
AsyncCall::Pointer notifier
a scheduled asynchronous finishCallback() call (or nil)
Definition: StoreClient.h:215
void skipHttpHeadersFromDisk()
skips HTTP header bytes previously loaded from disk
a storeGetPublic*() caller
Definition: StoreClient.h:40
int64_t nextHttpReadOffset() const
The offset of the next stored HTTP response byte wanted by the client.
void scheduleDiskRead()
CodeContextPointer codeContext
Store client context.
Definition: StoreClient.h:212
store_client(StoreEntry *)
bool mayInitiateCollapsing() const
whether Squid configuration allows us to become a CF initiator
Definition: StoreClient.h:59
int storeUnregister(store_client *sc, StoreEntry *e, void *data)
Definition: MemBuf.h:23
bool onCollapsingPath() const
whether Squid configuration allows collapsing for this transaction
Definition: store_client.cc:52
void readBody(const char *buf, ssize_t len)
virtual LogTags * loggingTags() const =0
StoreIOBuffer lastDiskRead
buffer used for the last storeRead() call
Definition: StoreClient.h:194
bool parseHttpHeadersFromDisk()
int bytesWanted() const
static int sc[16]
Definition: smbdes.c:121
store_client * storeClientListAdd(StoreEntry *e, void *data)
bool startCollapsingOn(const StoreEntry &, const bool doingRevalidation) const
Definition: store_client.cc:66
DelayId delayId
Definition: StoreClient.h:128
StoreIOBuffer copyInto
Definition: StoreClient.h:179
int64_t discardableHttpEnd_
the client will not use HTTP response bytes with lower offsets (if any)
Definition: StoreClient.h:183
bool didCollapse
whether startCollapsingOn() was called and returned true
Definition: StoreClient.h:64
StoreIOState::Pointer swapin_sio
Definition: StoreClient.h:114
int getType() const
Definition: store_client.cc:91
bool sendingHttpHeaders() const
std::optional< Store::ParsingBuffer > parsingBuffer
Definition: StoreClient.h:192
dlink_node node
Definition: StoreClient.h:139
auto discardableHttpEnd() const
the client will not use HTTP response bytes with lower offsets (if any)
Definition: StoreClient.h:82
void dumpStats(MemBuf *output, int clientNumber) const
struct store_client::@129 flags
bool answeredOnce() const
Definition: StoreClient.h:144
void copy(StoreEntry *, StoreIOBuffer, STCB *, void *)
bool moreToRead() const
Whether Store has (or possibly will have) more entry data for us.
bool atEof() const
Definition: StoreClient.h:106
bool startSwapin()
opens the swapin "file" if possible; otherwise, fail()s and returns false
CallbackData cbData
the first STCB callback parameter
Definition: StoreClient.h:211
void(void *, StoreIOBuffer) STCB
Definition: StoreClient.h:32
void setDelayId(DelayId delay_id)
void doCopy(StoreEntry *e)
void finishCallback()
finishes a copy()-STCB sequence by synchronously calling STCB
void handleBodyFromDisk()
de-serializes HTTP response (partially) read from disk storage
an interface for those capable of configuring an ACLFilledChecklist object
void scheduleRead()
uint64_t answers
the total number of finishCallback() calls
Definition: StoreClient.h:186

 

Introduction

Documentation

Support

Miscellaneous