1 #define __STDC_LIMIT_MACROS 1
19 if (clock_gettime(CLOCK_REALTIME, &tm) == 0)
20 return tm.tv_sec * 1e9 + tm.tv_nsec;
23 if (gettimeofday(&tm, 0) == 0)
24 return tm.tv_sec * 1e9 + tm.tv_usec * 1e3;
53 {
open (name, flags, perms); }
69 <<
"Destructor called on RFIO file '" <<
m_name
70 <<
"' but the file is still open";
132 if ((name == 0) || (*name == 0))
134 <<
"Cannot open a file without a name";
138 <<
"Must open file '" << name <<
"' at least for read or write";
140 std::string lname (name);
141 if (lname.find (
"//") == 0)
153 else if (flags & IOFlags::OpenRead)
154 openflags |= O_RDONLY;
155 else if (flags & IOFlags::OpenWrite)
156 openflags |= O_WRONLY;
162 openflags |= O_APPEND;
165 openflags |= O_CREAT;
171 openflags |= O_TRUNC;
174 if ((newfd =
rfio_open64 (lname.c_str(), openflags, perms)) == -1)
176 <<
"rfio_open(name='" << lname
177 <<
"', flags=0x" << std::hex << openflags
178 <<
", permissions=0" << std::oct << perms << std::dec
195 <<
"RFIOFile::close(name='" <<
m_name
196 <<
"') called but the file is not open";
206 <<
"rfio_close64(name='" <<
m_name
215 <<
"RFIOFile::close(): system level close after a failed"
216 <<
" rfio_close64 also failed with error '" << strerror (errno)
217 <<
"' (error code " << errno <<
")";
220 <<
"RFIOFile::close(): system level close after a failed"
221 <<
" rfio_close64 succeeded";
266 if ((s == -1 &&
serrno == 1004) || (s > ssize_t (n)))
269 const char *sleepTimeMsg;
270 int secondsToSleep = 5;
274 sleepTimeMsg =
"10 minutes";
275 secondsToSleep = 600;
279 sleepTimeMsg =
"5 minutes";
280 secondsToSleep = 300;
284 sleepTimeMsg =
"1 minute";
289 <<
"RFIOFile retrying read\n"
290 <<
" return value from rfio_read64 = " << s <<
" (normally this is bytes read, -1 for error)\n"
291 <<
" bytes requested = " << n <<
" (this and bytes read are equal unless error or EOF)\n"
292 <<
" rfio error message = " <<
rfio_serror() <<
" (explanation from server, if possible)\n"
293 <<
" serrno = " <<
serrno <<
" (rfio server error code, 0 = OK, 1004 = timeout, ...)\n"
294 <<
" rfio_errno = " <<
rfio_errno <<
" (rfio error from actually accessing the file)\n"
295 <<
" current position = " <<
m_curpos <<
" (in bytes, beginning of file is 0)\n"
296 <<
" retries left before quitting = " << maxRetry <<
"\n"
297 <<
" will close and reopen file " <<
m_name <<
"\n"
298 <<
" will sleep for " << sleepTimeMsg <<
" before attempting retry";
300 sleep(secondsToSleep);
309 }
while (--maxRetry > 0);
320 LogDebug(
"RFIOFileDebug") <<
"Entering RFIOFile read()";
327 <<
"rfio_read(name='" <<
m_name <<
"', n=" << n <<
") failed"
335 <<
"Exiting RFIOFile read(), elapsed time = " << end - start
336 <<
" ns, bytes read = " << s <<
", file position = " <<
m_curpos;
356 <<
"rfio_write(name='" <<
m_name <<
"', n=" << n <<
") failed"
370 <<
"RFIOFile::position() called on a closed file";
373 <<
"RFIOFile::position() called with incorrect 'whence' parameter";
376 int mywhence = (whence ==
SET ? SEEK_SET
383 <<
"rfio_lseek(name='" <<
m_name <<
"', offset=" << offset
384 <<
", whence=" << mywhence <<
") failed at position "
396 <<
"RFIOFile::resize(name='" <<
m_name <<
"') not implemented";
404 <<
"RFIOFile::prefetch() called but RFIO_READOPT="
407 std::vector<iovec64>
iov (n);
411 iov[
i].iov_len = what[
i].
size();
422 <<
"RFIOFile::prefetch(name='" <<
m_name <<
"') failed with error '"
424 <<
", serrno=" <<
serrno <<
")";
430 <<
"RFIOFile::prefetch(name='" <<
m_name <<
"') failed at position "
433 <<
"); retrying " << (retry+1) <<
" times";
virtual IOSize write(const void *from, IOSize n)
int rfio_write64(int s, const void *ptr, int size)
virtual IOSize readv(IOPosBuffer *into, IOSize buffers)
std::vector< Variable::Flags > flags
virtual IOSize readv(IOPosBuffer *into, IOSize buffers)
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
int rfiosetopt(int opt, int *pval, int len)
int rfio_read64(int s, void *ptr, int size)
virtual void resize(IOOffset size)
virtual IOOffset position(void) const
virtual void create(const char *name, bool exclusive=false, int perms=0666)
static double realNanoSecs(void)
unsigned int offset(bool)
int rfio_open64(const char *filepath, int flags, int mode)
IOOffset offset(void) const
ssize_t retryRead(void *into, IOSize n, int maxRetry=10)
static std::string from(" from ")
virtual bool prefetch(const IOPosBuffer *what, IOSize n)
off64_t rfio_lseek64(int s, off64_t offset, int how)
int rfio_preseek64(int, struct iovec64 *, int)