basic SocketHandle supporting protocol and policy abstraction More...
#include <senf/Socket/SocketHandle.hh>
Classes | |
struct | IsCompatible |
Check policy compatibility. More... | |
Public Types | |
typedef SPolicy | Policy |
Public Member Functions | |
template<class OtherPolicy > | |
IsCompatible< OtherPolicy >::type const & | operator= (SocketHandle< OtherPolicy > other) |
Assign from other socket handle checking policy compatibility. More... | |
void | state (SocketStateMap &map, unsigned lod=0) |
Inquire state information of socket handle. More... | |
std::string | dumpState (unsigned lod=0) |
Format complete state information as string. More... | |
template<class Facet > | |
Facet & | facet () |
Access a protocol facet. More... | |
Public Member Functions inherited from senf::FileHandle | |
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 |
FileHandle () | |
~FileHandle () | |
Public Member Functions inherited from senf::comparable_safe_bool< class > | |
operator bool_type () const | |
bool | operator! () const |
Static Public Member Functions | |
static SocketHandle | cast_static (FileHandle handle) |
static SocketHandle | cast_dynamic (FileHandle handle) |
Static Public Member Functions inherited from senf::FileHandle | |
static FileHandle | cast_static (FileHandle handle) |
static FileHandle | cast_dynamic (FileHandle handle) |
Protected Member Functions | |
SocketHandle (std::unique_ptr< SocketBody > body) | |
Initialize SocketHandle providing the protocol. More... | |
SocketHandle (FileHandle other, bool isChecked) | |
Initialize SocketHandle from arbitrary checked FileHandle. More... | |
SocketBody & | body () |
Access socket body. More... | |
SocketBody const & | body () const |
Access socket body in const context. More... | |
SocketProtocol & | protocol () const |
Access protocol class. More... | |
void | assign (FileHandle other) |
Protected Member Functions inherited from senf::FileHandle | |
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 () | |
Related Functions | |
(Note that these are not member functions.) | |
template<class SPolicy > | |
std::ostream & | operator<< (std::ostream &os, SocketHandle< SPolicy > handle) |
Write stream status dump to output stream. More... | |
template<class Target , class Source > | |
Target | static_socket_cast (Source handle) |
static socket (down-)cast More... | |
template<class Target , class Source > | |
Target | dynamic_socket_cast (Source handle) |
dynamic socket (down-)cast More... | |
template<class Target , class Source > | |
bool | check_socket_cast (Source handle) |
dynamically check cast validity More... | |
Related Functions inherited from senf::FileHandle | |
int | retrieve_filehandle (FileHandle handle) |
Adapt FileHandle to senf::scheduler. More... | |
Structors and default members | |
SocketHandle () | |
template<class OtherPolicy > | |
SocketHandle (SocketHandle< OtherPolicy > other, typename IsCompatible< OtherPolicy >::type *=0) | |
Convert from other socket handle checking policy compatibility. More... | |
Additional Inherited Members | |
Protected Types inherited from senf::safe_bool_base | |
typedef void(safe_bool_base::* | bool_type) () const |
Static Protected Member Functions inherited from senf::FileHandle | |
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... | |
basic SocketHandle supporting protocol and policy abstraction
The senf::SocketHandle class introduces the two abstraction layers of the socket library. senf::SocketHandle does not provide socket functions it only provides the infrastructure necessary to support both, the protocol and the policy interface.
SocketHandle takes the socket policy as a template argument. SocketHandle also introduces the protocol class. However, the class has no public constructors (see the derived classes senf::ProtocolClientSocketHandle and senf::ProtocolServerSocketHandle).
The most important functionality provided by SocketHandle is the conversion constructor. This allows to implicitly convert between compatible socket handle types as specified by the socket policy. The conversion constructor is defined in such a way, that only valid conversions are possible (see the implementation source for a more complete discussion).
SPolicy | socket policy |
Definition at line 60 of file SocketHandle.hh.
typedef SPolicy senf::SocketHandle< SPolicy >::Policy |
Definition at line 67 of file SocketHandle.hh.
senf::SocketHandle< SPolicy >::SocketHandle | ( | ) |
senf::SocketHandle< SPolicy >::SocketHandle | ( | SocketHandle< OtherPolicy > | other, |
typename IsCompatible< OtherPolicy >::type * | = 0 |
||
) |
Convert from other socket handle checking policy compatibility.
|
explicitprotected |
Initialize SocketHandle providing the protocol.
protocol | Protocol class of the protocol implemented by this socket handle |
isServer | true , if this SobcketHandle instance implements a server handle, false otherwise |
|
protected |
Initialize SocketHandle from arbitrary checked FileHandle.
This constructor is used to support up- and downcasting of SocketHandle instances.
other | FileHandle to assign |
isChecked | has to be true |
isChecked
parameter ??
|
protected |
|
protected |
Access socket body.
This member replaces the corresponding FileHandle member and returns an appropriately cast body reference
|
protected |
Access socket body in const context.
This member replaces the corresponding FileHandle member and returns an appropriately cast body reference
|
static |
|
static |
std::string senf::SocketHandle< SPolicy >::dumpState | ( | unsigned | lod = 0 | ) |
Format complete state information as string.
Formats the complete state map value and returns it as a single multi-line string.
lod | level of detail requested. The interpretation of this value is protocol specific |
Access a protocol facet.
This member will try to access the given protocol facet of the socket. If Facet is a valid facet of the protocol, it is returned, otherwise std::bad_cast
will be thrown.
std::bad_cast | if Facet is not a protocol facet of this socket |
IsCompatible<OtherPolicy>::type const& senf::SocketHandle< SPolicy >::operator= | ( | SocketHandle< OtherPolicy > | other | ) |
Assign from other socket handle checking policy compatibility.
|
protected |
Access protocol class.
void senf::SocketHandle< SPolicy >::state | ( | SocketStateMap & | map, |
unsigned | lod = 0 |
||
) |
Inquire state information of socket handle.
The map argument (a string to string mapping) will be filled with information covering the current state of the socket. The information provided depends on the socket protocol. The amount of information returned can be controlled using the lod
value.
See senf::SocketProtocol::state() for more information, how the Information is generated.
map | string to string mapping to be filled with state information |
lod | level of detail requested. The interpretation of this value is protocol specific |