summaryrefslogtreecommitdiff
path: root/src/Buffer.cc
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-11-19 23:50:49 -0800
committerPixel <pixel@nobis-crew.org>2011-11-19 23:50:49 -0800
commit071e7f07901309a38c8cb5311aaecaa46c0c3542 (patch)
treef1b85e8e2e57a928ee870f5d13870656599324cd /src/Buffer.cc
parentb9e2cb295e8f53f0311d8e3b5b0edf69bb76ea78 (diff)
Having the ability to create buffers from const memory.
Diffstat (limited to 'src/Buffer.cc')
-rw-r--r--src/Buffer.cc10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/Buffer.cc b/src/Buffer.cc
index f276ec0..a958571 100644
--- a/src/Buffer.cc
+++ b/src/Buffer.cc
@@ -9,6 +9,11 @@
static const int s_blockSize = 16 * 1024;
+Balau::Buffer::~Buffer() {
+ if (!m_fromConst)
+ free(m_buffer);
+}
+
void Balau::Buffer::close() throw (GeneralException) {
reset();
}
@@ -30,6 +35,9 @@ ssize_t Balau::Buffer::read(void * buf, size_t count) throw (GeneralException) {
}
ssize_t Balau::Buffer::write(const void * buf, size_t count) throw (GeneralException) {
+ if (m_fromConst)
+ throw GeneralException("Buffer is read only and can't be written to.");
+
off_t cursor = wtell();
off_t end = cursor + count;
off_t endBlock = (end / s_blockSize) + ((end % s_blockSize) ? 1 : 0);
@@ -64,4 +72,4 @@ bool Balau::Buffer::isEOF() { return rtell() == m_bufSize; }
const char * Balau::Buffer::getName() { return "Buffer"; }
off_t Balau::Buffer::getSize() { return m_bufSize; }
bool Balau::Buffer::canRead() { return true; }
-bool Balau::Buffer::canWrite() { return true; }
+bool Balau::Buffer::canWrite() { return !m_fromConst; }