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