Changeset View
Changeset View
Standalone View
Standalone View
src/streams.h
Show First 20 Lines • Show All 318 Lines • ▼ Show 20 Lines | public: | ||||
void read(char *pch, size_t nSize) { | void read(char *pch, size_t nSize) { | ||||
if (nSize == 0) { | if (nSize == 0) { | ||||
return; | return; | ||||
} | } | ||||
// Read from the beginning of the buffer | // Read from the beginning of the buffer | ||||
unsigned int nReadPosNext = nReadPos + nSize; | unsigned int nReadPosNext = nReadPos + nSize; | ||||
if (nReadPosNext >= vch.size()) { | |||||
if (nReadPosNext > vch.size()) { | if (nReadPosNext > vch.size()) { | ||||
throw std::ios_base::failure( | throw std::ios_base::failure("CDataStream::read(): end of data"); | ||||
"CDataStream::read(): end of data"); | |||||
} | } | ||||
memcpy(pch, &vch[nReadPos], nSize); | memcpy(pch, &vch[nReadPos], nSize); | ||||
if (nReadPosNext == vch.size()) { | |||||
nReadPos = 0; | nReadPos = 0; | ||||
vch.clear(); | vch.clear(); | ||||
return; | return; | ||||
} | } | ||||
memcpy(pch, &vch[nReadPos], nSize); | |||||
nReadPos = nReadPosNext; | nReadPos = nReadPosNext; | ||||
} | } | ||||
void ignore(int nSize) { | void ignore(int nSize) { | ||||
// Ignore from the beginning of the buffer | // Ignore from the beginning of the buffer | ||||
if (nSize < 0) { | if (nSize < 0) { | ||||
throw std::ios_base::failure( | throw std::ios_base::failure( | ||||
"CDataStream::ignore(): nSize negative"); | "CDataStream::ignore(): nSize negative"); | ||||
▲ Show 20 Lines • Show All 317 Lines • Show Last 20 Lines |