]> git.ipfire.org Git - thirdparty/squid.git/blob - src/StoreIOState.h
Polish: update the RefCount API a bt and split Lock out
[thirdparty/squid.git] / src / StoreIOState.h
1
2 /*
3 *
4 * SQUID Web Proxy Cache http://www.squid-cache.org/
5 * ----------------------------------------------------------
6 *
7 * Squid is the result of efforts by numerous individuals from
8 * the Internet community; see the CONTRIBUTORS file for full
9 * details. Many organizations have provided support for Squid's
10 * development; see the SPONSORS file for full details. Squid is
11 * Copyrighted (C) 2001 by the Regents of the University of
12 * California; see the COPYRIGHT file for full details. Squid
13 * incorporates software developed and/or copyrighted by other
14 * sources; see the CREDITS file for full details.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
29 *
30 */
31
32 #ifndef SQUID_STOREIOSTATE_H
33 #define SQUID_STOREIOSTATE_H
34
35 #include "base/RefCount.h"
36 #include "cbdata.h"
37
38 class StoreIOState : public RefCountable
39 {
40
41 public:
42 typedef RefCount<StoreIOState> Pointer;
43
44 /*
45 * STRCB is the "store read callback". STRCB functions are
46 * passed to storeRead(). Examples of STRCB callbacks are:
47 * storeClientReadBody
48 * storeClientReadHeader
49 */
50 typedef void STRCB(void *their_data, const char *buf, ssize_t len, StoreIOState::Pointer self);
51
52 /*
53 * STFNCB is the "store file number callback." It is called
54 * when an underlying storage module has allocated the swap
55 * file number and also indicates that the swap file has been
56 * opened for reading or writing. STFNCB functions are passed
57 * to storeCreate() and storeOpen(). Examples of STFNCB callbacks
58 * are:
59 * storeSwapInFileNotify
60 * storeSwapOutFileNotify
61 */
62 typedef void STFNCB(void *their_data, int errflag, StoreIOState::Pointer self);
63
64 /*
65 * STIOCB is the "store close callback" for store files. It
66 * is called when the store file is closed. STIOCB functions
67 * are passed to storeCreate() and storeOpen(). Examples of
68 * STIOCB callbacks are:
69 * storeSwapOutFileClosed
70 * storeSwapInFileClosed
71 */
72 typedef void STIOCB(void *their_data, int errflag, StoreIOState::Pointer self);
73
74 /* StoreIOState does not get mempooled - it's children do */
75 void *operator new (size_t amount);
76 void operator delete (void *address);
77 virtual ~StoreIOState();
78
79 StoreIOState();
80
81 off_t offset() const;
82
83 virtual void read_(char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data) = 0;
84 virtual void write(char const *buf, size_t size, off_t offset, FREE * free_func) = 0;
85
86 typedef enum {
87 wroteAll, ///< success: caller supplied all data it wanted to swap out
88 writerGone, ///< failure: caller left before swapping out everything
89 readerDone ///< success or failure: either way, stop swapping in
90 } CloseHow;
91 virtual void close(int how) = 0; ///< finish or abort swapping per CloseHow
92
93 sdirno swap_dirn;
94 sfileno swap_filen;
95 StoreEntry *e; /* Need this so the FS layers can play god */
96 mode_t mode;
97 off_t offset_; ///< number of bytes written or read for this entry so far
98 STFNCB *file_callback; /* called on delayed sfileno assignments */
99 STIOCB *callback;
100 void *callback_data;
101
102 struct {
103 STRCB *callback;
104 void *callback_data;
105 } read;
106
107 struct {
108 unsigned int closing:1; /* debugging aid */
109 } flags;
110 };
111
112 StoreIOState::Pointer storeCreate(StoreEntry *, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
113 StoreIOState::Pointer storeOpen(StoreEntry *, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
114 void storeClose(StoreIOState::Pointer, int how);
115 void storeRead(StoreIOState::Pointer, char *, size_t, off_t, StoreIOState::STRCB *, void *);
116 void storeIOWrite(StoreIOState::Pointer, char const *, size_t, off_t, FREE *);
117
118 #endif /* SQUID_STOREIOSTATE_H */