]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/ufs/UFSStoreState.h
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / fs / ufs / UFSStoreState.h
1 /*
2 * Copyright (C) 1996-2014 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_FS_UFS_UFSSTORESTATE_H
10 #define SQUID_FS_UFS_UFSSTORESTATE_H
11
12 #include "DiskIO/IORequestor.h"
13 #include "SquidList.h"
14 #include "StoreIOState.h"
15
16 namespace Fs
17 {
18 namespace Ufs
19 {
20 /// \ingroup UFS
21 class UFSStoreState : public StoreIOState, public IORequestor
22 {
23 public:
24 UFSStoreState(SwapDir * SD, StoreEntry * anEntry, STIOCB * callback_, void *callback_data_);
25 ~UFSStoreState();
26 virtual void close(int how);
27 virtual void closeCompleted();
28 // protected:
29 virtual void ioCompletedNotification();
30 virtual void readCompleted(const char *buf, int len, int errflag, RefCount<ReadRequest>);
31 virtual void writeCompleted(int errflag, size_t len, RefCount<WriteRequest>);
32 RefCount<DiskFile> theFile;
33 bool opening;
34 bool creating;
35 bool closing;
36 bool reading;
37 bool writing;
38 /* StoreIOState API */
39 void read_(char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data);
40 virtual bool write(char const *buf, size_t size, off_t offset, FREE * free_func);
41
42 protected:
43 virtual void doCloseCallback (int errflag);
44
45 class _queued_read
46 {
47 public:
48 MEMPROXY_CLASS(UFSStoreState::_queued_read);
49 char *buf;
50 size_t size;
51 off_t offset;
52 STRCB *callback;
53 void *callback_data;
54
55 };
56
57 class _queued_write
58 {
59 public:
60 MEMPROXY_CLASS(UFSStoreState::_queued_write);
61 char const *buf;
62 size_t size;
63 off_t offset;
64 FREE *free_func;
65
66 };
67
68 /** \todo These should be in the IO strategy */
69
70 struct {
71 /**
72 * DPW 2006-05-24
73 * the write_draining flag is used to avoid recursion inside
74 * the UFSStoreState::drainWriteQueue() method.
75 */
76 bool write_draining;
77 /**
78 * DPW 2006-05-24
79 * The try_closing flag is set by UFSStoreState::tryClosing()
80 * when UFSStoreState wants to close the file, but cannot
81 * because of pending I/Os. If set, UFSStoreState will
82 * try to close again in the I/O callbacks.
83 */
84 bool try_closing;
85 } flags;
86 link_list *pending_reads;
87 link_list *pending_writes;
88 void queueRead(char *, size_t, off_t, STRCB *, void *);
89 void queueWrite(char const *, size_t, off_t, FREE *);
90 bool kickReadQueue();
91 void drainWriteQueue();
92 void tryClosing();
93 char *read_buf;
94
95 private:
96 void openDone();
97 void freePending();
98 void doWrite();
99 CBDATA_CLASS2(UFSStoreState);
100 };
101
102 MEMPROXY_CLASS_INLINE(UFSStoreState::_queued_read);
103 MEMPROXY_CLASS_INLINE(UFSStoreState::_queued_write);
104
105 } //namespace Ufs
106 } //namespace Fs
107
108 #endif /* SQUID_FS_UFS_UFSSTORESTATE_H */