summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/atom.h2
-rw-r--r--src/bzip2.cpp1
-rw-r--r--src/client.cpp3
-rw-r--r--src/exceptionbase.cpp6
-rw-r--r--src/exceptionbase.h6
-rw-r--r--src/exceptions.cpp21
-rw-r--r--src/exceptions.h40
-rw-r--r--src/fifo.cpp3
-rw-r--r--src/fifo.h3
-rw-r--r--src/file.cpp3
-rw-r--r--src/file.h3
-rw-r--r--src/minimacro.cpp1
-rw-r--r--src/nids.cpp106
-rw-r--r--src/nids.h34
-rw-r--r--src/nidsstream.cpp95
-rw-r--r--src/nidsstream.h13
-rw-r--r--src/plugger.cpp2
-rw-r--r--src/plugger.h4
-rw-r--r--src/serversocket.cpp19
-rw-r--r--src/serversocket.h3
-rw-r--r--src/socket.cpp27
-rw-r--r--src/socket.h15
-rw-r--r--src/tafnode.cpp2
-rw-r--r--src/tafnode.h2
-rw-r--r--src/tafreader.cpp1
-rw-r--r--src/tests/nids.cpp10
-rw-r--r--src/unit/file.cpp1
-rw-r--r--src/xmlreader.cpp3
-rw-r--r--src/xmlreader.h3
29 files changed, 297 insertions, 135 deletions
diff --git a/src/atom.h b/src/atom.h
index 2655e2b..17c0d87 100644
--- a/src/atom.h
+++ b/src/atom.h
@@ -10,7 +10,7 @@
10 10
11#include <stdint.h> 11#include <stdint.h>
12#include <memory> 12#include <memory>
13#include "bu/exceptions.h" 13#include "bu/exceptionbase.h"
14 14
15namespace Bu 15namespace Bu
16{ 16{
diff --git a/src/bzip2.cpp b/src/bzip2.cpp
index c6742f2..10cfe8a 100644
--- a/src/bzip2.cpp
+++ b/src/bzip2.cpp
@@ -6,7 +6,6 @@
6 */ 6 */
7 7
8#include "bu/bzip2.h" 8#include "bu/bzip2.h"
9#include "bu/exceptions.h"
10#include "bu/trace.h" 9#include "bu/trace.h"
11 10
12using namespace Bu; 11using namespace Bu;
diff --git a/src/client.cpp b/src/client.cpp
index fb56e2c..0ab0618 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -9,7 +9,6 @@
9#include "bu/socket.h" 9#include "bu/socket.h"
10#include <stdlib.h> 10#include <stdlib.h>
11#include <errno.h> 11#include <errno.h>
12#include "bu/exceptions.h"
13#include "bu/protocol.h" 12#include "bu/protocol.h"
14#include "bu/clientlink.h" 13#include "bu/clientlink.h"
15#include "bu/clientlinkfactory.h" 14#include "bu/clientlinkfactory.h"
@@ -53,7 +52,7 @@ void Bu::Client::processInput()
53 break; 52 break;
54 } 53 }
55 } 54 }
56 catch( ConnectionException &e ) 55 catch( Bu::SocketException &e )
57 { 56 {
58 pSocket->close(); 57 pSocket->close();
59 bWantsDisconnect = true; 58 bWantsDisconnect = true;
diff --git a/src/exceptionbase.cpp b/src/exceptionbase.cpp
index 9515e2d..207fa47 100644
--- a/src/exceptionbase.cpp
+++ b/src/exceptionbase.cpp
@@ -38,6 +38,7 @@ Bu::ExceptionBase::ExceptionBase( int nCode ) throw() :
38} 38}
39 39
40Bu::ExceptionBase::ExceptionBase( const ExceptionBase &e ) throw () : 40Bu::ExceptionBase::ExceptionBase( const ExceptionBase &e ) throw () :
41 std::exception( e ),
41 nErrorCode( e.nErrorCode ), 42 nErrorCode( e.nErrorCode ),
42 sWhat( NULL ) 43 sWhat( NULL )
43{ 44{
@@ -83,3 +84,8 @@ int Bu::ExceptionBase::getErrorCode()
83 return nErrorCode; 84 return nErrorCode;
84} 85}
85 86
87
88namespace Bu
89{
90 subExceptionDef( UnsupportedException )
91}
diff --git a/src/exceptionbase.h b/src/exceptionbase.h
index 37f4418..6402481 100644
--- a/src/exceptionbase.h
+++ b/src/exceptionbase.h
@@ -178,4 +178,10 @@ name::name( const name &e ) throw() : \
178{ \ 178{ \
179} 179}
180 180
181namespace Bu
182{
183 // Exceptions that are so general they could be used anywhere go here.
184 subExceptionDecl( UnsupportedException )
185}
186
181#endif 187#endif
diff --git a/src/exceptions.cpp b/src/exceptions.cpp
deleted file mode 100644
index 5d6deeb..0000000
--- a/src/exceptions.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
1/*
2 * Copyright (C) 2007-2008 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#include "exceptions.h"
9#include <stdarg.h>
10
11namespace Bu
12{
13 subExceptionDef( XmlException )
14 subExceptionDef( TafException )
15 subExceptionDef( FileException )
16 subExceptionDef( FifoException )
17 subExceptionDef( SocketException )
18 subExceptionDef( ConnectionException )
19 subExceptionDef( PluginException )
20 subExceptionDef( UnsupportedException )
21}
diff --git a/src/exceptions.h b/src/exceptions.h
deleted file mode 100644
index 91e0e6d..0000000
--- a/src/exceptions.h
+++ /dev/null
@@ -1,40 +0,0 @@
1/*
2 * Copyright (C) 2007-2008 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#ifndef BU_EXCEPTIONS_H
9#define BU_EXCEPTIONS_H
10
11#include "bu/exceptionbase.h"
12#include <stdarg.h>
13
14namespace Bu
15{
16 subExceptionDecl( XmlException )
17 subExceptionDecl( TafException )
18 subExceptionDecl( FileException )
19 subExceptionDecl( FifoException )
20 subExceptionDecl( SocketException )
21 subExceptionDecl( ConnectionException )
22 subExceptionDecl( PluginException )
23 subExceptionDecl( UnsupportedException )
24
25 enum eFileException
26 {
27 excodeEOF
28 };
29
30 enum eConnectionException
31 {
32 excodeReadError,
33 excodeWriteError,
34 excodeBadReadError,
35 excodeConnectionClosed,
36 excodeSocketTimeout
37 };
38}
39
40#endif
diff --git a/src/fifo.cpp b/src/fifo.cpp
index f909e61..3f27b2c 100644
--- a/src/fifo.cpp
+++ b/src/fifo.cpp
@@ -6,12 +6,13 @@
6 */ 6 */
7 7
8#include "fifo.h" 8#include "fifo.h"
9#include "exceptions.h"
10#include <errno.h> 9#include <errno.h>
11#include <sys/types.h> 10#include <sys/types.h>
12#include <sys/stat.h> 11#include <sys/stat.h>
13#include <fcntl.h> 12#include <fcntl.h>
14 13
14namespace Bu { subExceptionDef( FifoException ) }
15
15Bu::Fifo::Fifo( const Bu::FString &sName, int iFlags, mode_t mAcc ) : 16Bu::Fifo::Fifo( const Bu::FString &sName, int iFlags, mode_t mAcc ) :
16 iFlags( iFlags ), 17 iFlags( iFlags ),
17 iIn( -1 ), 18 iIn( -1 ),
diff --git a/src/fifo.h b/src/fifo.h
index 4989839..2da5f16 100644
--- a/src/fifo.h
+++ b/src/fifo.h
@@ -14,9 +14,12 @@
14 14
15#include "bu/stream.h" 15#include "bu/stream.h"
16#include "bu/fstring.h" 16#include "bu/fstring.h"
17#include "bu/exceptionbase.h"
17 18
18namespace Bu 19namespace Bu
19{ 20{
21 subExceptionDecl( FifoException );
22
20 /** 23 /**
21 * A fifo stream. 24 * A fifo stream.
22 *@ingroup Streams 25 *@ingroup Streams
diff --git a/src/file.cpp b/src/file.cpp
index b3bae96..3419216 100644
--- a/src/file.cpp
+++ b/src/file.cpp
@@ -6,12 +6,13 @@
6 */ 6 */
7 7
8#include "file.h" 8#include "file.h"
9#include "exceptions.h"
10#include <errno.h> 9#include <errno.h>
11#include <sys/types.h> 10#include <sys/types.h>
12#include <sys/stat.h> 11#include <sys/stat.h>
13#include <fcntl.h> 12#include <fcntl.h>
14 13
14namespace Bu { subExceptionDef( FileException ) }
15
15Bu::File::File( const char *sName, const char *sFlags ) 16Bu::File::File( const char *sName, const char *sFlags )
16{ 17{
17 fh = fopen( sName, sFlags ); 18 fh = fopen( sName, sFlags );
diff --git a/src/file.h b/src/file.h
index 554ebc9..e48e6f1 100644
--- a/src/file.h
+++ b/src/file.h
@@ -14,9 +14,12 @@
14 14
15#include "bu/stream.h" 15#include "bu/stream.h"
16#include "bu/fstring.h" 16#include "bu/fstring.h"
17#include "bu/exceptionbase.h"
17 18
18namespace Bu 19namespace Bu
19{ 20{
21 subExceptionDecl( FileException );
22
20 /** 23 /**
21 * A file stream. 24 * A file stream.
22 *@ingroup Streams 25 *@ingroup Streams
diff --git a/src/minimacro.cpp b/src/minimacro.cpp
index 6fc5382..b97cefc 100644
--- a/src/minimacro.cpp
+++ b/src/minimacro.cpp
@@ -6,7 +6,6 @@
6 */ 6 */
7 7
8#include "bu/minimacro.h" 8#include "bu/minimacro.h"
9#include "bu/exceptions.h"
10 9
11Bu::MiniMacro::MiniMacro() 10Bu::MiniMacro::MiniMacro()
12{ 11{
diff --git a/src/nids.cpp b/src/nids.cpp
index 41c4dc1..d0cb843 100644
--- a/src/nids.cpp
+++ b/src/nids.cpp
@@ -3,9 +3,20 @@
3#include "bu/nidsstream.h" 3#include "bu/nidsstream.h"
4#include <stdio.h> 4#include <stdio.h>
5 5
6#define NIDS_MAGIC_CODE "\xFF\xC3\x99\xBD"
7
8namespace Bu
9{
10 subExceptionDef( NidsException )
11}
12
6Bu::Nids::Nids( Bu::Stream &sStore ) : 13Bu::Nids::Nids( Bu::Stream &sStore ) :
7 sStore( sStore ) 14 sStore( sStore ),
15 iBlockSize( 0 ),
16 iBlocks( 0 ),
17 iBlockStart( -1 )
8{ 18{
19 printf("blockUnused = %u\n", blockUnused );
9 printf("Stream caps:\n" 20 printf("Stream caps:\n"
10 " canRead: %s\n" 21 " canRead: %s\n"
11 " canWrite: %s\n" 22 " canWrite: %s\n"
@@ -25,19 +36,32 @@ Bu::Nids::Nids( Bu::Stream &sStore ) :
25 sStore.isOpen()?"yes":"no" 36 sStore.isOpen()?"yes":"no"
26 ); 37 );
27 printf("sizeof(Block) = %db\n", sizeof(Block) ); 38 printf("sizeof(Block) = %db\n", sizeof(Block) );
39
40
28} 41}
29 42
30Bu::Nids::~Nids() 43Bu::Nids::~Nids()
31{ 44{
32} 45}
33 46
47void Bu::Nids::initialize()
48{
49 char buf[4];
50 sStore.read( buf, 4 );
51 if( memcmp( buf, NIDS_MAGIC_CODE, 4 ) )
52 {
53 throw NidsException(
54 "Stream does not appear to be a valid NIDS format.");
55 }
56}
57
34void Bu::Nids::initialize( int iBlockSize, int iPreAllocate ) 58void Bu::Nids::initialize( int iBlockSize, int iPreAllocate )
35{ 59{
36 char cBuf = 0; 60 char cBuf = 0;
37 int iBuf = 0; 61 int iBuf = 0;
38 62
39 // Magic number 63 // Magic number
40 sStore.write( "\xFF\xC3\x99\xBD", 4 ); 64 sStore.write( NIDS_MAGIC_CODE, 4 );
41 65
42 // Version (0) 66 // Version (0)
43 sStore.write( &cBuf, 1 ); 67 sStore.write( &cBuf, 1 );
@@ -59,56 +83,112 @@ void Bu::Nids::initialize( int iBlockSize, int iPreAllocate )
59 this->iBlockSize = iBlockSize; 83 this->iBlockSize = iBlockSize;
60 this->iBlocks = iPreAllocate; 84 this->iBlocks = iPreAllocate;
61 this->iBlockStart = sStore.tell(); 85 this->iBlockStart = sStore.tell();
86 printf("iBlockStart = %d\n", this->iBlockStart );
62 bsBlockUsed.setSize( iPreAllocate, true ); 87 bsBlockUsed.setSize( iPreAllocate, true );
63 88
64 printf("%d blocks, %db each, %db block offset\n", 89 printf("%d blocks, %db each, %db block offset\n",
65 iBlocks, iBlockSize, iBlockStart ); 90 iBlocks, iBlockSize, iBlockStart );
66 91
67 char *block = new char[iBlockSize]; 92 Block *block = (Block *)new char[iBlockSize];
68 memset( block, 0, iBlockSize ); 93 memset( block, 0, iBlockSize );
94 block->uFirstBlock = block->uNextBlock = block->uPrevBlock = blockUnused;
69 for( int j = 0; j < iPreAllocate; j++ ) 95 for( int j = 0; j < iPreAllocate; j++ )
70 { 96 {
71 sStore.write( block, iBlockSize ); 97 sStore.write( block, iBlockSize );
72 } 98 }
99 delete[] (char *)block;
73} 100}
74 101
75int Bu::Nids::createStream( int iPreAllocate ) 102uint32_t Bu::Nids::createBlock( uint32_t uFirstBlock, uint32_t uPrevBlock,
103 int /*iPreAllocate*/ )
76{ 104{
77 for( int j = 0; j < iBlocks; j++ ) 105 for( int j = 0; j < iBlocks; j++ )
78 { 106 {
79 if( !bsBlockUsed.getBit( j ) ) 107 if( !bsBlockUsed.getBit( j ) )
80 { 108 {
81 Block b = { j, blockUnused, blockUnused, 0, 0 }; 109 Block b = { j, blockUnused, uPrevBlock, 0, 0, { } };
110 if( uFirstBlock != blockUnused )
111 b.uFirstBlock = uFirstBlock;
82 bsBlockUsed.setBit( j ); 112 bsBlockUsed.setBit( j );
83 sStore.setPos( iBlockStart+(iBlockSize*j) ); 113 sStore.setPos( iBlockStart+(iBlockSize*j) );
84 sStore.write( &b, sizeof(b) ); 114 sStore.write( &b, sizeof(b) );
115 return j;
85 } 116 }
86 } 117 }
87 return 0; 118 return blockUnused;
88} 119}
89 120
90void Bu::Nids::deleteStream( int iID ) 121int Bu::Nids::createStream( int iPreAllocate )
122{
123 return createBlock( blockUnused, blockUnused, iPreAllocate );
124}
125
126void Bu::Nids::deleteStream( int /*iID*/ )
91{ 127{
92} 128}
93 129
94Bu::NidsStream Bu::Nids::openStream( int iID ) 130Bu::NidsStream Bu::Nids::openStream( int iID )
95{ 131{
96 return NidsStream( *this ); 132 if( iBlockStart < 0 )
133 {
134 initialize();
135 }
136 return NidsStream( *this, iID );
97} 137}
98 138
99void Bu::Nids::extendStream( int iID, int iBlockCount ) 139int Bu::Nids::getBlockSize()
100{ 140{
141 return iBlockSize;
101} 142}
143/*
144void Bu::Nids::extendStream( int iID, int iBlockCount )
145{
146}*/
102 147
103void Bu::Nids::getBlock( int iIndex, Bu::Nids::Block *pBlock ) 148void Bu::Nids::getBlock( uint32_t uIndex, Bu::Nids::Block *pBlock )
104{ 149{
105 sStore.setPos( iBlockStart + (iBlockSize*iIndex) ); 150 sStore.setPos( iBlockStart + (iBlockSize*uIndex) );
106 sStore.read( pBlock, iBlockSize ); 151 sStore.read( pBlock, iBlockSize );
107} 152}
108 153
109void Bu::Nids::setBlock( int iIndex, Bu::Nids::Block *pBlock ) 154void Bu::Nids::setBlock( uint32_t uIndex, Bu::Nids::Block *pBlock )
110{ 155{
111 sStore.setPos( iBlockStart + (iBlockSize*iIndex) ); 156 sStore.setPos( iBlockStart + (iBlockSize*uIndex) );
112 sStore.write( pBlock, iBlockSize ); 157 sStore.write( pBlock, iBlockSize );
113} 158}
114 159
160void Bu::Nids::updateStreamSize( uint32_t uIndex, uint32_t uSize )
161{
162 sStore.setPos( iBlockStart + (iBlockSize*uIndex)+4*3 );
163 sStore.write( &uSize, 4 );
164}
165
166uint32_t Bu::Nids::getNextBlock( uint32_t uIndex,
167 struct Bu::Nids::Block *pBlock )
168{
169 uint32_t uNew;
170 if( pBlock->uNextBlock == blockUnused )
171 {
172 uNew = createBlock( pBlock->uFirstBlock, uIndex );
173 sStore.setPos( iBlockStart + (iBlockSize*uIndex)+1*4 );
174 sStore.write( &uNew, 4 );
175 getBlock( uNew, pBlock );
176 }
177 else
178 {
179 uNew = pBlock->uNextBlock;
180 getBlock( pBlock->uNextBlock, pBlock );
181 }
182 return uNew;
183}
184
185Bu::Nids::Block *Bu::Nids::newBlock()
186{
187 return (Block *)new char[iBlockSize];
188}
189
190void Bu::Nids::deleteBlock( Block *pBlock )
191{
192 delete[] (char *)pBlock;
193}
194
diff --git a/src/nids.h b/src/nids.h
index e364289..cdefdcb 100644
--- a/src/nids.h
+++ b/src/nids.h
@@ -3,12 +3,15 @@
3 3
4#include <stdint.h> 4#include <stdint.h>
5#include "bu/bitstring.h" 5#include "bu/bitstring.h"
6#include "bu/exceptionbase.h"
6 7
7namespace Bu 8namespace Bu
8{ 9{
9 class Stream; 10 class Stream;
10 class NidsStream; 11 class NidsStream;
11 12
13 subExceptionDecl( NidsException )
14
12 /** 15 /**
13 * Numerically Indexed Data Streams. This is a working name so I can 16 * Numerically Indexed Data Streams. This is a working name so I can
14 * actually get some code written instead of agonizing over the name. 17 * actually get some code written instead of agonizing over the name.
@@ -24,6 +27,14 @@ namespace Bu
24 virtual ~Nids(); 27 virtual ~Nids();
25 28
26 /** 29 /**
30 * Initialize this object based on the data already in the assosiated
31 * stream. This will be called automatically for you if you forget,
32 * but if you want to pre-initialize for some reason, just call this
33 * once before you actually start doing anything with your Nids.
34 */
35 void initialize();
36
37 /**
27 * Create a new Nids system in the assosiated stream. This should be 38 * Create a new Nids system in the assosiated stream. This should be
28 * used carefully, it will destroy all data already within the stream. 39 * used carefully, it will destroy all data already within the stream.
29 * More options will probably be added soon. 40 * More options will probably be added soon.
@@ -46,14 +57,16 @@ namespace Bu
46 */ 57 */
47 NidsStream openStream( int iID ); 58 NidsStream openStream( int iID );
48 59
60 int getBlockSize();
61
49 private: 62 private:
50 typedef struct Block 63 typedef struct Block
51 { 64 {
52 uint32_t iFirstBlock; 65 uint32_t uFirstBlock;
53 uint32_t iNextBlock; 66 uint32_t uNextBlock;
54 uint32_t iPrevBlock; 67 uint32_t uPrevBlock;
55 uint32_t iBytesUsed; 68 uint32_t uBytesUsed;
56 uint32_t iReserved; 69 uint32_t uReserved;
57 unsigned char pData[0]; 70 unsigned char pData[0];
58 } Block; 71 } Block;
59 72
@@ -62,9 +75,14 @@ namespace Bu
62 blockUnused = 0xFFFFFFFFUL 75 blockUnused = 0xFFFFFFFFUL
63 }; 76 };
64 77
65 void extendStream( int iID, int iBlockCount=1 ); 78 uint32_t createBlock( uint32_t uFirstBlock, uint32_t uPrevBlock,
66 void getBlock( int iIndex, struct Nids::Block *pBlock ); 79 int iPreAllocate=1 );
67 void setBlock( int iIndex, struct Nids::Block *pBlock ); 80 void getBlock( uint32_t uIndex, struct Nids::Block *pBlock );
81 void setBlock( uint32_t uIndex, struct Nids::Block *pBlock );
82 void updateStreamSize( uint32_t uIndex, uint32_t uSize );
83 uint32_t getNextBlock( uint32_t uIndex, struct Nids::Block *pBlock );
84 Block *newBlock();
85 void deleteBlock( Block *pBlock );
68 86
69 private: 87 private:
70 Bu::Stream &sStore; 88 Bu::Stream &sStore;
diff --git a/src/nidsstream.cpp b/src/nidsstream.cpp
index 2f24d69..740dc1f 100644
--- a/src/nidsstream.cpp
+++ b/src/nidsstream.cpp
@@ -1,20 +1,41 @@
1#include "bu/nidsstream.h" 1#include "bu/nidsstream.h"
2 2
3Bu::NidsStream::NidsStream( Nids &rNids ) : 3Bu::NidsStream::NidsStream( Nids &rNids, uint32_t uStream ) :
4 rNids( rNids ), 4 rNids( rNids ),
5 iPos( 0 ) 5 uStream( uStream ),
6 pCurBlock( NULL ),
7 uCurBlock( uStream ),
8 uSize( 0 ),
9 uBlockSize( rNids.iBlockSize-sizeof(Nids::Block) ),
10 uPos( 0 )
6{ 11{
12 printf("NidsStream::allocated\n");
13 pCurBlock = rNids.newBlock();
14 rNids.getBlock( uStream, pCurBlock );
15 uSize = pCurBlock->uBytesUsed;
7} 16}
8 17
18/*
9Bu::NidsStream::NidsStream( const Bu::NidsStream &rSrc ) : 19Bu::NidsStream::NidsStream( const Bu::NidsStream &rSrc ) :
20 Stream( rSrc ),
10 rNids( rSrc.rNids ), 21 rNids( rSrc.rNids ),
11 iPos( 0 ) 22 uStream( rSrc.uStream ),
12{ 23 pCurBlock( NULL ),
13 24 uCurBlock( uStream ),
14} 25 uSize( 0 ),
26 uBlockSize( rSrc.uBlockSize ),
27 iUsable( uBlockSize-sizeof(Nids::Block) ),
28 uPos( 0 )
29{
30 printf("NidsStream::copied\n");
31 pCurBlock = rNids.newBlock();
32 rNids.getBlock( uStream, pCurBlock );
33}*/
15 34
16Bu::NidsStream::~NidsStream() 35Bu::NidsStream::~NidsStream()
17{ 36{
37 rNids.updateStreamSize( uStream, uSize );
38 rNids.deleteBlock( pCurBlock );
18} 39}
19 40
20void Bu::NidsStream::close() 41void Bu::NidsStream::close()
@@ -23,29 +44,85 @@ void Bu::NidsStream::close()
23 44
24size_t Bu::NidsStream::read( void *pBuf, size_t nBytes ) 45size_t Bu::NidsStream::read( void *pBuf, size_t nBytes )
25{ 46{
47 if( uPos%uBlockSize+nBytes < uBlockSize )
48 {
49 size_t iRead = nBytes;
50 if( iRead > pCurBlock->uBytesUsed )
51 iRead = pCurBlock->uBytesUsed;
52 memcpy( pBuf, pCurBlock->pData+(uPos%uBlockSize), iRead );
53 uPos += nBytes;
54 printf("a: block %u = %ub (%ub total)\n",
55 uCurBlock, pCurBlock->uBytesUsed, uSize );
56 return iRead;
57 }
58 else
59 {
60 //size_t iTotal = 0;
61 for(;;)
62 {
63
64 }
65 }
26 return 0; 66 return 0;
27} 67}
28 68
29size_t Bu::NidsStream::write( const void *pBuf, size_t nBytes ) 69size_t Bu::NidsStream::write( const void *pBuf, size_t nBytes )
30{ 70{
31 return 0; 71 if( uPos%uBlockSize+nBytes < uBlockSize )
72 {
73 memcpy( pCurBlock->pData+(uPos%uBlockSize), pBuf, nBytes );
74 pCurBlock->uBytesUsed += nBytes;
75 rNids.setBlock( uCurBlock, pCurBlock );
76 uPos += nBytes;
77 uSize += nBytes;
78 printf("a: block %u = %ub (%ub total)\n",
79 uCurBlock, pCurBlock->uBytesUsed, uSize );
80 return nBytes;
81 }
82 else
83 {
84 size_t nTotal = 0;
85 for(;;)
86 {
87 uint32_t uNow = uBlockSize-(uPos%uBlockSize);
88 if( nBytes < uNow )
89 uNow = nBytes;
90 memcpy( pCurBlock->pData+(uPos%uBlockSize),
91 &((char *)pBuf)[nTotal], uNow );
92 pCurBlock->uBytesUsed += uNow;
93 rNids.setBlock( uCurBlock, pCurBlock );
94 uSize += uNow;
95 uPos += uNow;
96 nTotal += uNow;
97 nBytes -= uNow;
98 printf("b: block %u = %ub (%ub total)\n",
99 uCurBlock, pCurBlock->uBytesUsed, uSize );
100 if( nBytes == 0 )
101 return nTotal;
102 if( pCurBlock->uBytesUsed == uBlockSize )
103 uCurBlock = rNids.getNextBlock( uCurBlock, pCurBlock );
104 }
105 }
32} 106}
33 107
34long Bu::NidsStream::tell() 108long Bu::NidsStream::tell()
35{ 109{
36 return 0; 110 return uPos;
37} 111}
38 112
39void Bu::NidsStream::seek( long offset ) 113void Bu::NidsStream::seek( long offset )
40{ 114{
115 uPos += offset;
41} 116}
42 117
43void Bu::NidsStream::setPos( long pos ) 118void Bu::NidsStream::setPos( long pos )
44{ 119{
120 uPos = pos;
45} 121}
46 122
47void Bu::NidsStream::setPosEnd( long pos ) 123void Bu::NidsStream::setPosEnd( long pos )
48{ 124{
125 uPos = uSize-pos-1;
49} 126}
50 127
51bool Bu::NidsStream::isEOS() 128bool Bu::NidsStream::isEOS()
@@ -92,7 +169,7 @@ bool Bu::NidsStream::isBlocking()
92 return true; 169 return true;
93} 170}
94 171
95void Bu::NidsStream::setBlocking( bool bBlocking ) 172void Bu::NidsStream::setBlocking( bool /*bBlocking*/ )
96{ 173{
97} 174}
98 175
diff --git a/src/nidsstream.h b/src/nidsstream.h
index f64fca4..c220e5c 100644
--- a/src/nidsstream.h
+++ b/src/nidsstream.h
@@ -13,10 +13,10 @@ namespace Bu
13 /** 13 /**
14 * These can only be created by the Nids class. 14 * These can only be created by the Nids class.
15 */ 15 */
16 NidsStream( Nids &rNids ); 16 NidsStream( Nids &rNids, uint32_t uStream );
17 17
18 public: 18 public:
19 NidsStream( const NidsStream &rSrc ); 19// NidsStream( const NidsStream &rSrc );
20 virtual ~NidsStream(); 20 virtual ~NidsStream();
21 21
22 virtual void close(); 22 virtual void close();
@@ -40,9 +40,12 @@ namespace Bu
40 40
41 private: 41 private:
42 Nids &rNids; 42 Nids &rNids;
43 typedef struct Bu::Hash<int, struct Nids::Block *> BlockHash; 43 uint32_t uStream;
44 BlockHash hBlock; 44 Nids::Block *pCurBlock;
45 long iPos; 45 uint32_t uCurBlock;
46 uint32_t uSize;
47 uint32_t uBlockSize;
48 uint32_t uPos;
46 }; 49 };
47}; 50};
48 51
diff --git a/src/plugger.cpp b/src/plugger.cpp
index d891174..6ff31c4 100644
--- a/src/plugger.cpp
+++ b/src/plugger.cpp
@@ -6,3 +6,5 @@
6 */ 6 */
7 7
8#include "plugger.h" 8#include "plugger.h"
9
10namespace Bu { subExceptionDef( PluginException ) }
diff --git a/src/plugger.h b/src/plugger.h
index 6ae0296..746f5ac 100644
--- a/src/plugger.h
+++ b/src/plugger.h
@@ -12,12 +12,14 @@
12#include "bu/hash.h" 12#include "bu/hash.h"
13#include "bu/list.h" 13#include "bu/list.h"
14#include <dlfcn.h> 14#include <dlfcn.h>
15#include "bu/exceptions.h" 15#include "bu/exceptionbase.h"
16#include "bu/fstring.h" 16#include "bu/fstring.h"
17#include <stddef.h> 17#include <stddef.h>
18 18
19namespace Bu 19namespace Bu
20{ 20{
21 subExceptionDecl( PluginException );
22
21 typedef struct PluginInfo 23 typedef struct PluginInfo
22 { 24 {
23 const char *sID; 25 const char *sID;
diff --git a/src/serversocket.cpp b/src/serversocket.cpp
index 30f584d..6f7fc00 100644
--- a/src/serversocket.cpp
+++ b/src/serversocket.cpp
@@ -18,9 +18,10 @@
18#include <netdb.h> 18#include <netdb.h>
19#include <arpa/inet.h> 19#include <arpa/inet.h>
20#include <fcntl.h> 20#include <fcntl.h>
21#include "serversocket.h" 21#include "bu/serversocket.h"
22#include "exceptions.h" 22#include "bu/osx_compatibility.h"
23#include "osx_compatibility.h" 23
24namespace Bu { subExceptionDef( ServerSocketException ) }
24 25
25Bu::ServerSocket::ServerSocket( int nPort, int nPoolSize ) : 26Bu::ServerSocket::ServerSocket( int nPort, int nPoolSize ) :
26 nPort( nPort ) 27 nPort( nPort )
@@ -64,7 +65,7 @@ void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize )
64 nServer = socket( PF_INET, SOCK_STREAM, 0 ); 65 nServer = socket( PF_INET, SOCK_STREAM, 0 );
65 if( nServer < 0 ) 66 if( nServer < 0 )
66 { 67 {
67 throw Bu::SocketException("Couldn't create a listen socket."); 68 throw Bu::ServerSocketException("Couldn't create a listen socket.");
68 } 69 }
69 70
70 int opt = 1; 71 int opt = 1;
@@ -78,12 +79,12 @@ void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize )
78 79
79 if( bind( nServer, (struct sockaddr *) &name, sizeof(name) ) < 0 ) 80 if( bind( nServer, (struct sockaddr *) &name, sizeof(name) ) < 0 )
80 { 81 {
81 throw Bu::SocketException("Couldn't bind to the listen socket."); 82 throw Bu::ServerSocketException("Couldn't bind to the listen socket.");
82 } 83 }
83 84
84 if( listen( nServer, nPoolSize ) < 0 ) 85 if( listen( nServer, nPoolSize ) < 0 )
85 { 86 {
86 throw Bu::SocketException( 87 throw Bu::ServerSocketException(
87 "Couldn't begin listening to the server socket." 88 "Couldn't begin listening to the server socket."
88 ); 89 );
89 } 90 }
@@ -109,7 +110,7 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec )
109 110
110 if( TEMP_FAILURE_RETRY(select( nServer+1, &fdRead, NULL, NULL, &xT )) < 0 ) 111 if( TEMP_FAILURE_RETRY(select( nServer+1, &fdRead, NULL, NULL, &xT )) < 0 )
111 { 112 {
112 throw SocketException( 113 throw Bu::ServerSocketException(
113 "Error scanning for new connections: %s", strerror( errno ) 114 "Error scanning for new connections: %s", strerror( errno )
114 ); 115 );
115 } 116 }
@@ -134,7 +135,7 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec )
134#endif /* __CYGWIN__ */ 135#endif /* __CYGWIN__ */
135 if( nClient < 0 ) 136 if( nClient < 0 )
136 { 137 {
137 throw SocketException( 138 throw Bu::ServerSocketException(
138 "Error accepting a new connection: %s", strerror( errno ) 139 "Error accepting a new connection: %s", strerror( errno )
139 ); 140 );
140 } 141 }
@@ -150,7 +151,7 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec )
150 flags |= O_NONBLOCK; 151 flags |= O_NONBLOCK;
151 if( fcntl( nClient, F_SETFL, flags ) < 0) 152 if( fcntl( nClient, F_SETFL, flags ) < 0)
152 { 153 {
153 throw SocketException( 154 throw Bu::ServerSocketException(
154 "Error setting option on client socket: %s", 155 "Error setting option on client socket: %s",
155 strerror( errno ) 156 strerror( errno )
156 ); 157 );
diff --git a/src/serversocket.h b/src/serversocket.h
index 8267cea..1742786 100644
--- a/src/serversocket.h
+++ b/src/serversocket.h
@@ -10,10 +10,13 @@
10 10
11#include <stdint.h> 11#include <stdint.h>
12#include "bu/fstring.h" 12#include "bu/fstring.h"
13#include "bu/exceptionbase.h"
13#include <sys/select.h> 14#include <sys/select.h>
14 15
15namespace Bu 16namespace Bu
16{ 17{
18 subExceptionDecl( ServerSocketException );
19
17 /** 20 /**
18 * A single tcp/ip server socket. When created the server socket will bind 21 * A single tcp/ip server socket. When created the server socket will bind
19 * to the specified interface and port, and immediately begin listening for 22 * to the specified interface and port, and immediately begin listening for
diff --git a/src/socket.cpp b/src/socket.cpp
index 651a2e1..531d8ac 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -19,11 +19,12 @@
19#include <errno.h> 19#include <errno.h>
20#include <fcntl.h> 20#include <fcntl.h>
21#include "socket.h" 21#include "socket.h"
22#include "exceptions.h"
23#include "osx_compatibility.h" 22#include "osx_compatibility.h"
24 23
25#define RBS (1024*2) 24#define RBS (1024*2)
26 25
26namespace Bu { subExceptionDef( SocketException ) }
27
27Bu::Socket::Socket( int nSocket ) : 28Bu::Socket::Socket( int nSocket ) :
28 nSocket( nSocket ), 29 nSocket( nSocket ),
29 bActive( true ) 30 bActive( true )
@@ -50,7 +51,7 @@ Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout )
50 flags |= O_NONBLOCK; 51 flags |= O_NONBLOCK;
51 if (fcntl(nSocket, F_SETFL, flags) < 0) 52 if (fcntl(nSocket, F_SETFL, flags) < 0)
52 { 53 {
53 throw ExceptionBase("Couldn't set socket options.\n"); 54 throw Bu::SocketException("Couldn't set socket options.\n");
54 } 55 }
55 56
56 /* Connect to the server. */ 57 /* Connect to the server. */
@@ -63,7 +64,7 @@ Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout )
63 hostinfo = gethostbyname( sAddr.getStr() ); 64 hostinfo = gethostbyname( sAddr.getStr() );
64 if (hostinfo == NULL) 65 if (hostinfo == NULL)
65 { 66 {
66 throw ExceptionBase("Couldn't resolve hostname.\n"); 67 throw Bu::SocketException("Couldn't resolve hostname.\n");
67 } 68 }
68 xServerName.sin_addr = *(struct in_addr *) hostinfo->h_addr; 69 xServerName.sin_addr = *(struct in_addr *) hostinfo->h_addr;
69 } 70 }
@@ -136,8 +137,8 @@ void Bu::Socket::read()
136 { 137 {
137 //printf("errno: %d, %s\n", errno, strerror( errno ) ); 138 //printf("errno: %d, %s\n", errno, strerror( errno ) );
138 //perror("readInput"); 139 //perror("readInput");
139 throw ConnectionException( 140 throw SocketException(
140 excodeReadError, 141 SocketException::cRead,
141 "Read error: %s", 142 "Read error: %s",
142 strerror( errno ) 143 strerror( errno )
143 ); 144 );
@@ -162,8 +163,8 @@ void Bu::Socket::read()
162 struct timeval tv = { 0, 0 }; 163 struct timeval tv = { 0, 0 };
163 int retval = select( nSocket+1, &rfds, NULL, NULL, &tv ); 164 int retval = select( nSocket+1, &rfds, NULL, NULL, &tv );
164 if( retval == -1 ) 165 if( retval == -1 )
165 throw ConnectionException( 166 throw SocketException(
166 excodeBadReadError, 167 SocketException::cBadRead,
167 "Bad Read error" 168 "Bad Read error"
168 ); 169 );
169 if( !FD_ISSET( nSocket, &rfds ) ) 170 if( !FD_ISSET( nSocket, &rfds ) )
@@ -178,7 +179,7 @@ size_t Bu::Socket::read( void *pBuf, size_t nBytes )
178 int nRead = TEMP_FAILURE_RETRY( ::read( nSocket, pBuf, nBytes ) ); 179 int nRead = TEMP_FAILURE_RETRY( ::read( nSocket, pBuf, nBytes ) );
179 if( nRead < 0 ) 180 if( nRead < 0 )
180 { 181 {
181 throw ConnectionException( excodeReadError, strerror(errno) ); 182 throw SocketException( SocketException::cRead, strerror(errno) );
182 } 183 }
183 return nRead; 184 return nRead;
184} 185}
@@ -220,7 +221,7 @@ size_t Bu::Socket::write( const void *pBuf, size_t nBytes )
220 if( nWrote < 0 ) 221 if( nWrote < 0 )
221 { 222 {
222 if( errno == EAGAIN ) return 0; 223 if( errno == EAGAIN ) return 0;
223 throw ConnectionException( excodeWriteError, strerror(errno) ); 224 throw SocketException( SocketException::cWrite, strerror(errno) );
224 } 225 }
225 return nWrote; 226 return nWrote;
226} 227}
@@ -288,8 +289,8 @@ bool Bu::Socket::canRead()
288 struct timeval tv = { 0, 0 }; 289 struct timeval tv = { 0, 0 };
289 int retval = select( nSocket+1, &rfds, NULL, NULL, &tv ); 290 int retval = select( nSocket+1, &rfds, NULL, NULL, &tv );
290 if( retval == -1 ) 291 if( retval == -1 )
291 throw ConnectionException( 292 throw SocketException(
292 excodeBadReadError, 293 SocketException::cBadRead,
293 "Bad Read error" 294 "Bad Read error"
294 ); 295 );
295 if( !FD_ISSET( nSocket, &rfds ) ) 296 if( !FD_ISSET( nSocket, &rfds ) )
@@ -305,8 +306,8 @@ bool Bu::Socket::canWrite()
305 struct timeval tv = { 0, 0 }; 306 struct timeval tv = { 0, 0 };
306 int retval = select( nSocket+1, NULL, &wfds, NULL, &tv ); 307 int retval = select( nSocket+1, NULL, &wfds, NULL, &tv );
307 if( retval == -1 ) 308 if( retval == -1 )
308 throw ConnectionException( 309 throw SocketException(
309 excodeBadReadError, 310 SocketException::cBadRead,
310 "Bad Read error" 311 "Bad Read error"
311 ); 312 );
312 if( !FD_ISSET( nSocket, &wfds ) ) 313 if( !FD_ISSET( nSocket, &wfds ) )
diff --git a/src/socket.h b/src/socket.h
index 838dfad..337b797 100644
--- a/src/socket.h
+++ b/src/socket.h
@@ -10,11 +10,22 @@
10 10
11#include <stdint.h> 11#include <stdint.h>
12 12
13#include "stream.h" 13#include "bu/stream.h"
14#include "fstring.h" 14#include "bu/fstring.h"
15#include "bu/exceptionbase.h"
15 16
16namespace Bu 17namespace Bu
17{ 18{
19 subExceptionDeclBegin( SocketException );
20 enum {
21 cRead,
22 cWrite,
23 cBadRead,
24 cClosed,
25 cTimeout
26 };
27 subExceptionDeclEnd();
28
18 /** 29 /**
19 *@author Mike Buland 30 *@author Mike Buland
20 *@ingroup Serving 31 *@ingroup Serving
diff --git a/src/tafnode.cpp b/src/tafnode.cpp
index 35be4ff..128355a 100644
--- a/src/tafnode.cpp
+++ b/src/tafnode.cpp
@@ -7,6 +7,8 @@
7 7
8#include "bu/tafnode.h" 8#include "bu/tafnode.h"
9 9
10namespace Bu { subExceptionDef( TafException ) }
11
10Bu::TafNode::TafNode( NodeType eType ) : 12Bu::TafNode::TafNode( NodeType eType ) :
11 eType( eType ) 13 eType( eType )
12{ 14{
diff --git a/src/tafnode.h b/src/tafnode.h
index fcdfdf5..526ef68 100644
--- a/src/tafnode.h
+++ b/src/tafnode.h
@@ -12,9 +12,11 @@
12#include "bu/fstring.h" 12#include "bu/fstring.h"
13#include "bu/hash.h" 13#include "bu/hash.h"
14#include "bu/list.h" 14#include "bu/list.h"
15#include "bu/exceptionbase.h"
15 16
16namespace Bu 17namespace Bu
17{ 18{
19 subExceptionDecl( TafException );
18 /** 20 /**
19 * 21 *
20 *@ingroup Taf 22 *@ingroup Taf
diff --git a/src/tafreader.cpp b/src/tafreader.cpp
index 282f037..c5ef8cc 100644
--- a/src/tafreader.cpp
+++ b/src/tafreader.cpp
@@ -6,7 +6,6 @@
6 */ 6 */
7 7
8#include "bu/tafreader.h" 8#include "bu/tafreader.h"
9#include "bu/exceptions.h"
10#include "bu/fstring.h" 9#include "bu/fstring.h"
11 10
12#include <stdlib.h> 11#include <stdlib.h>
diff --git a/src/tests/nids.cpp b/src/tests/nids.cpp
index 18f66a6..4856883 100644
--- a/src/tests/nids.cpp
+++ b/src/tests/nids.cpp
@@ -10,15 +10,17 @@ int main( int argc, char *argv[] )
10 return 1; 10 return 1;
11 } 11 }
12 12
13 Bu::File fOut( argv[1], "wb"); 13 Bu::File fOut( argv[1], "wb+");
14 Bu::Nids n( fOut ); 14 Bu::Nids n( fOut );
15 15
16 n.initialize( 1024, 5 ); 16// n.initialize( 120, 5 );
17 17
18 Bu::NidsStream s = n.openStream( n.createStream() ); 18 Bu::NidsStream s = n.openStream( n.createStream() );
19 19/*
20 Bu::FString sBuf("Hey there, man...uh...how's it going?"); 20 Bu::FString sBuf( 350 );
21 memset( sBuf.getStr(), 'a', 350 );
21 s.write( sBuf ); 22 s.write( sBuf );
23 */
22 24
23 return 0; 25 return 0;
24} 26}
diff --git a/src/unit/file.cpp b/src/unit/file.cpp
index 68574ca..a22239d 100644
--- a/src/unit/file.cpp
+++ b/src/unit/file.cpp
@@ -7,7 +7,6 @@
7 7
8#include "bu/unitsuite.h" 8#include "bu/unitsuite.h"
9#include "bu/file.h" 9#include "bu/file.h"
10#include "bu/exceptions.h"
11 10
12#include <sys/types.h> 11#include <sys/types.h>
13#include <sys/stat.h> 12#include <sys/stat.h>
diff --git a/src/xmlreader.cpp b/src/xmlreader.cpp
index 9d299e6..12d8dba 100644
--- a/src/xmlreader.cpp
+++ b/src/xmlreader.cpp
@@ -1,6 +1,7 @@
1#include "bu/xmlreader.h" 1#include "bu/xmlreader.h"
2#include "bu/stream.h" 2#include "bu/stream.h"
3#include "bu/exceptions.h" 3
4namespace Bu { subExceptionDef( XmlException ) }
4 5
5Bu::XmlReader::XmlReader( Stream &rInput ) : 6Bu::XmlReader::XmlReader( Stream &rInput ) :
6 rInput( rInput ), 7 rInput( rInput ),
diff --git a/src/xmlreader.h b/src/xmlreader.h
index 375dfe3..f2d975b 100644
--- a/src/xmlreader.h
+++ b/src/xmlreader.h
@@ -2,11 +2,14 @@
2#define BU_XML_READER_H 2#define BU_XML_READER_H
3 3
4#include "bu/fstring.h" 4#include "bu/fstring.h"
5#include "bu/exceptionbase.h"
5 6
6namespace Bu 7namespace Bu
7{ 8{
8 class Stream; 9 class Stream;
9 10
11 subExceptionDecl( XmlException );
12
10 class XmlReader 13 class XmlReader
11 { 14 {
12 public: 15 public: