diff options
-rw-r--r-- | includes/BStream.h | 1 | ||||
-rw-r--r-- | includes/Handle.h | 2 | ||||
-rw-r--r-- | src/BStream.cc | 8 |
3 files changed, 10 insertions, 1 deletions
diff --git a/includes/BStream.h b/includes/BStream.h index 087948d..d5b5c17 100644 --- a/includes/BStream.h +++ b/includes/BStream.h @@ -23,6 +23,7 @@ class BStream : public Handle { size_t m_availBytes; size_t m_cursor; String m_name; + bool m_passThru; }; }; diff --git a/includes/Handle.h b/includes/Handle.h index 99aa3a5..f304086 100644 --- a/includes/Handle.h +++ b/includes/Handle.h @@ -87,6 +87,8 @@ class IO : public IOBase { IO(const IO<T> & io) { if (io.m_h) setHandle(io.m_h); } template<class U> IO(const IO<U> & io) { if (io.m_h) setHandle(io.m_h); } + template<class U> + bool isA() { return !!dynamic_cast<U *>(m_h); } IO<T> & operator=(const IO<T> & io) { if (m_h) m_h->delRef(); setHandle(io.m_h); return *this; } T * operator->() { Assert(m_h); T * r = dynamic_cast<T *>(m_h); Assert(r); return r; } bool isNull() { return dynamic_cast<T *>(m_h); } diff --git a/src/BStream.cc b/src/BStream.cc index 148e930..a27cbc5 100644 --- a/src/BStream.cc +++ b/src/BStream.cc @@ -1,10 +1,13 @@ #include "BStream.h" +#include "Buffer.h" static const int s_blockSize = 16 * 1024; -Balau::BStream::BStream(const IO<Handle> & h) : m_h(h), m_buffer((uint8_t *) malloc(s_blockSize)), m_availBytes(0), m_cursor(0) { +Balau::BStream::BStream(const IO<Handle> & h) : m_h(h), m_buffer((uint8_t *) malloc(s_blockSize)), m_availBytes(0), m_cursor(0), m_passThru(false) { Assert(m_h->canRead()); m_name.set("Stream(%s)", m_h->getName()); + if ((m_h.isA<Buffer>()) || (m_h.isA<BStream>())) + m_passThru = true; } void Balau::BStream::close() throw (Balau::GeneralException) { @@ -21,6 +24,8 @@ const char * Balau::BStream::getName() { return m_name.to_charp(); } off_t Balau::BStream::getSize() { return m_h->getSize(); } ssize_t Balau::BStream::read(void * _buf, size_t count) throw (Balau::GeneralException) { + if (m_passThru) + return m_h->read(_buf, count); uint8_t * buf = (uint8_t *) _buf; size_t copied = 0; size_t toCopy = count; @@ -62,6 +67,7 @@ ssize_t Balau::BStream::read(void * _buf, size_t count) throw (Balau::GeneralExc } int Balau::BStream::peekNextByte() { + m_passThru = false; if (m_availBytes == 0) { uint8_t b; ssize_t r = read(&b, 1); |