aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bufferstore.cc
diff options
context:
space:
mode:
authorFritz Elfert <felfert@to.com>2002-03-05 17:58:11 +0000
committerFritz Elfert <felfert@to.com>2002-03-05 17:58:11 +0000
commitcb2577b29fe7b93e9b168ded7f35da748fdeaf1d (patch)
treed7cf962ead89069f885f8da7137feb94acb3dfec /lib/bufferstore.cc
parent8f9ae0a93ba3ea860a28933c2a411eae9365c859 (diff)
downloadplptools-cb2577b29fe7b93e9b168ded7f35da748fdeaf1d.tar.gz
plptools-cb2577b29fe7b93e9b168ded7f35da748fdeaf1d.tar.bz2
plptools-cb2577b29fe7b93e9b168ded7f35da748fdeaf1d.zip
- Re-Implemented lower levels of ncpd (packet and link).
ncpd is now multithreaded. Results in much better performance and less CPU usage.
Diffstat (limited to 'lib/bufferstore.cc')
-rw-r--r--lib/bufferstore.cc47
1 files changed, 36 insertions, 11 deletions
diff --git a/lib/bufferstore.cc b/lib/bufferstore.cc
index 183ae6c..811c690 100644
--- a/lib/bufferstore.cc
+++ b/lib/bufferstore.cc
@@ -22,36 +22,45 @@
*
*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <stream.h>
// Should be iostream.h, but won't build on Sun WorkShop C++ 5.0
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <assert.h>
#include "bufferstore.h"
-bufferStore::bufferStore() {
- lenAllocd = 0;
- buff = 0L;
- len = 0;
- start = 0;
+bufferStore::bufferStore()
+ : len(0)
+ , lenAllocd(0)
+ , start(0)
+ , buff(0)
+{
}
-bufferStore::bufferStore(const bufferStore &a) {
+bufferStore::bufferStore(const bufferStore &a)
+ : start(0)
+{
lenAllocd = (a.getLen() > MIN_LEN) ? a.getLen() : MIN_LEN;
buff = (unsigned char *)malloc(lenAllocd);
+ assert(buff);
len = a.getLen();
memcpy(buff, a.getString(0), len);
- start = 0;
}
-bufferStore::bufferStore(const unsigned char *_buff, long _len) {
+bufferStore::bufferStore(const unsigned char *_buff, long _len)
+ : start(0)
+{
lenAllocd = (_len > MIN_LEN) ? _len : MIN_LEN;
buff = (unsigned char *)malloc(lenAllocd);
+ assert(buff);
len = _len;
memcpy(buff, _buff, len);
- start = 0;
}
bufferStore &bufferStore::operator =(const bufferStore &a) {
@@ -77,8 +86,8 @@ void bufferStore::init(const unsigned char *_buff, long _len) {
}
bufferStore::~bufferStore() {
- if (buff != 0L)
- free(buff);
+ if (buff)
+ ::free(buff);
}
unsigned long bufferStore::getLen() const {
@@ -133,7 +142,9 @@ void bufferStore::checkAllocd(long newLen) {
do {
lenAllocd = (lenAllocd < MIN_LEN) ? MIN_LEN : (lenAllocd * 2);
} while (newLen >= lenAllocd);
+ assert(lenAllocd);
buff = (unsigned char *)realloc(buff, lenAllocd);
+ assert(buff);
}
}
@@ -190,6 +201,20 @@ void bufferStore::truncate(long newLen) {
len = newLen;
}
+void bufferStore::prependByte(unsigned char cc) {
+ checkAllocd(len + 1);
+ memmove(&buff[1], buff, len++);
+ buff[0] = cc;
+}
+
+void bufferStore::prependWord(int a) {
+ checkAllocd(len + 2);
+ memmove(&buff[2], buff, len);
+ len += 2;
+ buff[0] = a & 0xff;
+ buff[1] = (a>>8) & 0xff;
+}
+
/*
* Local variables:
* c-basic-offset: 4