casacore
|
Class for unbuffered IO on a file. More...
#include <FiledesIO.h>
Public Member Functions | |
FiledesIO () | |
Default constructor. More... | |
FiledesIO (int fd, const String &fileName=String()) | |
Construct from the given file descriptor. More... | |
void | attach (int fd, const String &fileName) |
Attach to the given file descriptor. More... | |
void | detach () |
Detach from the file descriptor. More... | |
virtual | ~FiledesIO () |
The destructor detaches, but does not close the file. More... | |
virtual void | write (Int64 size, const void *buf) |
Write the number of bytes. More... | |
virtual void | pwrite (Int64 size, Int64 offset, const void *buf) |
Write the number of bytes at offset from start of the file. More... | |
virtual Int64 | read (Int64 size, void *buf, Bool throwException=True) |
Read size bytes from the descriptor. More... | |
virtual Int64 | pread (Int64 size, Int64 offset, void *buf, Bool throwException=True) |
Like read except reads from offset of the start of the file. More... | |
virtual Int64 | length () |
Get the length of the byte stream. More... | |
virtual Bool | isReadable () const |
Is the IO stream readable? More... | |
virtual Bool | isWritable () const |
Is the IO stream writable? More... | |
virtual Bool | isSeekable () const |
Is the IO stream seekable? More... | |
void | setWritable () |
Set that the IO stream is writable. More... | |
virtual String | fileName () const |
Get the file name of the file attached. More... | |
virtual void | fsync () |
Fsync the file (i.e. More... | |
Public Member Functions inherited from casacore::ByteIO | |
ByteIO () | |
The constructor does nothing. More... | |
virtual | ~ByteIO () |
virtual void | reopenRW () |
Reopen the underlying IO stream for read/write access. More... | |
Int64 | seek (Int offset, ByteIO::SeekOption=ByteIO::Begin) |
This function sets the position on the given offset. More... | |
Int64 | seek (Int64 offset, ByteIO::SeekOption=ByteIO::Begin) |
virtual void | flush () |
Flush the data to the file. More... | |
virtual void | resync () |
Resync the file (i.e. More... | |
Static Public Member Functions | |
static int | create (const Char *name, int mode=0666) |
Some static convenience functions for file create/open/close. More... | |
static int | open (const Char *name, Bool writable=False, Bool throwExcp=True) |
static void | close (int fd) |
Protected Member Functions | |
int | fd () const |
Get the file descriptor. More... | |
void | fillRWFlags (int fd) |
Determine if the file descriptor is readable and/or writable. More... | |
void | fillSeekable () |
Determine if the file is seekable. More... | |
virtual Int64 | doSeek (Int64 offset, ByteIO::SeekOption) |
Reset the position pointer to the given value. More... | |
Protected Member Functions inherited from casacore::ByteIO | |
ByteIO (const ByteIO &byteIO) | |
Make copy constructor and assignment protected, so a user cannot use them (but a derived class can). More... | |
ByteIO & | operator= (const ByteIO &byteIO) |
Private Member Functions | |
FiledesIO (const FiledesIO &that) | |
Copy constructor, should not be used. More... | |
FiledesIO & | operator= (const FiledesIO &that) |
Assignment, should not be used. More... | |
Private Attributes | |
Bool | itsSeekable |
Bool | itsReadable |
Bool | itsWritable |
int | itsFile |
String | itsFileName |
Additional Inherited Members | |
Public Types inherited from casacore::ByteIO | |
enum | OpenOption { Old, Update, Append, New, NewNoReplace, Scratch, Delete } |
Define the possible ByteIO open options. More... | |
enum | SeekOption { Begin, Current, End } |
Define the possible seek options. More... | |
Class for unbuffered IO on a file.
Public interface
This class is a specialization of class ByteIO. It uses a file descriptor to read/write data.
The file associated with the file descriptor has to be opened before hand. The constructor will determine automatically if the file is readable, writable and seekable. Note that on destruction the file descriptor is NOT closed.
This example shows how FiledesIO can be used with an fd. It uses the fd for a regular file, which could be done in an easier way using class RegularFileIO. However, when using pipes or sockets, this would be the only way.
Make it possible to use the Casacore IO functionality on any file. In this way any device can be hooked to the IO framework.
Definition at line 88 of file FiledesIO.h.
casacore::FiledesIO::FiledesIO | ( | ) |
Default constructor.
A stream can be attached using the attach function.
Construct from the given file descriptor.
The file name is only used in possible error messages.
|
virtual |
The destructor detaches, but does not close the file.
|
private |
Copy constructor, should not be used.
void casacore::FiledesIO::attach | ( | int | fd, |
const String & | fileName | ||
) |
Attach to the given file descriptor.
An exception is thrown if it is not in a detached state. The file name is only used in error messages.
|
static |
|
static |
Some static convenience functions for file create/open/close.
Close is only done if the fd is non-negative.
void casacore::FiledesIO::detach | ( | ) |
Detach from the file descriptor.
The file is not closed.
|
protectedvirtual |
Reset the position pointer to the given value.
It returns the new position.
Implements casacore::ByteIO.
Reimplemented in casacore::MMapfdIO.
|
inlineprotected |
|
virtual |
Get the file name of the file attached.
Reimplemented from casacore::ByteIO.
|
protected |
Determine if the file descriptor is readable and/or writable.
|
protected |
Determine if the file is seekable.
|
virtual |
|
virtual |
Is the IO stream readable?
Implements casacore::ByteIO.
|
virtual |
Is the IO stream seekable?
Implements casacore::ByteIO.
|
virtual |
Is the IO stream writable?
Implements casacore::ByteIO.
|
virtual |
Get the length of the byte stream.
Implements casacore::ByteIO.
|
static |
Assignment, should not be used.
|
virtual |
Like read except reads from offset of the start of the file.
The file offset is not changed
Reimplemented from casacore::ByteIO.
Write the number of bytes at offset from start of the file.
The file offset is not changed
Reimplemented from casacore::ByteIO.
|
virtual |
Read size
bytes from the descriptor.
Returns the number of bytes actually read or a negative number if an error occurred. Will throw an Exception (AipsError) if the requested number of bytes could not be read, or an error occured, unless throwException is set to False. Will always throw an exception if the descriptor is not readable or the system call returned an undocumented value.
Implements casacore::ByteIO.
Reimplemented in casacore::MMapfdIO.
|
inline |
Set that the IO stream is writable.
Definition at line 142 of file FiledesIO.h.
References itsWritable, and casacore::True.
|
virtual |
|
private |
Definition at line 180 of file FiledesIO.h.
Referenced by fd().
|
private |
Definition at line 181 of file FiledesIO.h.
|
private |
Definition at line 178 of file FiledesIO.h.
|
private |
Definition at line 177 of file FiledesIO.h.
|
private |
Definition at line 179 of file FiledesIO.h.
Referenced by setWritable().