]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/ufs/UFSStoreState.h
merge from trunk r12441
[thirdparty/squid.git] / src / fs / ufs / UFSStoreState.h
1 /*
2 * SQUID Web Proxy Cache http://www.squid-cache.org/
3 * ----------------------------------------------------------
4 *
5 * Squid is the result of efforts by numerous individuals from
6 * the Internet community; see the CONTRIBUTORS file for full
7 * details. Many organizations have provided support for Squid's
8 * development; see the SPONSORS file for full details. Squid is
9 * Copyrighted (C) 2001 by the Regents of the University of
10 * California; see the COPYRIGHT file for full details. Squid
11 * incorporates software developed and/or copyrighted by other
12 * sources; see the CREDITS file for full details.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
27 *
28 */
29
30 #ifndef SQUID_FS_UFS_UFSSTORESTATE_H
31 #define SQUID_FS_UFS_UFSSTORESTATE_H
32
33 #include "DiskIO/IORequestor.h"
34 #include "SquidList.h"
35 #include "StoreIOState.h"
36
37 namespace Fs
38 {
39 namespace Ufs
40 {
41 /// \ingroup UFS
42 class UFSStoreState : public StoreIOState, public IORequestor
43 {
44 public:
45 void * operator new (size_t);
46 void operator delete (void *);
47 UFSStoreState(SwapDir * SD, StoreEntry * anEntry, STIOCB * callback_, void *callback_data_);
48 ~UFSStoreState();
49 virtual void close(int how);
50 virtual void closeCompleted();
51 // protected:
52 virtual void ioCompletedNotification();
53 virtual void readCompleted(const char *buf, int len, int errflag, RefCount<ReadRequest>);
54 virtual void writeCompleted(int errflag, size_t len, RefCount<WriteRequest>);
55 RefCount<DiskFile> theFile;
56 bool opening;
57 bool creating;
58 bool closing;
59 bool reading;
60 bool writing;
61 void read_(char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data);
62 void write(char const *buf, size_t size, off_t offset, FREE * free_func);
63
64 protected:
65 virtual void doCloseCallback (int errflag);
66
67 class _queued_read
68 {
69 public:
70 MEMPROXY_CLASS(UFSStoreState::_queued_read);
71 char *buf;
72 size_t size;
73 off_t offset;
74 STRCB *callback;
75 void *callback_data;
76
77 };
78
79 class _queued_write
80 {
81 public:
82 MEMPROXY_CLASS(UFSStoreState::_queued_write);
83 char const *buf;
84 size_t size;
85 off_t offset;
86 FREE *free_func;
87
88 };
89
90 /** \todo These should be in the IO strategy */
91
92 struct {
93 /**
94 * DPW 2006-05-24
95 * the write_draining flag is used to avoid recursion inside
96 * the UFSStoreState::drainWriteQueue() method.
97 */
98 bool write_draining;
99 /**
100 * DPW 2006-05-24
101 * The try_closing flag is set by UFSStoreState::tryClosing()
102 * when UFSStoreState wants to close the file, but cannot
103 * because of pending I/Os. If set, UFSStoreState will
104 * try to close again in the I/O callbacks.
105 */
106 bool try_closing;
107 } flags;
108 link_list *pending_reads;
109 link_list *pending_writes;
110 void queueRead(char *, size_t, off_t, STRCB *, void *);
111 void queueWrite(char const *, size_t, off_t, FREE *);
112 bool kickReadQueue();
113 void drainWriteQueue();
114 void tryClosing();
115 char *read_buf;
116
117 private:
118 void openDone();
119 void freePending();
120 void doWrite();
121 CBDATA_CLASS(UFSStoreState);
122 };
123
124 MEMPROXY_CLASS_INLINE(UFSStoreState::_queued_read);
125 MEMPROXY_CLASS_INLINE(UFSStoreState::_queued_write);
126
127 } //namespace Ufs
128 } //namespace Fs
129
130 #endif /* SQUID_FS_UFS_UFSSTORESTATE_H */