Augmented Socket::Buffer features.
This commit is contained in:
parent
4e16982929
commit
97b51ff39a
2 changed files with 27 additions and 0 deletions
|
@ -32,6 +32,18 @@ unsigned int Socket::Buffer::size(){
|
|||
return data.size();
|
||||
}
|
||||
|
||||
/// Returns either the amount of total bytes available in the buffer or max, whichever is smaller.
|
||||
unsigned int Socket::Buffer::bytes(unsigned int max){
|
||||
unsigned int i = 0;
|
||||
for (std::deque<std::string>::iterator it = data.begin(); it != data.end(); ++it){
|
||||
i += ( *it).size();
|
||||
if (i >= max){
|
||||
return max;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/// Appends this string to the internal std::deque of std::string objects.
|
||||
/// It is automatically split every BUFFER_BLOCKSIZE bytes.
|
||||
void Socket::Buffer::append(const std::string & newdata){
|
||||
|
@ -62,6 +74,18 @@ void Socket::Buffer::append(const char * newdata, const unsigned int newdatasize
|
|||
}
|
||||
}
|
||||
|
||||
/// Prepends this data block to the internal std::deque of std::string objects.
|
||||
/// It is _not_ automatically split every BUFFER_BLOCKSIZE bytes.
|
||||
void Socket::Buffer::prepend(const std::string & newdata){
|
||||
data.push_back(newdata);
|
||||
}
|
||||
|
||||
/// Prepends this data block to the internal std::deque of std::string objects.
|
||||
/// It is _not_ automatically split every BUFFER_BLOCKSIZE bytes.
|
||||
void Socket::Buffer::prepend(const char * newdata, const unsigned int newdatasize){
|
||||
data.push_back(std::string(newdata, (size_t)newdatasize));
|
||||
}
|
||||
|
||||
/// Returns true if at least count bytes are available in this buffer.
|
||||
bool Socket::Buffer::available(unsigned int count){
|
||||
unsigned int i = 0;
|
||||
|
|
|
@ -30,8 +30,11 @@ namespace Socket {
|
|||
std::deque<std::string> data;
|
||||
public:
|
||||
unsigned int size();
|
||||
unsigned int bytes(unsigned int max);
|
||||
void append(const std::string & newdata);
|
||||
void append(const char * newdata, const unsigned int newdatasize);
|
||||
void prepend(const std::string & newdata);
|
||||
void prepend(const char * newdata, const unsigned int newdatasize);
|
||||
std::string & get();
|
||||
bool available(unsigned int count);
|
||||
std::string remove(unsigned int count);
|
||||
|
|
Loading…
Add table
Reference in a new issue