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