nidas v1.2.3
|
A base class for buffering data. More...
#include <IOStream.h>
Public Member Functions | |
IOStream (IOChannel &input, size_t buflen=8192) | |
Create IOStream. | |
virtual | ~IOStream () |
size_t | available () const |
Number of bytes available to be copied from the buffer of IOStream. | |
bool | isNewInput () const |
Did last read(), or read(buf,len) call result in a new file being opened? | |
size_t | read () |
Do an IOChannel::read into the internal buffer of IOStream. | |
size_t | readBuf (void *buf, size_t len) throw () |
Copy available bytes from the internal buffer to buf, returning the number of bytes copied, which may be less then len. | |
size_t | read (void *buf, size_t len) |
Read len bytes of data into buf. | |
size_t | skip (size_t len) |
If the internal buffer is empty, do an IOChannel::read into the buffer. | |
size_t | backup (size_t len) throw () |
Move the read buffer pointer backwards by len number of bytes, so that the next readBuf will return data that was previously read. | |
size_t | backup () throw () |
Move the read buffer pointer backwards to the beginning of the buffer. | |
size_t | readUntil (void *buf, size_t len, char term) |
Read into the user buffer until a terminating character is found or len-1 bytes have been read. | |
size_t | write (const struct iovec *iov, int nbufs, bool flush) |
Write data. | |
size_t | write (const void *buf, size_t len, bool flush) |
void | flush () |
Flush buffer to physical device. | |
dsm_time_t | createFile (dsm_time_t t, bool exact) |
Request that IOChannel object open a new file, with a name based on a time. | |
const std::string & | getName () const |
long long | getNumInputBytes () const |
Number of bytes read with this IOStream. | |
void | addNumInputBytes (int val) |
long long | getNumOutputBytes () const |
Total number of bytes written with this IOStream. | |
void | addNumOutputBytes (int val) |
Protected Member Functions | |
void | reallocateBuffer (size_t len) |
Protected Attributes | |
IOChannel & | _iochannel |
Private Member Functions | |
IOStream (const IOStream &) | |
No copying. | |
IOStream & | operator= (const IOStream &) |
No assignment. | |
Private Attributes | |
char * | _buffer |
data buffer | |
char * | _head |
where we insert bytes into the buffer | |
char * | _tail |
where we remove bytes from the buffer | |
size_t | _buflen |
The actual buffer size. | |
size_t | _halflen |
char * | _eob |
One past end of buffer. | |
bool | _newInput |
Was the previous read performed on a newly opened file? | |
long long | _nbytesIn |
long long | _nbytesOut |
size_t | _nEAGAIN |
A base class for buffering data.
Create IOStream.
input | reference to an Input object providing the physical IO |
buflen | length of buffer, in bytes. |
References reallocateBuffer().
|
virtual |
References _buffer.
References _nbytesIn, and nidas::core::getSample().
Referenced by readBuf().
References _nbytesOut, and nidas::core::getSample().
|
inline |
Number of bytes available to be copied from the buffer of IOStream.
Referenced by read(), nidas::dynld::SampleInputStream::read(), read(), readBuf(), nidas::dynld::SampleInputStream::readSamples(), readUntil(), and skip().
size_t IOStream::backup | ( | ) | ||||
throw | ( | ) |
Move the read buffer pointer backwards by len number of bytes, so that the next readBuf will return data that was previously read.
This just backs over bytes in the current buffer, and does not reposition the physical device.
References nidas::util::addBackslashSequences(), DLOG, nidas::core::getSample(), len, and WLOG.
Referenced by nidas::dynld::SampleInputStream::handleNewInput(), and nidas::dynld::SampleInputStream::parseInputHeader().
|
inline |
Request that IOChannel object open a new file, with a name based on a time.
t | Time to use when creating file name. |
exact | Use exact time when creating file name, else the time is truncated down to an even time interval. |
nidas::util::IOException |
References _iochannel, nidas::core::IOChannel::createFile(), and flush().
void IOStream::flush | ( | ) |
Flush buffer to physical device.
This is not done automatically by the destructor - the user must call flush before destroying this IOStream.
nidas::util::IOException |
References _buffer, _head, _iochannel, _tail, addNumOutputBytes(), nidas::core::IOChannel::flush(), nidas::core::getSample(), and nidas::core::IOChannel::write().
Referenced by createFile(), nidas::dynld::SampleOutputStream::flush(), write(), and write().
|
inline |
References _iochannel, and nidas::core::IOChannel::getName().
Referenced by reallocateBuffer(), and write().
Number of bytes read with this IOStream.
References _nbytesIn.
Referenced by nidas::dynld::SampleInputStream::handleNewInput(), nidas::dynld::SampleInputStream::parseInputHeader(), nidas::dynld::SampleInputStream::readInputHeader(), and nidas::dynld::SampleInputStream::sampleFromHeader().
Total number of bytes written with this IOStream.
References _nbytesOut.
|
inline |
Did last read(), or read(buf,len) call result in a new file being opened?
References _newInput.
Referenced by nidas::dynld::SampleInputStream::read().
size_t IOStream::read | ( | ) |
Do an IOChannel::read into the internal buffer of IOStream.
nidas::util::IOException |
References _buffer, _eob, _head, _iochannel, _nbytesIn, _newInput, _tail, available(), nidas::core::getSample(), nidas::core::IOChannel::isNewInput(), nidas::core::IOChannel::read(), and VLOG.
Referenced by nidas::dynld::SampleInputStream::read(), read(), nidas::dynld::SampleInputStream::readInputHeader(), readUntil(), and skip().
Read len bytes of data into buf.
nidas::util::IOException |
References _iochannel, _newInput, available(), nidas::core::getSample(), nidas::core::IOChannel::isNewInput(), len, read(), and readBuf().
Copy available bytes from the internal buffer to buf, returning the number of bytes copied, which may be less then len.
An IOChannel::read() is not done, even if the internal buffer is empty.
References _tail, addNumInputBytes(), available(), nidas::core::getSample(), and len.
Referenced by nidas::dynld::SampleInputStream::read(), and read().
Read into the user buffer until a terminating character is found or len-1 bytes have been read.
The buffer is NULL terminated.
nidas::util::IOException |
References _head, _iochannel, _nbytesIn, _newInput, _tail, available(), nidas::core::getSample(), nidas::core::IOChannel::isNewInput(), len, and read().
If the internal buffer is empty, do an IOChannel::read into the buffer.
Then skip over len bytes in the user buffer.
nidas::util::IOException |
References _nbytesIn, _newInput, _tail, available(), nidas::core::getSample(), len, and read().
Write data.
This supports an atomic write of data from multiple buffers into an output buffer. The write either completely succeeds (all buffers written), or completely fails (no buffers written). This prevents partial data samples from being written, and also reduces the need for copying to a temporary buffer.
iov | Array of pointers to buffers of data to be written. |
nbufs | Number of buffers, the length of iov. |
flush | force a write to the physical device. |
nidas::util::IOException |
References _buffer, _buflen, _eob, _halflen, _head, _iochannel, _nEAGAIN, _tail, addNumOutputBytes(), flush(), getName(), nidas::core::getSample(), reallocateBuffer(), WLOG, and nidas::core::IOChannel::write().
Referenced by nidas::dynld::SampleOutputStream::write(), write(), nidas::dynld::SampleOutputStream::write(), and nidas::core::SampleInputHeader::write().
nidas::util::IOException |
References flush(), nidas::core::getSample(), len, and write().
|
private |
data buffer
Referenced by backup(), flush(), read(), reallocateBuffer(), write(), and ~IOStream().
|
private |
The actual buffer size.
Referenced by reallocateBuffer(), and write().
|
private |
One past end of buffer.
Referenced by read(), reallocateBuffer(), and write().
|
private |
Referenced by reallocateBuffer(), and write().
|
private |
where we insert bytes into the buffer
Referenced by available(), flush(), read(), readUntil(), reallocateBuffer(), and write().
|
protected |
Referenced by createFile(), flush(), getName(), read(), read(), readUntil(), and write().
Referenced by addNumInputBytes(), getNumInputBytes(), read(), readUntil(), and skip().
Referenced by addNumOutputBytes(), and getNumOutputBytes().
|
private |
Was the previous read performed on a newly opened file?
Referenced by isNewInput(), read(), read(), readUntil(), and skip().
|
private |
where we remove bytes from the buffer
Referenced by available(), backup(), flush(), read(), readBuf(), readUntil(), reallocateBuffer(), skip(), and write().