]> git.ipfire.org Git - thirdparty/squid.git/blob - src/StoreClient.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / StoreClient.h
1 /*
2 * Copyright (C) 1996-2015 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 "dlink.h"
13 #include "StoreIOBuffer.h"
14 #include "StoreIOState.h"
15
16 typedef void STCB(void *, StoreIOBuffer); /* store callback */
17
18 class StoreEntry;
19
20 class StoreClient
21 {
22
23 public:
24 virtual ~StoreClient () {}
25
26 virtual void created (StoreEntry *newEntry) = 0;
27 };
28
29 #if USE_DELAY_POOLS
30 #include "DelayId.h"
31 #endif
32
33 /* keep track each client receiving data from that particular StoreEntry */
34
35 class store_client
36 {
37 CBDATA_CLASS(store_client);
38
39 public:
40 store_client(StoreEntry *);
41 ~store_client();
42 bool memReaderHasLowerOffset(int64_t) const;
43 int getType() const;
44 void fail();
45 void callback(ssize_t len, bool error = false);
46 void doCopy (StoreEntry *e);
47 void readHeader(const char *buf, ssize_t len);
48 void readBody(const char *buf, ssize_t len);
49 void copy(StoreEntry *, StoreIOBuffer, STCB *, void *);
50 void dumpStats(MemBuf * output, int clientNumber) const;
51
52 int64_t cmp_offset;
53 #if STORE_CLIENT_LIST_DEBUG
54
55 void *owner;
56 #endif
57
58 StoreEntry *entry; /* ptr to the parent StoreEntry, argh! */
59 StoreIOState::Pointer swapin_sio;
60
61 struct {
62 bool disk_io_pending;
63 bool store_copying;
64 bool copy_event_pending;
65 } flags;
66
67 #if USE_DELAY_POOLS
68 DelayId delayId;
69 void setDelayId(DelayId delay_id);
70 #endif
71
72 dlink_node node;
73 /* Below here is private - do no alter outside storeClient calls */
74 StoreIOBuffer copyInto;
75
76 private:
77 bool moreToSend() const;
78
79 void fileRead();
80 void scheduleDiskRead();
81 void scheduleMemRead();
82 void scheduleRead();
83 bool startSwapin();
84 void unpackHeader(char const *buf, ssize_t len);
85
86 int type;
87 bool object_ok;
88
89 /* Until we finish stuffing code into store_client */
90
91 public:
92
93 struct Callback {
94 Callback ():callback_handler(NULL), callback_data(NULL) {}
95
96 Callback (STCB *, void *);
97 bool pending() const;
98 STCB *callback_handler;
99 void *callback_data;
100 } _callback;
101 };
102
103 void storeClientCopy(store_client *, StoreEntry *, StoreIOBuffer, STCB *, void *);
104 store_client* storeClientListAdd(StoreEntry * e, void *data);
105 int storeClientCopyPending(store_client *, StoreEntry * e, void *data);
106 int storeUnregister(store_client * sc, StoreEntry * e, void *data);
107 int storePendingNClients(const StoreEntry * e);
108 int storeClientIsThisAClient(store_client * sc, void *someClient);
109
110 #endif /* SQUID_STORECLIENT_H */
111