]> git.ipfire.org Git - thirdparty/squid.git/blob - src/StoreIOState.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / StoreIOState.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_STOREIOSTATE_H
10 #define SQUID_STOREIOSTATE_H
11
12 #include "base/RefCount.h"
13 #include "cbdata.h"
14
15 class StoreIOState : public RefCountable
16 {
17
18 public:
19 typedef RefCount<StoreIOState> Pointer;
20
21 /*
22 * STRCB is the "store read callback". STRCB functions are
23 * passed to storeRead(). Examples of STRCB callbacks are:
24 * storeClientReadBody
25 * storeClientReadHeader
26 */
27 typedef void STRCB(void *their_data, const char *buf, ssize_t len, StoreIOState::Pointer self);
28
29 /*
30 * STFNCB is the "store file number callback." It is called
31 * when an underlying storage module has allocated the swap
32 * file number and also indicates that the swap file has been
33 * opened for reading or writing. STFNCB functions are passed
34 * to storeCreate() and storeOpen(). Examples of STFNCB callbacks
35 * are:
36 * storeSwapInFileNotify
37 * storeSwapOutFileNotify
38 */
39 typedef void STFNCB(void *their_data, int errflag, StoreIOState::Pointer self);
40
41 /*
42 * STIOCB is the "store close callback" for store files. It
43 * is called when the store file is closed. STIOCB functions
44 * are passed to storeCreate() and storeOpen(). Examples of
45 * STIOCB callbacks are:
46 * storeSwapOutFileClosed
47 * storeSwapInFileClosed
48 */
49 typedef void STIOCB(void *their_data, int errflag, StoreIOState::Pointer self);
50
51 /* StoreIOState does not get mempooled - it's children do */
52 void *operator new (size_t amount);
53 void operator delete (void *address);
54 virtual ~StoreIOState();
55
56 StoreIOState();
57
58 off_t offset() const;
59
60 virtual void read_(char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data) = 0;
61 /** write the given buffer and free it when it is no longer needed
62 * \param offset zero for the very first write and -1 for all other writes
63 * \retval false if write failed (callback has been or will be called)
64 */
65 virtual bool write(char const *buf, size_t size, off_t offset, FREE * free_func) = 0;
66
67 typedef enum {
68 wroteAll, ///< success: caller supplied all data it wanted to swap out
69 writerGone, ///< failure: caller left before swapping out everything
70 readerDone ///< success or failure: either way, stop swapping in
71 } CloseHow;
72 virtual void close(int how) = 0; ///< finish or abort swapping per CloseHow
73
74 sdirno swap_dirn;
75 sfileno swap_filen;
76 StoreEntry *e; /* Need this so the FS layers can play god */
77 mode_t mode;
78 off_t offset_; ///< number of bytes written or read for this entry so far
79 STFNCB *file_callback; /* called on delayed sfileno assignments */
80 STIOCB *callback;
81 void *callback_data;
82
83 struct {
84 STRCB *callback;
85 void *callback_data;
86 } read;
87
88 struct {
89 bool closing; /* debugging aid */
90 } flags;
91 };
92
93 StoreIOState::Pointer storeCreate(StoreEntry *, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
94 StoreIOState::Pointer storeOpen(StoreEntry *, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
95 void storeClose(StoreIOState::Pointer, int how);
96 void storeRead(StoreIOState::Pointer, char *, size_t, off_t, StoreIOState::STRCB *, void *);
97 void storeIOWrite(StoreIOState::Pointer, char const *, size_t, off_t, FREE *);
98
99 #endif /* SQUID_STOREIOSTATE_H */
100