senf::FileHandle Class Reference
[The Handle Hierarchy]

Basic file handle wrapper. More...

#include <senf/Socket/FileHandle.hh>

Inheritance diagram for senf::FileHandle:
Inheritance graph
[legend]

List of all members.


Detailed Description

Basic file handle wrapper.

senf::FileHandle provides a simple wrapper for arbitrary file handles. It exposes only a minimal interface which does not include reading or writing (since some filehandles are not readable or writable or only using special function calls like sendto).

The FileHandle class provides handle/body handling and uses automatic reference counting. The senf::FileHandle instance is very lightweight and should be used like a built-in type.

Attention:
You should mostly pass around senf::FileHandle objects by value and not by reference.
The FileHandle abstraction is only applicable to real filehandles. It is not possible to wrap any provider or consumer into a filehandle like interface using this wrapper. The wrapper will forward some calls directly to the underlying API without relying on virtual methods. This allows important members to be inlined.

It is not possible to use the senf::FileHandle class directly since it does not have any public constructor. The FileHandle class is however the baseclass of all handle classes of the socket library.

Writing senf::FileHandle derived classes

To build a new FileHandle type you need to derive from senf::FileHandle. The derived class will have to call the protected FileHandle constructor passing a new senf::FileBody instance. This instance may either be a simple senf::FileBody or a class derived from senf::FileBody.

Definition at line 111 of file FileHandle.hh.


Public Member Functions

void  close ()
  Close filehandle.
void  terminate ()
  Close filehandle ignoring error conditions.
bool  readable () const
  Check, whether a read on the handle would not block < (ignoring blocking state).
bool  waitReadable (senf::ClockService::clock_type timeout=-1) const
  Wait, until read on the handle would not block (ignoring < blocking state).
bool  writeable () const
  Check, whether a write on the handle would not block < (ignoring blocking state).
bool  waitWriteable (senf::ClockService::clock_type timeout=-1) const
  Wait, until a write on the handle would not block < (ignoring blocking state).
bool  oobReadable () const
  Check, whether a read of prioritized data on the handle < would not block (ignoring blocking state).
bool  waitOOBReadable (senf::ClockService::clock_type timeout=-1) const
  Wait, until read of prioritized data on the handle does < not block (ignoring blocking state).
bool  blocking () const
  Return current blocking state.
void  blocking (bool status)
  Set blocking state.
bool  eof () const
  Check EOF condition.
bool  valid () const
  Check filehandle validity.
bool  boolean_test () const
  Short for valid() && ! eof().
int  fd () const
  Return the raw FileHandle.

Static Public Member Functions

static FileHandle  cast_static (FileHandle handle)
static FileHandle  cast_dynamic (FileHandle handle)

Related Functions

(Note that these are not member functions.)

int  retrieve_filehandle (FileHandle handle)
  Adapt FileHandle to senf::scheduler.

Structors and default members

  FileHandle ()
  ~FileHandle ()

Protected Member Functions

  FileHandle (std::auto_ptr< FileBody > body)
  create new FileHandle instance
  FileHandle (FileBody::ptr body)
FileBody body ()
  Access body.
FileBody const &  body () const
  Access body in const context.
void  fd (int fd)
  Set raw filehandle.

Static Protected Member Functions

static FileBody body (FileHandle &handle)
  Access body of another FileHandle instance.
static FileBody const &  body (FileHandle const &handle)
  Access body of another < FileHandle instance in const context.

Constructor & Destructor Documentation

senf::FileHandle::
FileHandle ()

Definition at line 207 of file FileHandle.cci.

senf::FileHandle::
~FileHandle ()

Definition at line 211 of file FileHandle.cci.

senf::FileHandle::
FileHandle ( std::auto_ptr< FileBody body )

create new FileHandle instance

The FileHandle instance will take over ownership over the given FileBody instance which must have been allocated using new. To configure the FileHandle behavior, A derived class may provide any class derived from FileBody here.

Definition at line 217 of file FileHandle.cci.

senf::FileHandle::
FileHandle ( FileBody::ptr  body )

Definition at line 221 of file FileHandle.cci.


Member Function Documentation

void senf::FileHandle::
blocking ( bool  status )

Set blocking state.

Definition at line 178 of file FileHandle.cci.

bool senf::FileHandle::
blocking ()

Return current blocking state.

Definition at line 172 of file FileHandle.cci.

senf::FileBody const & senf::FileHandle::
body ( FileHandle const &  handle )

Access body of another < FileHandle instance in const context.

Definition at line 230 of file FileHandle.cci.

senf::FileBody & senf::FileHandle::
body ( FileHandle handle )

Access body of another FileHandle instance.

Definition at line 225 of file FileHandle.cci.

senf::FileBody const & senf::FileHandle::
body ()

bool senf::FileHandle::
boolean_test ()

Short for valid() && ! eof().

This is called when using a FileHandle instance in a boolean context

See the performance comments for the eof() member

Definition at line 195 of file FileHandle.cci.

void senf::FileHandle::
close ()

Close filehandle.

Exceptions:
senf::SystemException 

Definition at line 126 of file FileHandle.cci.

bool senf::FileHandle::
eof ()

Check EOF condition.

Depending on the socket type, this might never return true.

This member is somewhat problematic performance wise if called frequently since it relies on virtual functions. However, since the eof() handling is extremely protocol dependent, a policy based implementation does not seam feasible.

Definition at line 183 of file FileHandle.cci.

void senf::FileHandle::
fd ( int  fd )

Set raw filehandle.

Definition at line 235 of file FileHandle.cci.

int senf::FileHandle::
fd ()

Return the raw FileHandle.

Definition at line 201 of file FileHandle.cci.

bool senf::FileHandle::
oobReadable ()

Check, whether a read of prioritized data on the handle < would not block (ignoring blocking state).

Definition at line 160 of file FileHandle.cci.

bool senf::FileHandle::
readable ()

Check, whether a read on the handle would not block < (ignoring blocking state).

Definition at line 136 of file FileHandle.cci.

void senf::FileHandle::
terminate ()

Close filehandle ignoring error conditions.

Definition at line 131 of file FileHandle.cci.

bool senf::FileHandle::
valid ()

Check filehandle validity.

Any operation besides valid() will fail on an invalid FileHandle

Definition at line 189 of file FileHandle.cci.

bool senf::FileHandle::
waitOOBReadable ( senf::ClockService::clock_type  timeout = -1 )

Wait, until read of prioritized data on the handle does < not block (ignoring blocking state).

Parameters:
[in]  timeout  max time to wait, default is to wait forever.
Returns:
true, if handle became readable for out-of-band data or false on timeout.

Definition at line 166 of file FileHandle.cci.

bool senf::FileHandle::
waitReadable ( senf::ClockService::clock_type  timeout = -1 )

Wait, until read on the handle would not block (ignoring < blocking state).

Parameters:
[in]  timeout  max time to wait, default is to wait forever.
Returns:
true, if handle became readable or false on timeout.

Definition at line 142 of file FileHandle.cci.

bool senf::FileHandle::
waitWriteable ( senf::ClockService::clock_type  timeout = -1 )

Wait, until a write on the handle would not block < (ignoring blocking state).

Parameters:
[in]  timeout  max time to wait, default is to wait forever.
Returns:
true, if handle became writable or false on timeout.

Definition at line 154 of file FileHandle.cci.

bool senf::FileHandle::
writeable ()

Check, whether a write on the handle would not block < (ignoring blocking state).

Definition at line 148 of file FileHandle.cci.


The documentation for this class was generated from the following files: