FileDescriptor class Reference (original) (raw)

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


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](FileDescriptor%5Fh-source.html)>

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<FileDescriptorManager> fdMgr
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]

| | 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]
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 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]
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]
FileDescriptor const& FileDescriptor::operator= ( FileDescriptor const & other ) [private]
bool FileDescriptor::read ( int & ch ) [inline]
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 )

| | Installs a callback for read-available events. | | ------------------------------------------------- |

| | 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 )

Member Data Documentation

char FileDescriptor::buf [private]

int FileDescriptor::buflen [private]

int FileDescriptor::fd [private]

int FileDescriptor::pos [private]


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