diff options
Diffstat (limited to 'src/queuebuf.cpp')
-rw-r--r-- | src/queuebuf.cpp | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/src/queuebuf.cpp b/src/queuebuf.cpp index 9404164..9577793 100644 --- a/src/queuebuf.cpp +++ b/src/queuebuf.cpp | |||
@@ -70,13 +70,13 @@ size_t Bu::QueueBuf::read( void *pRawBuf, size_t nBytes ) | |||
70 | iLeft -= iCopy; | 70 | iLeft -= iCopy; |
71 | pBuf += iCopy; | 71 | pBuf += iCopy; |
72 | iTotalSize -= iCopy; | 72 | iTotalSize -= iCopy; |
73 | sio << "Read " << iCopy << " bytes, new size: " << iTotalSize << sio.nl; | 73 | // sio << "Read " << iCopy << " bytes, new size: " << iTotalSize << sio.nl; |
74 | } | 74 | } |
75 | 75 | ||
76 | return nBytes - iLeft; | 76 | return nBytes - iLeft; |
77 | } | 77 | } |
78 | 78 | ||
79 | size_t QueueBuf::peek( void *pBuf, size_t nBytes ) | 79 | size_t Bu::QueueBuf::peek( void *pRawBuf, size_t nBytes ) |
80 | { | 80 | { |
81 | if( nBytes <= 0 ) | 81 | if( nBytes <= 0 ) |
82 | return 0; | 82 | return 0; |
@@ -88,31 +88,33 @@ size_t QueueBuf::peek( void *pBuf, size_t nBytes ) | |||
88 | char *pBuf = (char *)pRawBuf; | 88 | char *pBuf = (char *)pRawBuf; |
89 | 89 | ||
90 | int iTmpReadOffset = iReadOffset; | 90 | int iTmpReadOffset = iReadOffset; |
91 | int iTmpRemSize = iTotalSize; | 91 | size_t iTmpRemSize = iTotalSize; |
92 | BlockList::iterator iBlock = lBlocks.begin(); | ||
92 | while( iLeft > 0 && iTmpRemSize > 0 ) | 93 | while( iLeft > 0 && iTmpRemSize > 0 ) |
93 | { | 94 | { |
94 | |||
95 | // Switching to use temp variables instead of iReadOffset and iTotalSize | 95 | // Switching to use temp variables instead of iReadOffset and iTotalSize |
96 | if( iReadOffset == iBlockSize ) | 96 | if( iTmpReadOffset == iBlockSize ) |
97 | { | 97 | { |
98 | if( lBlocks.isEmpty() ) | 98 | iBlock++; |
99 | if( iBlock == lBlocks.end() ) | ||
99 | { | 100 | { |
100 | return nBytes-iLeft; | 101 | return nBytes-iLeft; |
101 | } | 102 | } |
102 | iReadOffset = 0; | 103 | iTmpReadOffset = 0; |
103 | } | 104 | } |
104 | char *pBlock = lBlocks.first(); | 105 | char *pBlock = *iBlock; |
105 | size_t iCopy = iBlockSize-iReadOffset; | 106 | size_t iCopy = iBlockSize-iTmpReadOffset; |
106 | if( iLeft < iCopy ) | 107 | if( iLeft < iCopy ) |
107 | iCopy = iLeft; | 108 | iCopy = iLeft; |
108 | if( iTotalSize < iCopy ) | 109 | if( iTmpRemSize < iCopy ) |
109 | iCopy = iTotalSize; | 110 | iCopy = iTmpRemSize; |
110 | memcpy( pBuf, pBlock+iReadOffset, iCopy ); | 111 | memcpy( pBuf, pBlock+iTmpReadOffset, iCopy ); |
111 | iReadOffset += iCopy; | 112 | iTmpReadOffset += iCopy; |
112 | iLeft -= iCopy; | 113 | iLeft -= iCopy; |
113 | pBuf += iCopy; | 114 | pBuf += iCopy; |
114 | iTotalSize -= iCopy; | 115 | iTmpRemSize -= iCopy; |
115 | sio << "Read " << iCopy << " bytes, new size: " << iTotalSize << sio.nl; | 116 | // sio << "Read (peek) " << iCopy << " bytes, new temp size: " |
117 | // << iTmpRemSize << sio.nl; | ||
116 | } | 118 | } |
117 | 119 | ||
118 | return nBytes - iLeft; | 120 | return nBytes - iLeft; |
@@ -147,7 +149,8 @@ size_t Bu::QueueBuf::write( const void *pRawBuf, size_t nBytes ) | |||
147 | iLeft -= iCopy; | 149 | iLeft -= iCopy; |
148 | pBuf += iCopy; | 150 | pBuf += iCopy; |
149 | iTotalSize += iCopy; | 151 | iTotalSize += iCopy; |
150 | sio << "Wrote " << iCopy << " bytes, new size: " << iTotalSize << sio.nl; | 152 | // sio << "Wrote " << iCopy << " bytes, new size: " << iTotalSize |
153 | // << sio.nl; | ||
151 | } | 154 | } |
152 | 155 | ||
153 | return nBytes; | 156 | return nBytes; |
@@ -158,8 +161,27 @@ long Bu::QueueBuf::tell() | |||
158 | return -1; | 161 | return -1; |
159 | } | 162 | } |
160 | 163 | ||
161 | void Bu::QueueBuf::seek( long ) | 164 | void Bu::QueueBuf::seek( long iAmnt ) |
162 | { | 165 | { |
166 | if( iAmnt <= 0 ) | ||
167 | return; | ||
168 | |||
169 | if( iAmnt >= iTotalSize ) | ||
170 | { | ||
171 | // sio << "seek: clear all data (" << iAmnt << ">=" << iTotalSize | ||
172 | // << ")." << sio.nl; | ||
173 | close(); | ||
174 | return; | ||
175 | } | ||
176 | |||
177 | iReadOffset += iAmnt; | ||
178 | iTotalSize -= iAmnt; | ||
179 | while( iReadOffset >= iBlockSize ) | ||
180 | { | ||
181 | removeBlock(); | ||
182 | iReadOffset -= iBlockSize; | ||
183 | // sio << "seek: removal step (" << iReadOffset << ")" << sio.nl; | ||
184 | } | ||
163 | } | 185 | } |
164 | 186 | ||
165 | void Bu::QueueBuf::setPos( long ) | 187 | void Bu::QueueBuf::setPos( long ) |
@@ -221,13 +243,13 @@ void Bu::QueueBuf::setBlocking( bool ) | |||
221 | void Bu::QueueBuf::addBlock() | 243 | void Bu::QueueBuf::addBlock() |
222 | { | 244 | { |
223 | lBlocks.append( new char[iBlockSize] ); | 245 | lBlocks.append( new char[iBlockSize] ); |
224 | sio << "Added new block." << sio.nl; | 246 | // sio << "Added new block." << sio.nl; |
225 | } | 247 | } |
226 | 248 | ||
227 | void Bu::QueueBuf::removeBlock() | 249 | void Bu::QueueBuf::removeBlock() |
228 | { | 250 | { |
229 | delete[] lBlocks.first(); | 251 | delete[] lBlocks.first(); |
230 | lBlocks.erase( lBlocks.begin() ); | 252 | lBlocks.erase( lBlocks.begin() ); |
231 | sio << "Removed block." << sio.nl; | 253 | // sio << "Removed block." << sio.nl; |
232 | } | 254 | } |
233 | 255 | ||