Class Buffer.

Inherits Garbage

A Buffer is a FIFO of bytes.

There are two ways to append data: append() and read(). Data in the buffer can be examined with operator[] or string(), removed with remove(), or written with write().

Generally, a buffer is used only to read or only to write. In the former case, its owner calls append() and EventLoop calls write(), and in the latter EventLoop calls read() and the object's owner calls remove() etc. However, its owner has the option of putting things into the buffer and later removing them. One class does use that: IMAPS.


Creates an empty Buffer.

Reimplements Garbage::Garbage().

void Buffer::addFilter( Filter * f )

Adds f to this Buffer, creating another Buffer behind f. All current contents are moved to the Buffer behind f.

This implies that for a read buffer, all unread contents will be filtered.

void Buffer::append( const String & s )

Appends the String s to a Buffer.

void Buffer::append( const char * s, uint l )

Appends l bytes starting at s to the Buffer. If l is 0 (the default), s is considered to be NUL-terminated.

char Buffer::at( uint i ) const

This private function retrieves bytes that are not in the first Vector on behalf of operator[](). It's kept here to make the inline function smaller. i is an internal variable, and this function should never be called except from the operator.

bool Buffer::eof() const

Have we encountered EOF when reading into this buffer?

uint Buffer::error() const

Returns the errno value for the last error value encountered during IO on this Buffer, or 0 if there was no error.

char Buffer::operator[]( uint i ) const

Returns the byte at index i of the Buffer. Returns 0 if i is too large, or the buffer is empty.

void Buffer::read( int fd )

Reads as much as possible from the file descriptor fd into the Buffer. It assumes that the file descriptor is nonblocking, and that enough memory is available.

void Buffer::remove( uint n )

Discards the first n bytes from the Buffer. If there are fewer than n bytes in the Buffer, the Buffer is left empty.

String * Buffer::removeLine( uint s )

This function removes a line (terminated by LF or CRLF) of at most s bytes from the Buffer, and returns a pointer to a String with the line ending removed. If the Buffer does not contain a complete line less than s bytes long, this function a null pointer.

If s has its default value of 0, the entire Buffer is searched.

uint Buffer::size() const

Returns the number of bytes in the Buffer.

String Buffer::string( uint num ) const

Returns a string containing the first num bytes in the buffer. If the buffer contains fewer than num bytes, they are all returned. This function does not remove() the returned data.

void Buffer::write( int fd )

Writes as much as possible from the Buffer to its file descriptor fd. That file descriptor must be nonblocking.

This web page based on source code belonging to Oryx Mail Systems GmbH. All rights reserved.