Basic file handle wrapper. More...

#include <senf/Socket/FileHandle.hh>

Inheritance diagram for senf::FileHandle:

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

 FileHandle (std::unique_ptr< FileBody > body)
 create new FileHandle instance More...
 
 FileHandle (FileBody::ptr body)
 
FileBodybody ()
 Access body. More...
 
FileBody const & body () const
 Access body in const context. More...
 
void fd (int fd)
 Set raw filehandle. More...
 
void * extraPtr () const
 get extra data pointer More...
 
void extraPtr (void *ptr)
 set extra data pointer More...
 
- Protected Member Functions inherited from senf::comparable_safe_bool< class >
 ~comparable_safe_bool ()
 
- Protected Member Functions inherited from senf::safe_bool_base
void this_type_does_not_support_comparisons () const
 
 safe_bool_base ()
 
 safe_bool_base (const safe_bool_base &)
 
safe_bool_baseoperator= (const safe_bool_base &)
 
 ~safe_bool_base ()
 

Static Protected Member Functions

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

Related Functions

(Note that these are not member functions.)

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

Structors and default members

 FileHandle ()
 
 ~FileHandle ()
 

Additional Inherited Members

- Protected Types inherited from senf::safe_bool_base
typedef void(safe_bool_base::* bool_type) () const
 

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 102 of file FileHandle.hh.

Constructor & Destructor Documentation

◆ FileHandle() [1/3]

senf::FileHandle::FileHandle ( )

◆ ~FileHandle()

senf::FileHandle::~FileHandle ( )

◆ FileHandle() [2/3]

senf::FileHandle::FileHandle ( std::unique_ptr< FileBody body)
explicitprotected

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.

◆ FileHandle() [3/3]

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

Member Function Documentation

◆ blocking() [1/2]

bool senf::FileHandle::blocking ( ) const

Return current blocking state.

◆ blocking() [2/2]

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

Set blocking state.

◆ body() [1/4]

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

Access body.

◆ body() [2/4]

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

Access body in const context.

◆ body() [3/4]

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

Access body of another FileHandle instance.

◆ body() [4/4]

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

Access body of another FileHandle instance in const context.

◆ boolean_test()

bool senf::FileHandle::boolean_test ( ) const

Short for valid() && ! eof()

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

See the performance comments for the eof() member

◆ cast_dynamic()

static FileHandle senf::FileHandle::cast_dynamic ( FileHandle  handle)
static

◆ cast_static()

static FileHandle senf::FileHandle::cast_static ( FileHandle  handle)
static

◆ close()

void senf::FileHandle::close ( )

Close filehandle.

Exceptions
senf::SystemException

◆ eof()

bool senf::FileHandle::eof ( ) const

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.

◆ extraPtr() [1/2]

void* senf::FileHandle::extraPtr ( ) const
protected

get extra data pointer

◆ extraPtr() [2/2]

void senf::FileHandle::extraPtr ( void *  ptr)
protected

set extra data pointer

◆ fd() [1/2]

int senf::FileHandle::fd ( ) const

Return the raw FileHandle.

◆ fd() [2/2]

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

Set raw filehandle.

◆ is_shared()

bool senf::FileHandle::is_shared ( ) const

◆ oobReadable()

bool senf::FileHandle::oobReadable ( ) const

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

◆ readable()

bool senf::FileHandle::readable ( ) const

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

◆ refcount()

int senf::FileHandle::refcount ( ) const

◆ terminate()

void senf::FileHandle::terminate ( )

Close filehandle ignoring error conditions.

◆ valid()

bool senf::FileHandle::valid ( ) const

Check filehandle validity.

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

◆ waitOOBReadable()

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

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

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

◆ waitReadable()

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

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

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

◆ waitWriteable()

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

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

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

◆ writeable()

bool senf::FileHandle::writeable ( ) const

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


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