]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/DiskIO/Blocking/BlockingFile.cc
2 * DEBUG: section 47 Store Directory Routines
3 * AUTHOR: Robert Collins
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
34 #include "BlockingFile.h"
38 #include "DiskIO/IORequestor.h"
39 #include "DiskIO/ReadRequest.h"
40 #include "DiskIO/WriteRequest.h"
47 CBDATA_CLASS_INIT(BlockingFile
);
49 BlockingFile::BlockingFile(char const *aPath
) : fd (-1), closed (true), error_(false)
52 debugs(79, 3, "BlockingFile::BlockingFile: " << aPath
);
53 path_
= xstrdup (aPath
);
56 BlockingFile::~BlockingFile()
63 BlockingFile::open(int flags
, mode_t mode
, RefCount
<IORequestor
> callback
)
65 /* Simulate async calls */
66 fd
= file_open(path_
, flags
);
67 ioRequestor
= callback
;
70 debugs(79, 3, "BlockingFile::open: got failure (" << errno
<< ")");
75 debugs(79, 3, "BlockingFile::open: opened FD " << fd
);
78 callback
->ioCompletedNotification();
82 * Alias for BlockingFile::open(...)
83 \copydoc BlockingFile::open(int flags, mode_t mode, RefCount<IORequestor> callback)
86 BlockingFile::create(int flags
, mode_t mode
, RefCount
<IORequestor
> callback
)
88 /* We use the same logic path for open */
89 open(flags
, mode
, callback
);
92 void BlockingFile::doClose()
103 BlockingFile::close()
105 debugs(79, 3, "BlockingFile::close: " << this << " closing for " << ioRequestor
.getRaw());
107 assert (ioRequestor
.getRaw());
108 ioRequestor
->closeCompleted();
112 BlockingFile::canRead() const
118 BlockingFile::error() const
120 if ((fd
< 0 && !closed
) || error_
)
126 void BlockingFile::error(bool const &aBool
)
132 BlockingFile::read(ReadRequest
*aRequest
)
135 assert (ioRequestor
.getRaw());
136 readRequest
= aRequest
;
137 debugs(79, 3, HERE
<< aRequest
->len
<< " for FD " << fd
<< " at " << aRequest
->offset
);
138 file_read(fd
, aRequest
->buf
, aRequest
->len
, aRequest
->offset
, ReadDone
, this);
142 BlockingFile::ReadDone(int fd
, const char *buf
, int len
, int errflag
, void *my_data
)
144 BlockingFile
*myFile
= static_cast<BlockingFile
*>(my_data
);
146 myFile
->readDone (fd
, buf
, len
, errflag
);
150 BlockingFile::write(WriteRequest
*aRequest
)
152 debugs(79, 3, HERE
<< aRequest
->len
<< " for FD " << fd
<< " at " << aRequest
->offset
);
153 writeRequest
= aRequest
;
156 (char *)aRequest
->buf
,
160 aRequest
->free_func
);
164 BlockingFile::ioInProgress() const
166 /** \retval false IO is never pending with UFS */
170 /* === STATIC =========================================================== */
173 BlockingFile::readDone(int rvfd
, const char *buf
, int len
, int errflag
)
175 debugs(79, 3, "BlockingFile::readDone: FD " << rvfd
);
181 debugs(79, 3, "BlockingFile::readDone: got failure (" << errflag
<< ")");
184 rlen
= (ssize_t
) len
;
187 if (errflag
== DISK_EOF
)
188 errflag
= DISK_OK
; /* EOF is signalled by len == 0, not errors... */
190 ReadRequest::Pointer result
= readRequest
;
194 ioRequestor
->readCompleted(buf
, rlen
, errflag
, result
);
198 BlockingFile::WriteDone (int fd
, int errflag
, size_t len
, void *me
)
200 BlockingFile
*aFile
= static_cast<BlockingFile
*>(me
);
201 aFile
->writeDone (fd
, errflag
, len
);
205 BlockingFile::writeDone(int rvfd
, int errflag
, size_t len
)
208 debugs(79, 3, HERE
<< "FD " << fd
<< ", len " << len
);
210 WriteRequest::Pointer result
= writeRequest
;
214 debugs(79, DBG_CRITICAL
, "storeUfsWriteDone: got failure (" << errflag
<< ")");
216 ioRequestor
->writeCompleted (DISK_ERROR
,0, result
);
220 ioRequestor
->writeCompleted(DISK_OK
, len
, result
);