CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes
File Class Reference

#include <File.h>

Inheritance diagram for File:
IOChannel Storage IOInput IOOutput IOInput IOOutput RemoteFile

Public Member Functions

virtual void abort (void)
 
virtual void attach (IOFD fd)
 
void close (void) override
 
virtual void create (const char *name, bool exclusive=false, int perms=0666)
 
virtual void create (const std::string &name, bool exclusive=false, int perms=0666)
 
 File (void)
 
 File (IOFD fd, bool autoclose=true)
 
 File (const char *name, int flags=IOFlags::OpenRead, int perms=0666)
 
 File (const std::string &name, int flags=IOFlags::OpenRead, int perms=0666)
 
void flush (void) override
 
virtual void open (const char *name, int flags=IOFlags::OpenRead, int perms=0666)
 
virtual void open (const std::string &name, int flags=IOFlags::OpenRead, int perms=0666)
 
IOOffset position (IOOffset offset, Relative whence=SET) override
 
bool prefetch (const IOPosBuffer *what, IOSize n) override
 
IOSize read (void *into, IOSize n) override
 
IOSize read (void *into, IOSize n, IOOffset pos) override
 
IOSize readv (IOBuffer *into, IOSize length) override
 
void resize (IOOffset size) override
 
virtual void setAutoClose (bool closeit)
 
IOOffset size (void) const override
 
IOSize write (const void *from, IOSize n) override
 
IOSize write (const void *from, IOSize n, IOOffset pos) override
 
IOSize writev (const IOBuffer *from, IOSize length) override
 
 ~File (void) override
 
- Public Member Functions inherited from IOChannel
virtual IOFD fd (void) const
 
virtual void fd (IOFD value)
 
 IOChannel (IOFD fd=-1)
 
virtual bool isBlocking (void) const
 
IOSize read (void *into, IOSize n) override
 
IOSize readv (IOBuffer *into, IOSize buffers) override
 
virtual void setBlocking (bool value)
 
IOSize write (const void *from, IOSize n) override
 
IOSize writev (const IOBuffer *from, IOSize buffers) override
 
 ~IOChannel (void) override
 
- Public Member Functions inherited from IOInput
int read (void)
 
IOSize read (IOBuffer into)
 
IOSize xread (IOBuffer into)
 
IOSize xread (void *into, IOSize n)
 
IOSize xreadv (IOBuffer *into, IOSize buffers)
 
virtual ~IOInput (void)
 Destruct the stream. A no-op. More...
 
- Public Member Functions inherited from IOOutput
IOSize write (unsigned char byte)
 
IOSize write (IOBuffer from)
 
IOSize xwrite (const void *from, IOSize n)
 
IOSize xwrite (IOBuffer from)
 
IOSize xwritev (const IOBuffer *from, IOSize buffers)
 
virtual ~IOOutput (void)
 Destruct the stream. A no-op. More...
 
- Public Member Functions inherited from Storage
virtual bool eof (void) const
 
virtual IOOffset position (void) const
 
IOSize read (IOBuffer into, IOOffset pos)
 
virtual IOSize readv (IOPosBuffer *into, IOSize buffers)
 
virtual void rewind (void)
 
 Storage (void)
 
IOSize write (IOBuffer from, IOOffset pos)
 
virtual IOSize writev (const IOPosBuffer *from, IOSize buffers)
 
 ~Storage (void) override
 

Private Types

enum  { InternalAutoClose = 4096 }
 

Private Member Functions

Fileduplicate (bool copy) const
 
Fileduplicate (File *child) const
 
 File (IOFD fd, unsigned flags)
 

Static Private Member Functions

static bool sysclose (IOFD fd, int *error=nullptr)
 
static IOFD sysduplicate (IOFD fd)
 
static void sysopen (const char *name, int flags, int perms, IOFD &newfd, unsigned &newflags)
 

Private Attributes

unsigned m_flags
 

Additional Inherited Members

- Public Types inherited from Storage
enum  Relative { SET, CURRENT, END }
 
- Protected Member Functions inherited from IOChannel
bool sysclose (IOFD fd, int *error=nullptr)
 

Detailed Description

Basic file-related functions. Nicked from SEAL.

Definition at line 11 of file File.h.

Member Enumeration Documentation

anonymous enum
private
Enumerator
InternalAutoClose 

Definition at line 54 of file File.h.

54 { InternalAutoClose = 4096 }; //< Close on delete

Constructor & Destructor Documentation

File::File ( void  )

Create a new file object without a file attached to it.

Definition at line 57 of file File.cc.

References EDM_IOFD_INVALID, and ztee::fd.

57  {
59  m_flags = 0;
60 }
unsigned m_flags
Definition: File.h:64
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
File::File ( IOFD  fd,
bool  autoclose = true 
)

Create a new file object from a file descriptor. The descriptor will be closed automatically when the file object is destructed if autoclose is true (the default).

Definition at line 65 of file File.cc.

References ztee::fd.

65  {
66  this->fd(fd);
67  m_flags = autoclose ? InternalAutoClose : 0;
68 }
unsigned m_flags
Definition: File.h:64
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
File::File ( const char *  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)

Create a new file object by calling open() with the given arguments.

Definition at line 77 of file File.cc.

77 { open(name, flags, perms); }
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: File.cc:156
File::File ( const std::string &  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)

Create a new file object by calling open() with the given arguments.

Definition at line 80 of file File.cc.

References HLT_2018_cff::flags.

80  {
81  open(name.c_str(), flags, perms);
82 }
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: File.cc:156
File::~File ( void  )
override

Release the resources held by the file object. If the object holds a valid file descriptor given to it through the constructor or obtained by calling open(), the descriptor will be closed.

Definition at line 87 of file File.cc.

87  {
89  abort();
90 }
unsigned m_flags
Definition: File.h:64
virtual void abort(void)
Definition: File.cc:254
File::File ( IOFD  fd,
unsigned  flags 
)
private

Internal function for copying file objects to retain the state flags.

Definition at line 71 of file File.cc.

References ztee::fd, and HLT_2018_cff::flags.

71  {
72  this->fd(fd);
73  m_flags = flags;
74 }
unsigned m_flags
Definition: File.h:64
virtual IOFD fd(void) const
Definition: IOChannel.cc:69

Member Function Documentation

void File::abort ( void  )
virtual

Close the file and ignore all errors.

Reimplemented in RemoteFile.

Definition at line 254 of file File.cc.

References EDM_IOFD_INVALID, and ztee::fd.

Referenced by RemoteFile::abort().

254  {
255  IOFD fd = this->fd();
256  if (fd != EDM_IOFD_INVALID) {
257  sysclose(fd);
259  this->fd(EDM_IOFD_INVALID);
260  }
261 }
unsigned m_flags
Definition: File.h:64
static bool sysclose(IOFD fd, int *error=nullptr)
Definition: UnixFile.cc:135
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
void File::attach ( IOFD  fd)
virtual

Definition at line 178 of file File.cc.

References ztee::fd.

178  {
179  this->fd(fd);
180  m_flags = 0;
181 }
unsigned m_flags
Definition: File.h:64
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
void File::close ( void  )
overridevirtual

Close the file.

Reimplemented from IOChannel.

Reimplemented in RemoteFile.

Definition at line 241 of file File.cc.

References EDM_IOFD_INVALID, relativeConstraints::error, ztee::fd, and throwStorageError().

Referenced by RemoteFile::close(), esMonitoring.AsyncLineReaderMixin::handle_close(), esMonitoring.FDJsonServer::handle_close(), Vispa.Gui.BoxContentDialog.BoxContentDialog::keyPressEvent(), and Vispa.Gui.FindDialog.FindDialog::keyPressEvent().

241  {
242  IOFD fd = this->fd();
243  assert(fd != EDM_IOFD_INVALID);
244 
245  int error;
246  if (!sysclose(fd, &error))
247  throwStorageError("FileCloseError", "Calling File::close()", "sysclose", error);
248 
250  this->fd(EDM_IOFD_INVALID);
251 }
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:6
unsigned m_flags
Definition: File.h:64
static bool sysclose(IOFD fd, int *error=nullptr)
Definition: UnixFile.cc:135
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
void File::create ( const char *  name,
bool  exclusive = false,
int  perms = 0666 
)
virtual

Create and open the file name in write mode. If exclusive, the creation fails if the file already exists, otherwise if the file exists, it will be truncated. The new file will have the permissions perms.

Definition at line 131 of file File.cc.

References IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenTruncate, and IOFlags::OpenWrite.

131  {
133 }
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: File.cc:156
void File::create ( const std::string &  name,
bool  exclusive = false,
int  perms = 0666 
)
virtual

Create and open the file name in write mode. If exclusive, the creation fails if the file already exists, otherwise if the file exists, it will be truncated. The new file will have the permissions perms.

Definition at line 139 of file File.cc.

References IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenTruncate, and IOFlags::OpenWrite.

139  {
140  open(name.c_str(), (OpenCreate | OpenWrite | OpenTruncate | (exclusive ? OpenExclusive : 0)), perms);
141 }
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: File.cc:156
File * File::duplicate ( bool  copy) const
private

Duplicate the file object. If copy, also duplicates the underlying file descriptor, otherwise the two will point to the same descriptor. If the file descriptor is not copied, the copy will not close its file descriptor on destruction, the original object (this) will.

Definition at line 110 of file File.cc.

References trackingPlots::dup, ztee::fd, and VtxSmearedBeamProfile_cfi::File.

110  {
111  File *dup = new File(fd(), copy ? m_flags : 0);
112  return copy ? this->duplicate(dup) : dup;
113 }
unsigned m_flags
Definition: File.h:64
File(void)
Definition: File.cc:57
File * duplicate(bool copy) const
Definition: File.cc:110
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
Definition: File.h:11
File * File::duplicate ( File child) const
private

Internal implementation of duplicate() to actually duplicate the file handle into child.

Definition at line 117 of file File.cc.

References class-composition::child, EDM_IOFD_INVALID, IOChannel::fd(), ztee::fd, and m_flags.

117  {
118  IOFD fd = this->fd();
119  assert(fd != EDM_IOFD_INVALID);
120  assert(child);
121  child->fd(sysduplicate(fd));
122  child->m_flags = m_flags;
123  return child;
124 }
unsigned m_flags
Definition: File.h:64
static IOFD sysduplicate(IOFD fd)
Definition: UnixFile.cc:9
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
void File::flush ( void  )
overridevirtual

Flush the system's file system buffers for this file.

Reimplemented from Storage.

Definition at line 122 of file UnixFile.cc.

References EDM_IOFD_INVALID, ztee::fd, and throwStorageError().

122  {
123  IOFD fd = this->fd();
124  assert(fd != EDM_IOFD_INVALID);
125 
126 #if _POSIX_SYNCHRONIZED_IO > 0
127  if (fdatasync(fd) == -1)
128  throwStorageError("FileFlushError", "Calling File::flush()", "fdatasync()", errno);
129 #elif _POSIX_FSYNC > 0
130  if (fsync(fd) == -1)
131  throwStorageError("FileFlushError", "Calling File::flush()", "fsync()", errno);
132 #endif
133 }
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:6
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
void File::open ( const char *  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)
virtual

Open or possibly create the file name with options specified in flags. If the file is to be created, it will be given the permissions perms. If this object already has a file open, it is closed first.

Definition at line 156 of file File.cc.

References EDM_IOFD_INVALID, ztee::fd, IOFlags::OpenRead, and IOFlags::OpenWrite.

156  {
157  // is zero and always implied. OTOH, existence check should be
158  // done with Filename::exists() -- see comments there about what
159  // can happen on a WIN32 remote share even if the file doesn't
160  // exist. For now make sure that read or write was asked for.
161 
162  assert(name && *name);
163  assert(flags & (OpenRead | OpenWrite));
164 
165  // If I am already open, close the old file first.
167  close();
168 
169  IOFD newfd = EDM_IOFD_INVALID;
170  unsigned newflags = InternalAutoClose;
171 
172  sysopen(name, flags, perms, newfd, newflags);
173 
174  fd(newfd);
175  m_flags = newflags;
176 }
unsigned m_flags
Definition: File.h:64
static void sysopen(const char *name, int flags, int perms, IOFD &newfd, unsigned &newflags)
Definition: UnixFile.cc:17
void close(void) override
Definition: File.cc:241
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
void File::open ( const std::string &  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)
virtual

Open or possibly create the file name with options specified in flags. If the file is to be created, it will be given the permissions perms. If this object already has a file open, it is closed first. Redirected to the overloaded method taking a "const char *" argument.

Definition at line 148 of file File.cc.

References HLT_2018_cff::flags.

148  {
149  open(name.c_str(), flags, perms);
150 }
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: File.cc:156
IOOffset File::position ( IOOffset  offset,
Relative  whence = SET 
)
overridevirtual

Return the current file pointer position.

Implements Storage.

Definition at line 101 of file UnixFile.cc.

References EDM_IOFD_INVALID, ztee::fd, mps_fire::result, L1DTConfigBti_cff::SET, and throwStorageError().

101  {
102  IOFD fd = this->fd();
103  assert(fd != EDM_IOFD_INVALID);
104  assert(whence == CURRENT || whence == SET || whence == END);
105 
107  int mywhence = (whence == SET ? SEEK_SET : whence == CURRENT ? SEEK_CUR : SEEK_END);
108  if ((result = ::lseek(fd, offset, mywhence)) == -1)
109  throwStorageError("FilePositionError", "Calling File::position()", "lseek()", errno);
110 
111  return result;
112 }
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:6
int64_t IOOffset
Definition: IOTypes.h:19
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
bool File::prefetch ( const IOPosBuffer what,
IOSize  n 
)
overridevirtual

Prefetch data for the file.

Reimplemented from Storage.

Definition at line 185 of file File.cc.

References ztee::fd, mps_fire::i, info(), dqmiodumpmetadata::n, IOPosBuffer::offset(), hltrates_dqm_sourceclient-live_cfg::offset, IOPosBuffer::size(), and findQualityFiles::size.

185  {
186  IOFD fd = this->fd();
187  for (IOSize i = 0; i < n; ++i) {
188 #if F_RDADVISE
189  radvisory info;
190  info.ra_offset = what[i].offset();
191  info.ra_count = what[i].size();
192  fcntl(fd, F_RDADVISE, &info);
193 #elif _POSIX_ADVISORY_INFO > 0
194  posix_fadvise(fd, what[i].offset(), what[i].size(), POSIX_FADV_WILLNEED);
195 #else
196 #error advisory read ahead not available on this platform
197 #endif
198  }
199  return true;
200 }
static const TGPicture * info(bool iBackgroundIsBlack)
IOOffset size(void) const override
Definition: UnixFile.cc:90
IOOffset offset(void) const
Definition: IOPosBuffer.h:39
IOSize size(void) const
Definition: IOPosBuffer.h:45
int IOFD
Definition: IOTypes.h:22
size_t IOSize
Definition: IOTypes.h:14
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
IOSize File::read ( void *  into,
IOSize  n 
)
overridevirtual

Read from the file.

Implements IOInput.

Definition at line 203 of file File.cc.

References IOInput::read().

203 { return IOChannel::read(into, n); }
int read(void)
Definition: IOInput.cc:52
IOSize File::read ( void *  into,
IOSize  n,
IOOffset  pos 
)
overridevirtual

Reimplemented from Storage.

Definition at line 58 of file UnixFile.cc.

References ztee::fd, edm::errors::FileReadError, alignCSCRings::s, and throwStorageError().

58  {
59  assert(pos >= 0);
60 
61  ssize_t s;
62  do
63  s = ::pread(fd(), into, n, pos);
64  while (s == -1 && errno == EINTR);
65 
66  if (s == -1)
67  throwStorageError(edm::errors::FileReadError, "Calling File::read()", "pread()", errno);
68 
69  return s;
70 }
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:6
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
IOSize File::readv ( IOBuffer into,
IOSize  length 
)
overridevirtual

Read from the file.

Reimplemented from IOInput.

Definition at line 206 of file File.cc.

References IOChannel::readv().

206 { return IOChannel::readv(into, length); }
IOSize readv(IOBuffer *into, IOSize buffers) override
void File::resize ( IOOffset  size)
overridevirtual

Resize to the file to size. If size is less than the file's current size, the file is truncated. If size is larger than the file's current size, the file is extended with zero bytes. Does not change the current file pointer.

Implements Storage.

Definition at line 114 of file UnixFile.cc.

References EDM_IOFD_INVALID, ztee::fd, and throwStorageError().

Referenced by Vispa.Gui.TextDialog.TextDialog::__init__(), Vispa.Plugins.ConfigEditor.ToolDialog.ToolDialog::__init__(), Vispa.Main.MainWindow.MainWindow::_loadIni(), and Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

114  {
115  IOFD fd = this->fd();
116  assert(fd != EDM_IOFD_INVALID);
117 
118  if (ftruncate(fd, size) == -1)
119  throwStorageError("FileResizeError", "Calling File::resize()", "ftruncate()", errno);
120 }
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:6
IOOffset size(void) const override
Definition: UnixFile.cc:90
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
void File::setAutoClose ( bool  autoclose)
virtual

Set the autoclose flag of the file. If autoclose is true, the destructor will automatically try to close the underlying file descriptor. Otherwise the file descriptor will be left open. Set the flag off if the file descriptor is originally owned by someone else.

Definition at line 98 of file File.cc.

98  {
100  if (autoclose)
102 }
unsigned m_flags
Definition: File.h:64
IOOffset File::size ( void  ) const
overridevirtual

Get the size of the file.

Reimplemented from Storage.

Definition at line 90 of file UnixFile.cc.

References EDM_IOFD_INVALID, ztee::fd, and throwStorageError().

Referenced by ntupleDataFormat._Collection::__iter__(), and ntupleDataFormat._Collection::__len__().

90  {
91  IOFD fd = this->fd();
92  assert(fd != EDM_IOFD_INVALID);
93 
94  struct stat info;
95  if (fstat(fd, &info) == -1)
96  throwStorageError("FileSizeError", "Calling File::size()", "fstat()", errno);
97 
98  return info.st_size;
99 }
static const TGPicture * info(bool iBackgroundIsBlack)
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:6
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
bool File::sysclose ( IOFD  fd,
int *  error = nullptr 
)
staticprivate

Actually close a file handle and return error code.

Definition at line 135 of file UnixFile.cc.

References runTheMatrix::ret.

135  {
136  int ret = ::close(fd);
137  if (error)
138  *error = errno;
139  return ret != -1;
140 }
ret
prodAgent to be discontinued
void close(void) override
Definition: File.cc:241
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
IOFD File::sysduplicate ( IOFD  fd)
staticprivate

Definition at line 9 of file UnixFile.cc.

References trackingPlots::dup, EDM_IOFD_INVALID, and throwStorageError().

9  {
10  IOFD copyfd;
11  if ((copyfd = ::dup(fd)) == EDM_IOFD_INVALID)
12  throwStorageError("FileDuplicateError", "Calling File::sysduplicate()", "dup()", errno);
13 
14  return copyfd;
15 }
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:6
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
void File::sysopen ( const char *  name,
int  flags,
int  perms,
IOFD newfd,
unsigned &  newflags 
)
staticprivate

Definition at line 17 of file UnixFile.cc.

References edm::errors::FileOpenError, O_NONBLOCK, IOFlags::OpenAppend, IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenNonBlock, IOFlags::OpenNotCTTY, IOFlags::OpenRead, IOFlags::OpenTruncate, IOFlags::OpenUnbuffered, IOFlags::OpenWrite, and throwStorageError().

17  {
18  // Translate our flags to system flags.
19  int openflags = 0;
20 
21  if ((flags & OpenRead) && (flags & OpenWrite))
22  openflags |= O_RDWR;
23  else if (flags & OpenRead)
24  openflags |= O_RDONLY;
25  else if (flags & OpenWrite)
26  openflags |= O_WRONLY;
27 
28  if (flags & OpenNonBlock)
29  openflags |= O_NONBLOCK;
30 
31  if (flags & OpenAppend)
32  openflags |= O_APPEND;
33 
34 #ifdef O_SYNC
35  if (flags & OpenUnbuffered)
36  openflags |= O_SYNC;
37 #else
38  if (flags & OpenUnbuffered)
39  newflags |= OpenUnbuffered;
40 #endif
41 
42  if (flags & OpenCreate)
43  openflags |= O_CREAT;
44 
45  if (flags & OpenExclusive)
46  openflags |= O_EXCL;
47 
48  if (flags & OpenTruncate)
49  openflags |= O_TRUNC;
50 
51  if (flags & OpenNotCTTY)
52  openflags |= O_NOCTTY;
53 
54  if ((newfd = ::open(name, openflags, perms)) == -1)
55  throwStorageError(edm::errors::FileOpenError, "Calling File::sysopen()", "open()", errno);
56 }
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:6
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: File.cc:156
#define O_NONBLOCK
Definition: SysFile.h:21
IOSize File::write ( const void *  from,
IOSize  n 
)
overridevirtual

Write to the file.

Implements IOOutput.

Definition at line 209 of file File.cc.

References IOFlags::OpenAppend, IOFlags::OpenUnbuffered, position, alignCSCRings::s, and IOChannel::write().

209  {
210  // FIXME: This may create a race condition or cause trouble on
211  // remote files. Should be currently needed only on WIN32.
212  if (m_flags & OpenAppend)
213  position(0, END);
214 
215  IOSize s = IOChannel::write(from, n);
216 
217  if (m_flags & OpenUnbuffered)
218  // FIXME: Exception handling?
219  flush();
220 
221  return s;
222 }
unsigned m_flags
Definition: File.h:64
virtual IOOffset position(void) const
Definition: Storage.cc:72
IOSize write(const void *from, IOSize n) override
void flush(void) override
Definition: UnixFile.cc:122
size_t IOSize
Definition: IOTypes.h:14
IOSize File::write ( const void *  from,
IOSize  n,
IOOffset  pos 
)
overridevirtual

Reimplemented from Storage.

Definition at line 72 of file UnixFile.cc.

References ztee::fd, edm::errors::FileWriteError, IOFlags::OpenUnbuffered, alignCSCRings::s, and throwStorageError().

72  {
73  assert(pos >= 0);
74 
75  ssize_t s;
76  do
77  s = ::pwrite(fd(), from, n, pos);
78  while (s == -1 && errno == EINTR);
79 
80  if (s == -1)
81  throwStorageError(edm::errors::FileWriteError, "Calling File::write()", "pwrite()", errno);
82 
83  if (m_flags & OpenUnbuffered)
84  // FIXME: Exception handling?
85  flush();
86 
87  return s;
88 }
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:6
unsigned m_flags
Definition: File.h:64
void flush(void) override
Definition: UnixFile.cc:122
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
IOSize File::writev ( const IOBuffer from,
IOSize  length 
)
overridevirtual

Write to the file.

Reimplemented from IOOutput.

Definition at line 225 of file File.cc.

References IOFlags::OpenAppend, IOFlags::OpenUnbuffered, position, alignCSCRings::s, and IOChannel::writev().

225  {
226  // FIXME: This may create a race condition or cause trouble on
227  // remote files. Should be currently needed only on WIN32.
228  if (m_flags & OpenAppend)
229  position(0, END);
230 
231  IOSize s = IOChannel::writev(from, length);
232 
233  if (m_flags & OpenUnbuffered)
234  // FIXME: Exception handling?
235  flush();
236 
237  return s;
238 }
unsigned m_flags
Definition: File.h:64
IOSize writev(const IOBuffer *from, IOSize buffers) override
virtual IOOffset position(void) const
Definition: Storage.cc:72
void flush(void) override
Definition: UnixFile.cc:122
size_t IOSize
Definition: IOTypes.h:14

Member Data Documentation

unsigned File::m_flags
private

Definition at line 64 of file File.h.

Referenced by duplicate().