]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/DiskIO/Blocking/BlockingFile.cc
4 * DEBUG: section 47 Store Directory Routines
5 * AUTHOR: Robert Collins
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
36 #include "BlockingFile.h"
37 #include "DiskIO/IORequestor.h"
38 #include "DiskIO/ReadRequest.h"
39 #include "DiskIO/WriteRequest.h"
41 CBDATA_CLASS_INIT(BlockingFile
);
44 BlockingFile::operator new(size_t sz
)
46 CBDATA_INIT_TYPE(BlockingFile
);
47 BlockingFile
*result
= cbdataAlloc(BlockingFile
);
48 /* Mark result as being owned - we want the refcounter to do the delete
54 BlockingFile::operator delete(void *address
)
56 BlockingFile
*t
= static_cast<BlockingFile
*>(address
);
60 BlockingFile::BlockingFile(char const *aPath
) : fd (-1), closed (true), error_(false)
63 debugs(79, 3, "BlockingFile::BlockingFile: " << aPath
);
64 path_
= xstrdup (aPath
);
67 BlockingFile::~BlockingFile()
74 BlockingFile::open(int flags
, mode_t mode
, RefCount
<IORequestor
> callback
)
76 /* Simulate async calls */
77 fd
= file_open(path_
, flags
);
78 ioRequestor
= callback
;
81 debugs(79, 3, "BlockingFile::open: got failure (" << errno
<< ")");
86 debugs(79, 3, "BlockingFile::open: opened FD " << fd
);
89 callback
->ioCompletedNotification();
93 * Alias for BlockingFile::open(...)
94 \copydoc BlockingFile::open(int flags, mode_t mode, RefCount<IORequestor> callback)
97 BlockingFile::create(int flags
, mode_t mode
, RefCount
<IORequestor
> callback
)
99 /* We use the same logic path for open */
100 open(flags
, mode
, callback
);
104 void BlockingFile::doClose()
109 store_open_disk_fd
--;
115 BlockingFile::close()
117 debugs(79, 3, "BlockingFile::close: " << this << " closing for " << ioRequestor
.getRaw());
119 assert (ioRequestor
.getRaw());
120 ioRequestor
->closeCompleted();
124 BlockingFile::canRead() const
130 BlockingFile::error() const
132 if ((fd
< 0 && !closed
) || error_
)
138 void BlockingFile::error(bool const &aBool
)
144 BlockingFile::read(ReadRequest
*aRequest
)
147 assert (ioRequestor
.getRaw());
148 readRequest
= aRequest
;
149 file_read(fd
, aRequest
->buf
, aRequest
->len
, aRequest
->offset
, ReadDone
, this);
153 BlockingFile::ReadDone(int fd
, const char *buf
, int len
, int errflag
, void *my_data
)
155 BlockingFile
*myFile
= static_cast<BlockingFile
*>(my_data
);
157 myFile
->readDone (fd
, buf
, len
, errflag
);
161 BlockingFile::write(WriteRequest
*aRequest
)
163 debugs(79, 3, "storeUfsWrite: FD " << fd
);
164 writeRequest
= aRequest
;
167 (char *)aRequest
->buf
,
171 aRequest
->free_func
);
175 BlockingFile::ioInProgress() const
177 /** \retval false IO is never pending with UFS */
181 /* === STATIC =========================================================== */
184 BlockingFile::readDone(int rvfd
, const char *buf
, int len
, int errflag
)
186 debugs(79, 3, "BlockingFile::readDone: FD " << rvfd
);
192 debugs(79, 3, "BlockingFile::readDone: got failure (" << errflag
<< ")");
195 rlen
= (ssize_t
) len
;
198 if (errflag
== DISK_EOF
)
199 errflag
= DISK_OK
; /* EOF is signalled by len == 0, not errors... */
201 ReadRequest::Pointer result
= readRequest
;
205 ioRequestor
->readCompleted(buf
, rlen
, errflag
, result
);
209 BlockingFile::WriteDone (int fd
, int errflag
, size_t len
, void *me
)
211 BlockingFile
*aFile
= static_cast<BlockingFile
*>(me
);
212 aFile
->writeDone (fd
, errflag
, len
);
216 BlockingFile::writeDone(int rvfd
, int errflag
, size_t len
)
219 debugs(79, 3, "storeUfsWriteDone: FD " << fd
<< ", len " << len
);
221 WriteRequest::Pointer result
= writeRequest
;
225 debugs(79, 0, "storeUfsWriteDone: got failure (" << errflag
<< ")");
227 ioRequestor
->writeCompleted (DISK_ERROR
,0, result
);
231 ioRequestor
->writeCompleted(DISK_OK
, len
, result
);