1 /*
2  * Copyright (C) 1996-2021 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 /* DEBUG: section 47    Store Directory Routines */
10 
11 #ifndef SQUID_BLOCKINGFILE_H
12 #define SQUID_BLOCKINGFILE_H
13 
14 #include "cbdata.h"
15 #include "DiskIO/DiskFile.h"
16 #include "DiskIO/IORequestor.h"
17 #include "typedefs.h" //DRCB, DWCB
18 
19 class BlockingFile : public DiskFile
20 {
21     CBDATA_CLASS(BlockingFile);
22 
23 public:
24     BlockingFile(char const *path);
25     ~BlockingFile();
26     virtual void open(int flags, mode_t mode, RefCount<IORequestor> callback);
27     virtual void create(int flags, mode_t mode, RefCount<IORequestor> callback);
28     virtual void read(ReadRequest *);
29     virtual void write(WriteRequest *);
30     virtual void close();
31     virtual bool error() const;
getFD()32     virtual int getFD() const { return fd;}
33 
34     virtual bool canRead() const;
35     virtual bool ioInProgress() const;
36 
37 private:
38     static DRCB ReadDone;
39     static DWCB WriteDone;
40     int fd;
41     bool closed;
42     void error (bool const &);
43     bool error_;
44     char const *path_;
45     RefCount<IORequestor> ioRequestor;
46     RefCount<ReadRequest> readRequest;
47     RefCount<WriteRequest> writeRequest;
48     void doClose();
49     void readDone(int fd, const char *buf, int len, int errflag);
50     void writeDone(int fd, int errflag, size_t len);
51 };
52 
53 #endif /* SQUID_BLOCKINGFILE_H */
54 
55