diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-01-27 16:54:55 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-01-27 16:54:55 +0000 |
commit | 00bb8c39b97638c872ebccc6aee7f3c5fb57d7d6 (patch) | |
tree | f5e127d2e169a0eb93c66d5c76852303d4a10f0c /src/nidsstream.cpp | |
parent | 9098237f5bb16b204a5ea999b702e5eb170f68ac (diff) | |
download | libbu++-00bb8c39b97638c872ebccc6aee7f3c5fb57d7d6.tar.gz libbu++-00bb8c39b97638c872ebccc6aee7f3c5fb57d7d6.tar.bz2 libbu++-00bb8c39b97638c872ebccc6aee7f3c5fb57d7d6.tar.xz libbu++-00bb8c39b97638c872ebccc6aee7f3c5fb57d7d6.zip |
Corrected the Bu::File::canRead() and Bu::File::canWrite() functions, they work
now. It helps to read the system docs. Anyway, nids is all fixed up, it seems
to work great now, and I guess I got all the corner cases we'll hit for a while,
fishtrax really did a number on them :)
I also cleaned up all the debugging output, now you can see your program run
instead of libbu++ internals.
There could still be a good amount of improvement made in nids, it really
shouldn't re-write whole blocks every time you write to a stream, but that will
be an easy change down the line that won't effect any of the existing code.
Diffstat (limited to '')
-rw-r--r-- | src/nidsstream.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/nidsstream.cpp b/src/nidsstream.cpp index fff73f6..31e1293 100644 --- a/src/nidsstream.cpp +++ b/src/nidsstream.cpp | |||
@@ -55,7 +55,7 @@ size_t Bu::NidsStream::read( void *pBuf, size_t nBytes ) | |||
55 | if( iRead > pCurBlock->uBytesUsed-(uPos%uBlockSize) ) | 55 | if( iRead > pCurBlock->uBytesUsed-(uPos%uBlockSize) ) |
56 | iRead = pCurBlock->uBytesUsed-(uPos%uBlockSize); | 56 | iRead = pCurBlock->uBytesUsed-(uPos%uBlockSize); |
57 | memcpy( pBuf, pCurBlock->pData+(uPos%uBlockSize), iRead ); | 57 | memcpy( pBuf, pCurBlock->pData+(uPos%uBlockSize), iRead ); |
58 | //printf("buffill: %ub, %u-%u/%u -> %d-%d/%d (a:%u)", | 58 | //printf("read buffill: %ub, %u-%u/%u -> %d-%d/%d (a:%u)", |
59 | // iRead, uPos, uPos+iRead-1, uSize, 0, iRead-1, nBytes, uCurBlock ); | 59 | // iRead, uPos, uPos+iRead-1, uSize, 0, iRead-1, nBytes, uCurBlock ); |
60 | uPos += iRead; | 60 | uPos += iRead; |
61 | //printf(" -- %u\n", uPos%uBlockSize ); | 61 | //printf(" -- %u\n", uPos%uBlockSize ); |
@@ -80,7 +80,7 @@ size_t Bu::NidsStream::read( void *pBuf, size_t nBytes ) | |||
80 | iRead = pCurBlock->uBytesUsed-(uPos%uBlockSize); | 80 | iRead = pCurBlock->uBytesUsed-(uPos%uBlockSize); |
81 | memcpy( ((char *)pBuf)+nTotal, | 81 | memcpy( ((char *)pBuf)+nTotal, |
82 | pCurBlock->pData+(uPos%uBlockSize), iRead ); | 82 | pCurBlock->pData+(uPos%uBlockSize), iRead ); |
83 | //printf("buffill: %ub, %u-%u/%u -> %d-%d/%d (b:%u)\n", | 83 | //printf(" read buffill: %ub, %u-%u/%u -> %d-%d/%d (b:%u)\n", |
84 | // iRead, uPos, uPos+iRead-1, uSize, | 84 | // iRead, uPos, uPos+iRead-1, uSize, |
85 | // nTotal, nTotal+nBytes-1, nBytes, uCurBlock ); | 85 | // nTotal, nTotal+nBytes-1, nBytes, uCurBlock ); |
86 | uPos += iRead; | 86 | uPos += iRead; |
@@ -111,6 +111,10 @@ size_t Bu::NidsStream::write( const void *pBuf, size_t nBytes ) | |||
111 | { | 111 | { |
112 | //printf("wa: %u:%u:%u:%u -> ", uPos, uPos%uBlockSize, uSize, pCurBlock->uBytesUsed ); | 112 | //printf("wa: %u:%u:%u:%u -> ", uPos, uPos%uBlockSize, uSize, pCurBlock->uBytesUsed ); |
113 | memcpy( pCurBlock->pData+(uPos%uBlockSize), pBuf, nBytes ); | 113 | memcpy( pCurBlock->pData+(uPos%uBlockSize), pBuf, nBytes ); |
114 | //printf("write buffill: %ub, %u-%u/%u -> %d-%d/%d (a:%u:%u)\n", | ||
115 | // nBytes, 0, nBytes-1, nBytes, | ||
116 | // uPos, uPos+nBytes-1, uSize, uCurBlock, | ||
117 | // pCurBlock->uBytesUsed ); | ||
114 | if( (uPos%uBlockSize)+nBytes > pCurBlock->uBytesUsed ) | 118 | if( (uPos%uBlockSize)+nBytes > pCurBlock->uBytesUsed ) |
115 | pCurBlock->uBytesUsed = (uPos%uBlockSize)+nBytes; | 119 | pCurBlock->uBytesUsed = (uPos%uBlockSize)+nBytes; |
116 | rNids.setBlock( uCurBlock, pCurBlock ); | 120 | rNids.setBlock( uCurBlock, pCurBlock ); |
@@ -132,6 +136,9 @@ size_t Bu::NidsStream::write( const void *pBuf, size_t nBytes ) | |||
132 | uNow = nBytes; | 136 | uNow = nBytes; |
133 | memcpy( pCurBlock->pData+(uPos%uBlockSize), | 137 | memcpy( pCurBlock->pData+(uPos%uBlockSize), |
134 | &((char *)pBuf)[nTotal], uNow ); | 138 | &((char *)pBuf)[nTotal], uNow ); |
139 | //printf("write buffill: %ub, %u-%u/%u -> %d-%d/%d (b:%u:%u)\n", | ||
140 | // uNow, nTotal, nTotal+uNow-1, nBytes, | ||
141 | // uPos, uPos+uNow-1, uSize, uCurBlock, pCurBlock->uBytesUsed ); | ||
135 | if( (uPos%uBlockSize)+uNow > pCurBlock->uBytesUsed ) | 142 | if( (uPos%uBlockSize)+uNow > pCurBlock->uBytesUsed ) |
136 | pCurBlock->uBytesUsed = (uPos%uBlockSize)+uNow; | 143 | pCurBlock->uBytesUsed = (uPos%uBlockSize)+uNow; |
137 | rNids.setBlock( uCurBlock, pCurBlock ); | 144 | rNids.setBlock( uCurBlock, pCurBlock ); |
@@ -142,7 +149,8 @@ size_t Bu::NidsStream::write( const void *pBuf, size_t nBytes ) | |||
142 | nBytes -= uNow; | 149 | nBytes -= uNow; |
143 | //printf("wb: block %u = %ub (%ub total)\n", | 150 | //printf("wb: block %u = %ub (%ub total)\n", |
144 | // uCurBlock, pCurBlock->uBytesUsed, uSize ); | 151 | // uCurBlock, pCurBlock->uBytesUsed, uSize ); |
145 | if( pCurBlock->uBytesUsed == uBlockSize ) | 152 | //if( pCurBlock->uBytesUsed == uBlockSize ) |
153 | if( uPos%uBlockSize == 0 ) | ||
146 | uCurBlock = rNids.getNextBlock( uCurBlock, pCurBlock ); | 154 | uCurBlock = rNids.getNextBlock( uCurBlock, pCurBlock ); |
147 | if( nBytes == 0 ) | 155 | if( nBytes == 0 ) |
148 | return nTotal; | 156 | return nTotal; |