]> 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 void read_(char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data);
60 void write(char const *buf, size_t size, off_t offset, FREE * free_func);
61
62 protected:
63 virtual void doCloseCallback (int errflag);
64
65 class _queued_read
66 {
67 public:
68 MEMPROXY_CLASS(UFSStoreState::_queued_read);
69 char *buf;
70 size_t size;
71 off_t offset;
72 STRCB *callback;
73 void *callback_data;
74
75 };
76
77 class _queued_write
78 {
79 public:
80 MEMPROXY_CLASS(UFSStoreState::_queued_write);
81 char const *buf;
82 size_t size;
83 off_t offset;
84 FREE *free_func;
85
86 };
87
88 /** \todo These should be in the IO strategy */
89
90 struct {
91 /**
92 * DPW 2006-05-24
93 * the write_draining flag is used to avoid recursion inside
94 * the UFSStoreState::drainWriteQueue() method.
95 */
96 bool write_draining;
97 /**
98 * DPW 2006-05-24
99 * The try_closing flag is set by UFSStoreState::tryClosing()
100 * when UFSStoreState wants to close the file, but cannot
101 * because of pending I/Os. If set, UFSStoreState will
102 * try to close again in the I/O callbacks.
103 */
104 bool try_closing;
105 } flags;
106 link_list *pending_reads;
107 link_list *pending_writes;
108 void queueRead(char *, size_t, off_t, STRCB *, void *);
109 void queueWrite(char const *, size_t, off_t, FREE *);
110 bool kickReadQueue();
111 void drainWriteQueue();
112 void tryClosing();
113 char *read_buf;
114
115 private:
116 void openDone();
117 void freePending();
118 void doWrite();
119 CBDATA_CLASS2(UFSStoreState);
120 };
121
122 MEMPROXY_CLASS_INLINE(UFSStoreState::_queued_read);
123 MEMPROXY_CLASS_INLINE(UFSStoreState::_queued_write);
124
125 } //namespace Ufs
126 } //namespace Fs
127
128 #endif /* SQUID_FS_UFS_UFSSTORESTATE_H */