Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

FileDescriptor Class Reference

Associates callbacks with events on a given Unix File Descriptor, and provides an interface to Unix system calls dealing with file descriptors. More...

#include <FileDescriptor.h>

Inheritance diagram for FileDescriptor:

Inheritance graph
[legend]
Collaboration diagram for FileDescriptor:

Collaboration graph
[legend]
List of all members.

Public Methods

 FileDescriptor (ref< FileDescriptorManager > const &_fdMgr, int _fd)
virtual ~FileDescriptor ()
bool isOpen () const
bool inputReady ()
int getFd () const
ref<FileDescriptorManager>
const& 
getFdMgr () const
virtual void close ()
bool setNonBlocking (bool on)
void block (bool forRead, bool forWrite)
bool read (int &ch)
void setReadCallback (ref< Callback > const &cb, Callback::Method cbm)
void setWriteCallback (ref< Callback > const &cb, Callback::Method cbm)
void clearReadCallback ()
void clearWriteCallback ()
void fireReadCallback ()
void fireWriteCallback ()
int read (char *inbuf, int len, bool complete=false)
int write (char const *outbuf, int len, bool complete=false)

Protected Methods

virtual int lowlevel_read (int handle, char *buf, int len)
virtual int lowlevel_write (int handle, char const *buf, int len)
virtual int lowlevel_close (int handle)

Private Methods

bool fillBuffer ()
 FileDescriptor (FileDescriptor const &other)
FileDescriptor const& operator= (FileDescriptor const &other)
void updateCallbacks ()

Private Attributes

ref<FileDescriptorManagerfdMgr
int fd
char buf [1024]
int buflen
int pos
callback_entry_t readCallback
callback_entry_t writeCallback

Detailed Description

Associates callbacks with events on a given Unix File Descriptor, and provides an interface to Unix system calls dealing with file descriptors.

Works in association with a FileDescriptorManager.

Definition at line 27 of file FileDescriptor.h.


Constructor & Destructor Documentation

FileDescriptor::FileDescriptor ( FileDescriptor const & other ) [private]
 

FileDescriptor::FileDescriptor ( ref< FileDescriptorManager > const & _fdMgr,
int _fd )
 

This constructor wraps the passed in _fd in association with the passed in _fdMgr.

FileDescriptor::~FileDescriptor ( ) [virtual]
 

The file-descriptor is close()d on destruction.


Member Function Documentation

void FileDescriptor::block ( bool forRead,
bool forWrite )
 

Calls select() to wait for some event on this fd only; all others are ignored.

%%% (NOTE: should probably be protected rather than public; don't %%% call it unless you're sure you know what you're doing - and %%% let tonyg@kcbbs.gen.nz know if you *do* find a legitimate use %%% for it!)

void FileDescriptor::clearReadCallback ( )
 

Clear our read-available callback - we are no longer interested in those events.

void FileDescriptor::clearWriteCallback ( )
 

Clear our write-available callback - we are no longer interested in those events.

void FileDescriptor::close ( ) [virtual]
 

Closes this fd.

Reimplemented in SocketDescriptor.

bool FileDescriptor::fillBuffer ( ) [private]
 

Fill buffer with at least one byte. Returns true if okay, false if would block.

Referenced by inputReady(), and read().

void FileDescriptor::fireReadCallback ( )
 

Calls the read-callback; does not clear the callback.

void FileDescriptor::fireWriteCallback ( )
 

Calls the write-callback; does not clear the callback.

int FileDescriptor::getFd ( ) const [inline]
 

Access the file descriptor wrapped by this.

Definition at line 132 of file FileDescriptor.h.

ref< FileDescriptorManager > const & FileDescriptor::getFdMgr<FileDescriptorManager> ( ) const
 

Access our controlling fdMgr.

bool FileDescriptor::inputReady ( ) [inline]
 

true -> some bytes are available for read *now*.

Definition at line 127 of file FileDescriptor.h.

bool FileDescriptor::isOpen ( ) const [inline]
 

true -> this fd is open.

Definition at line 124 of file FileDescriptor.h.

Referenced by inputReady().

int FileDescriptor::lowlevel_close ( int handle ) [protected, virtual]
 

int FileDescriptor::lowlevel_read ( int fd,
char * buf,
int len ) [protected, virtual]
 

for sockets on Linux, where you can use send(... MSG_NOSIGNAL) etc., and for sockets on Win32 where you have to use recv and send instead of read and write. Default (superclass) behaviour is to use write and read.

Reimplemented in SocketDescriptor.

int FileDescriptor::lowlevel_write ( int fd,
char const * buf,
int len ) [protected, virtual]
 

Reimplemented in SocketDescriptor.

FileDescriptor const& FileDescriptor::operator= ( FileDescriptor const & other ) [private]
 

bool FileDescriptor::read ( int & ch ) [inline]
 

Read a single byte.

Definition at line 175 of file FileDescriptor.h.

int FileDescriptor::read ( char * inbuf,
int len,
bool complete = false )
 

These process as many bytes as possible without blocking, and return the number of bytes processed, unless 'complete' is set, in which case they keep working until exactly len bytes have been processed or an exception is met.

bool FileDescriptor::setNonBlocking ( bool on )
 

true -> success.

void FileDescriptor::setReadCallback ( ref< Callback > const & cb,
Callback::Method cbm )
 

Installs a callback for read-available events.

void FileDescriptor::setWriteCallback ( ref< Callback > const & cb,
Callback::Method cbm )
 

Installs a callback for write-available events.

void FileDescriptor::updateCallbacks ( ) [private]
 

Updates the fd_set objects in our FileDescriptorManager depending on whether we are interested in read-available, write-available, or both conditions.

int FileDescriptor::write ( char const * outbuf,
int len,
bool complete = false )
 

Referenced by ReadCallback::sendToAll().


Member Data Documentation

char FileDescriptor::buf [private]
 

Input buffer (output is unbuffered).

Definition at line 74 of file FileDescriptor.h.

int FileDescriptor::buflen [private]
 

Number of bytes in the buffer.

Definition at line 75 of file FileDescriptor.h.

int FileDescriptor::fd [private]
 

Unix fd we are wrapping.

Definition at line 73 of file FileDescriptor.h.

ref< FileDescriptorManager > FileDescriptor::fdMgr<FileDescriptorManager> [private]
 

The FileDescriptorManager that manages this.

Definition at line 72 of file FileDescriptor.h.

int FileDescriptor::pos [private]
 

Index of next byte to return.

Definition at line 76 of file FileDescriptor.h.

callback_entry_t FileDescriptor::readCallback [private]
 

Callback for read-available.

Definition at line 89 of file FileDescriptor.h.

callback_entry_t FileDescriptor::writeCallback [private]
 

Callback for write-available.

Definition at line 90 of file FileDescriptor.h.


The documentation for this class was generated from the following file:
Generated at Wed Aug 15 01:05:28 2001 for mps-cpp by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001