summaryrefslogtreecommitdiff
path: root/src/BStream.cc
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-12-04 01:19:09 -0800
committerPixel <pixel@nobis-crew.org>2011-12-04 01:20:10 -0800
commitd440c3f50a918a932293ad98bcec96eaa4683222 (patch)
tree33e8e42a8e4506ae9da70cdb44dd133bde7f7219 /src/BStream.cc
parente5577eb7a643ce7885e5d14660a6d24254161622 (diff)
Reworked some things in the architecture, mainly exceptions and asserts.
-) Removed Assert() -) Added AAssert(), IAssert(), RAssert(), TAssert() and Failure() -) Reworked all asserts in the code, and added meaningful messages to them. -) Changed the way the startup code is generated; BALAU_STARTUP is no longer necessary.
Diffstat (limited to 'src/BStream.cc')
-rw-r--r--src/BStream.cc14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/BStream.cc b/src/BStream.cc
index 89e38b0..cd7a121 100644
--- a/src/BStream.cc
+++ b/src/BStream.cc
@@ -4,7 +4,7 @@
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), m_passThru(false) {
- Assert(m_h->canRead());
+ AAssert(m_h->canRead(), "You can't create a buffered stream with a Handle that can't read");
m_name.set("Stream(%s)", m_h->getName());
if ((m_h.isA<Buffer>()) || (m_h.isA<BStream>()))
m_passThru = true;
@@ -50,9 +50,9 @@ ssize_t Balau::BStream::read(void * _buf, size_t count) throw (Balau::GeneralExc
return m_h->read(buf, count) + copied;
m_cursor = 0;
- Assert(m_availBytes == 0);
+ IAssert(m_availBytes == 0, "At this point, our internal buffer should be empty, but it's not: %lu", m_availBytes);
ssize_t r = m_h->read(m_buffer, s_blockSize);
- Assert(r >= 0);
+ RAssert(r >= 0, "BStream got an error while reading: %li", r);
m_availBytes = r;
if (toCopy > m_availBytes)
@@ -74,9 +74,9 @@ int Balau::BStream::peekNextByte() {
ssize_t r = read(&b, 1);
if (!r)
return -1;
- Assert(r == 1);
- Assert(m_cursor > 0);
- Assert(m_availBytes < s_blockSize);
+ RAssert(r == 1, "We asked for one byte, yet we got %li", r);
+ IAssert(m_cursor > 0, "m_cursor is %li", m_cursor);
+ IAssert(m_availBytes < s_blockSize, "m_availBytes = %li; s_blockSize = %i", m_availBytes, s_blockSize);
m_cursor--;
m_availBytes++;
}
@@ -109,7 +109,7 @@ Balau::String Balau::BStream::readString(bool putNL) {
if (isClosed() || isEOF())
return ret;
peekNextByte();
- Assert(m_cursor == 0);
+ IAssert(m_cursor == 0, "m_cursor is %li", m_cursor);
cr = (uint8_t *) memchr(m_buffer, '\r', m_availBytes);
lf = (uint8_t *) memchr(m_buffer, '\n', m_availBytes);
if (cr && lf) {