]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/ufs/UFSStoreState.h
Merged from trunk r12948.
[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 UFSStoreState(SwapDir * SD, StoreEntry * anEntry, STIOCB * callback_, void *callback_data_);
46 ~UFSStoreState();
47 virtual void close(int how);
48 virtual void closeCompleted();
49 // protected:
50 virtual void ioCompletedNotification();
51 virtual void readCompleted(const char *buf, int len, int errflag, RefCount<ReadRequest>);
52 virtual void writeCompleted(int errflag, size_t len, RefCount<WriteRequest>);
53 RefCount<DiskFile> theFile;
54 bool opening;
55 bool creating;
56 bool closing;
57 bool reading;
58 bool writing;
59 /* StoreIOState API */
60 void read_(char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data);
61 virtual bool write(char const *buf, size_t size, off_t offset, FREE * free_func);
62
63 protected:
64 virtual void doCloseCallback (int errflag);
65
66 class _queued_read
67 {
68 public:
69 MEMPROXY_CLASS(UFSStoreState::_queued_read);
70 char *buf;
71 size_t size;
72 off_t offset;
73 STRCB *callback;
74 void *callback_data;
75
76 };
77
78 class _queued_write
79 {
80 public:
81 MEMPROXY_CLASS(UFSStoreState::_queued_write);
82 char const *buf;
83 size_t size;
84 off_t offset;
85 FREE *free_func;
86
87 };
88
89 /** \todo These should be in the IO strategy */
90
91 struct {
92 /**
93 * DPW 2006-05-24
94 * the write_draining flag is used to avoid recursion inside
95 * the UFSStoreState::drainWriteQueue() method.
96 */
97 bool write_draining;
98 /**
99 * DPW 2006-05-24
100 * The try_closing flag is set by UFSStoreState::tryClosing()
101 * when UFSStoreState wants to close the file, but cannot
102 * because of pending I/Os. If set, UFSStoreState will
103 * try to close again in the I/O callbacks.
104 */
105 bool try_closing;
106 } flags;
107 link_list *pending_reads;
108 link_list *pending_writes;
109 void queueRead(char *, size_t, off_t, STRCB *, void *);
110 void queueWrite(char const *, size_t, off_t, FREE *);
111 bool kickReadQueue();
112 void drainWriteQueue();
113 void tryClosing();
114 char *read_buf;
115
116 private:
117 void openDone();
118 void freePending();
119 void doWrite();
120 CBDATA_CLASS2(UFSStoreState);
121 };
122
123 MEMPROXY_CLASS_INLINE(UFSStoreState::_queued_read);
124 MEMPROXY_CLASS_INLINE(UFSStoreState::_queued_write);
125
126 } //namespace Ufs
127 } //namespace Fs
128
129 #endif /* SQUID_FS_UFS_UFSSTORESTATE_H */