Basic file handle wrapper. More...
#include <senf/Socket/FileHandle.hh>
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) | |
FileBody & | body () |
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_base & | operator= (const safe_bool_base &) |
~safe_bool_base () | |
Static Protected Member Functions | |
static FileBody & | body (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 |
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.
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.
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.
senf::FileHandle::FileHandle | ( | ) |
senf::FileHandle::~FileHandle | ( | ) |
|
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.
|
explicitprotected |
bool senf::FileHandle::blocking | ( | ) | const |
Return current blocking state.
void senf::FileHandle::blocking | ( | bool | status | ) |
Set blocking state.
|
protected |
Access body.
|
protected |
Access body in const context.
|
staticprotected |
Access body of another FileHandle instance.
|
staticprotected |
Access body of another FileHandle instance in const context.
bool senf::FileHandle::boolean_test | ( | ) | const |
This is called when using a FileHandle instance in a boolean context
See the performance comments for the eof() member
|
static |
|
static |
void senf::FileHandle::close | ( | ) |
Close filehandle.
senf::SystemException |
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.
|
protected |
get extra data pointer
|
protected |
set extra data pointer
int senf::FileHandle::fd | ( | ) | const |
Return the raw FileHandle.
|
protected |
Set raw filehandle.
bool senf::FileHandle::is_shared | ( | ) | const |
bool senf::FileHandle::oobReadable | ( | ) | const |
Check, whether a read of prioritized data on the handle would not block (ignoring blocking state)
bool senf::FileHandle::readable | ( | ) | const |
Check, whether a read on the handle would not block (ignoring blocking state)
int senf::FileHandle::refcount | ( | ) | const |
void senf::FileHandle::terminate | ( | ) |
Close filehandle ignoring error conditions.
bool senf::FileHandle::valid | ( | ) | const |
Check filehandle validity.
Any operation besides valid() will fail on an invalid FileHandle
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)
[in] | timeout | max time to wait, default is to wait forever. |
true
, if handle became readable for out-of-band data or false
on timeout. 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)
[in] | timeout | max time to wait, default is to wait forever. |
true
, if handle became readable or false
on timeout. 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)
[in] | timeout | max time to wait, default is to wait forever. |
true
, if handle became writable or false
on timeout. bool senf::FileHandle::writeable | ( | ) | const |
Check, whether a write on the handle would not block (ignoring blocking state)