Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members

Readfd Class Reference

#include <lib.h>

List of all members.


Detailed Description

Class for doing secure, non-blocking, line-buffered reads from any file descriptor.

When an attempt to read has been issued to this class, no other code should read from the file descriptor, as it will mess up the buffers.


Public Member Functions

 Readfd (int fd)
int read_line (std::string &str)
 Tries to read a line without blocking and writes the result into str.

int read_bytes (std::string &str, size_t count)
 Tries to read count bytes into str without blocking.

int event (int timeout=-1)
 Blocks until the file descriptor becomes ready for reading or timeout (milliseconds) elapses.

bool eof ()
 Returns true if an EOF or error condition has occured.

size_t buflimit ()
 Returns the max allowed size of the internal memory buffer.

size_t buflimit (size_t set)
 Sets the max allowed size of the internal memory buffer.


Protected Attributes

int _fd
size_t _len
size_t _pos
size_t _buflimit
char * _buf
pollfd _pollfd

Static Protected Attributes

const size_t _readsize = 1024


Constructor & Destructor Documentation

Readfd::Readfd int  fd  )  [inline]
 

Parameters:
fd The file descriptor to be read from. This is set once and for all, and it cannot be changed later.


Member Function Documentation

size_t Readfd::buflimit size_t  set  )  [inline]
 

Sets the max allowed size of the internal memory buffer.

If the buffer grows beyond this, it will be treated as a read error, protecting against DOS attacks.

bool Readfd::eof  )  [inline]
 

Returns true if an EOF or error condition has occured.

If this happens, the Readfd object is no use anymore and should be destroyed.

int Readfd::event int  timeout = -1  ) 
 

Blocks until the file descriptor becomes ready for reading or timeout (milliseconds) elapses.

int Readfd::read_bytes std::string &  str,
size_t  count
 

Tries to read count bytes into str without blocking.

Has three possible return values: 1 if something could be read (not necessarily all count bytes), 0 if reading would block and -1 if there was an error on the file descriptor.

int Readfd::read_line std::string &  str  ) 
 

Tries to read a line without blocking and writes the result into str.

Has three possible return values: 1 if it succeeds, 0 if reading would block and -1 if there was an error on the file descriptor.


The documentation for this class was generated from the following files:
Generated on Sun Oct 19 17:34:48 2003 for rve by doxygen 1.3.3