]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/DiskIO/Blocking/BlockingFile.cc
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 47 Store Directory Routines */
12 #include "BlockingFile.h"
15 #include "DiskIO/IORequestor.h"
16 #include "DiskIO/ReadRequest.h"
17 #include "DiskIO/WriteRequest.h"
23 CBDATA_CLASS_INIT(BlockingFile
);
25 BlockingFile::BlockingFile(char const *aPath
) : fd(-1), closed(true), error_(false)
28 debugs(79, 3, "BlockingFile::BlockingFile: " << aPath
);
29 path_
= xstrdup(aPath
);
32 BlockingFile::~BlockingFile()
39 BlockingFile::open(int flags
, mode_t
, RefCount
<IORequestor
> callback
)
41 /* Simulate async calls */
42 fd
= file_open(path_
, flags
);
43 ioRequestor
= callback
;
46 debugs(79, 3, "BlockingFile::open: got failure (" << errno
<< ")");
51 debugs(79, 3, "BlockingFile::open: opened FD " << fd
);
54 callback
->ioCompletedNotification();
58 * Alias for BlockingFile::open(...)
59 \copydoc BlockingFile::open(int flags, mode_t mode, RefCount<IORequestor> callback)
62 BlockingFile::create(int flags
, mode_t mode
, RefCount
<IORequestor
> callback
)
64 /* We use the same logic path for open */
65 open(flags
, mode
, callback
);
68 void BlockingFile::doClose()
81 debugs(79, 3, "BlockingFile::close: " << this << " closing for " << ioRequestor
.getRaw());
83 assert (ioRequestor
.getRaw());
84 ioRequestor
->closeCompleted();
88 BlockingFile::canRead() const
94 BlockingFile::error() const
96 if ((fd
< 0 && !closed
) || error_
)
102 void BlockingFile::error(bool const &aBool
)
108 BlockingFile::read(ReadRequest
*aRequest
)
111 assert (ioRequestor
.getRaw());
112 readRequest
= aRequest
;
113 debugs(79, 3, HERE
<< aRequest
->len
<< " for FD " << fd
<< " at " << aRequest
->offset
);
114 file_read(fd
, aRequest
->buf
, aRequest
->len
, aRequest
->offset
, ReadDone
, this);
118 BlockingFile::ReadDone(int fd
, const char *buf
, int len
, int errflag
, void *my_data
)
120 BlockingFile
*myFile
= static_cast<BlockingFile
*>(my_data
);
122 myFile
->readDone (fd
, buf
, len
, errflag
);
126 BlockingFile::write(WriteRequest
*aRequest
)
128 debugs(79, 3, HERE
<< aRequest
->len
<< " for FD " << fd
<< " at " << aRequest
->offset
);
129 writeRequest
= aRequest
;
132 (char *)aRequest
->buf
,
136 aRequest
->free_func
);
140 BlockingFile::ioInProgress() const
142 /** \retval false IO is never pending with UFS */
146 /* === STATIC =========================================================== */
149 BlockingFile::readDone(int rvfd
, const char *buf
, int len
, int errflag
)
151 debugs(79, 3, "BlockingFile::readDone: FD " << rvfd
);
157 debugs(79, 3, "BlockingFile::readDone: got failure (" << errflag
<< ")");
160 rlen
= (ssize_t
) len
;
163 if (errflag
== DISK_EOF
)
164 errflag
= DISK_OK
; /* EOF is signalled by len == 0, not errors... */
166 ReadRequest::Pointer result
= readRequest
;
170 ioRequestor
->readCompleted(buf
, rlen
, errflag
, result
);
174 BlockingFile::WriteDone (int fd
, int errflag
, size_t len
, void *me
)
176 BlockingFile
*aFile
= static_cast<BlockingFile
*>(me
);
177 aFile
->writeDone (fd
, errflag
, len
);
181 BlockingFile::writeDone(int rvfd
, int errflag
, size_t len
)
184 debugs(79, 3, HERE
<< "FD " << fd
<< ", len " << len
);
186 WriteRequest::Pointer result
= writeRequest
;
190 debugs(79, DBG_CRITICAL
, "storeUfsWriteDone: got failure (" << errflag
<< ")");
192 ioRequestor
->writeCompleted (DISK_ERROR
,0, result
);
196 ioRequestor
->writeCompleted(DISK_OK
, len
, result
);