basic SocketHandle supporting protocol and policy abstraction More...

#include <senf/Socket/SocketHandle.hh>

Inheritance diagram for senf::SocketHandle< SPolicy >:

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...
 
SocketProtocolprotocol () 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)
 
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 ()
 

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

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

Detailed Description

template<class SPolicy>
class senf::SocketHandle< SPolicy >

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

Template Parameters
SPolicysocket policy
Note
This class is not meant to be used as a base-class outside the library implementation; The protected interface is for internal use only.
Todo:
Create a SocketHandleBase class and move some non-Policy dependent code there

Definition at line 60 of file SocketHandle.hh.

Member Typedef Documentation

◆ Policy

template<class SPolicy>
typedef SPolicy senf::SocketHandle< SPolicy >::Policy

Definition at line 67 of file SocketHandle.hh.

Constructor & Destructor Documentation

◆ SocketHandle() [1/4]

template<class SPolicy>
senf::SocketHandle< SPolicy >::SocketHandle ( )

◆ SocketHandle() [2/4]

template<class SPolicy>
template<class OtherPolicy >
senf::SocketHandle< SPolicy >::SocketHandle ( SocketHandle< OtherPolicy >  other,
typename IsCompatible< OtherPolicy >::type = 0 
)

Convert from other socket handle checking policy compatibility.

◆ SocketHandle() [3/4]

template<class SPolicy>
senf::SocketHandle< SPolicy >::SocketHandle ( std::unique_ptr< SocketBody >  body)
explicitprotected

Initialize SocketHandle providing the protocol.

Parameters
protocolProtocol class of the protocol implemented by this socket handle
isServertrue, if this SobcketHandle instance implements a server handle, false otherwise

◆ SocketHandle() [4/4]

template<class SPolicy>
senf::SocketHandle< SPolicy >::SocketHandle ( FileHandle  other,
bool  isChecked 
)
protected

Initialize SocketHandle from arbitrary checked FileHandle.

This constructor is used to support up- and downcasting of SocketHandle instances.

Warning
It is absolutely necessary to ensure, that the FileHandle passed in is really a SocketHandle holding a SocketBody (and not a simple FileBody) instance. Additionally. the SocketPolicy absolutely must be compatible.
Parameters
otherFileHandle to assign
isCheckedhas to be true
Todo:
Answer, why the heck I need the isChecked parameter ??

Member Function Documentation

◆ assign()

template<class SPolicy>
void senf::SocketHandle< SPolicy >::assign ( FileHandle  other)
protected

◆ body() [1/2]

template<class SPolicy>
SocketBody& senf::SocketHandle< SPolicy >::body ( )
protected

Access socket body.

This member replaces the corresponding FileHandle member and returns an appropriately cast body reference

◆ body() [2/2]

template<class SPolicy>
SocketBody const& senf::SocketHandle< SPolicy >::body ( ) const
protected

Access socket body in const context.

This member replaces the corresponding FileHandle member and returns an appropriately cast body reference

◆ cast_dynamic()

template<class SPolicy>
static SocketHandle senf::SocketHandle< SPolicy >::cast_dynamic ( FileHandle  handle)
static

◆ cast_static()

template<class SPolicy>
static SocketHandle senf::SocketHandle< SPolicy >::cast_static ( FileHandle  handle)
static

◆ dumpState()

template<class SPolicy>
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.

Parameters
lodlevel of detail requested. The interpretation of this value is protocol specific
Implementation note:
This member will be re-implemented in every derived class. See the state() documentation.

◆ facet()

template<class SPolicy>
template<class Facet >
Facet& senf::SocketHandle< SPolicy >::facet ( )

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.

Exceptions
std::bad_castif Facet is not a protocol facet of this socket
Returns
the Facet protocol facet of this socket

◆ operator=()

template<class SPolicy>
template<class OtherPolicy >
IsCompatible<OtherPolicy>::type const& senf::SocketHandle< SPolicy >::operator= ( SocketHandle< OtherPolicy >  other)

Assign from other socket handle checking policy compatibility.

◆ protocol()

template<class SPolicy>
SocketProtocol& senf::SocketHandle< SPolicy >::protocol ( ) const
protected

Access protocol class.

◆ state()

template<class SPolicy>
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.

Parameters
mapstring to string mapping to be filled with state information
lodlevel of detail requested. The interpretation of this value is protocol specific
Implementation note:
This member will be re-implemented in every derived class. This is very important since state() is not a virtual function (which we don't want since we don't want to add a vtable pointer to every handle instance).

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