Generic SocketHandle with server interface. More...

#include <senf/Socket/ClientSocketHandle.hh>

Inheritance diagram for senf::ServerSocketHandle< SPolicy >:

Public Types

typedef SPolicy::AddressingPolicy::Address Address
 Address type from the addressing policy. More...
 
typedef boost::call_traits< Address >::param_type AddressParam
 'Best' type for passing address as parameter More...
 
typedef ClientSocketHandle< SPolicy > ClientHandle
 Corresponding client socket handle with the same policy. More...
 
- Public Types inherited from senf::SocketHandle< SPolicy >
typedef SPolicy Policy
 

Public Member Functions

void state (SocketStateMap &map, unsigned lod=0)
 
std::string dumpState (unsigned lod=0)
 
- Public Member Functions inherited from senf::SocketHandle< SPolicy >
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...
 
 SocketHandle ()
 
template<class OtherPolicy >
 SocketHandle (SocketHandle< OtherPolicy > other, typename IsCompatible< OtherPolicy >::type *=0)
 Convert from other socket handle checking policy compatibility. 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 ServerSocketHandle cast_static (FileHandle handle)
 
static ServerSocketHandle cast_dynamic (FileHandle handle)
 
- Static Public Member Functions inherited from senf::SocketHandle< SPolicy >
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

 ServerSocketHandle (FileHandle other, bool isChecked)
 
 ServerSocketHandle (std::unique_ptr< SocketBody > body)
 
- Protected Member Functions inherited from senf::SocketHandle< SPolicy >
 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 ()
 

Structors and default members

 ServerSocketHandle ()
 
template<class OtherPolicy >
 ServerSocketHandle (ServerSocketHandle< OtherPolicy > other, typename SocketHandle< SPolicy >::template IsCompatible< OtherPolicy >::type *=0)
 
template<class OtherPolicy >
SocketHandle< SPolicy >::template IsCompatible< OtherPolicy >::type const & operator= (ServerSocketHandle< OtherPolicy > other)
 

Server socket interface

void bind (AddressParam addr)
 Set local address. More...
 
void listen (unsigned backlog=0)
 Allow clients to connect to this server socket. More...
 
Address local ()
 Query local address. More...
 
void local (Address &addr)
 Query local address. More...
 
ClientHandle accept ()
 Accept new connection. More...
 
std::pair< ClientHandle, Addressacceptfrom ()
 Accept new connection. More...
 
ClientHandle acceptfrom (Address &addr)
 Accept new connection. 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::ServerSocketHandle< SPolicy >

Generic SocketHandle with server interface.

This class provides the server side policy interface of the socket abstraction. ServerSocketHandle defines the complete policy interface. It does not implement any functionality itself however. All calls are forwarded to the following policy classes:

senf::ServerSocketHandle::bind AddressingPolicy::bind (senf::AddressingPolicyBase)
senf::ServerSocketHandle::listen CommunicationPolicy::listen (senf::CommunicationPolicyBase)
senf::ServerSocketHandle::local AddressingPolicy::local (senf::AddressingPolicyBase)
senf::ServerSocketHandle::accept CommunicationPolicy::accept (senf::CommunicationPolicyBase)
senf::ServerSocketHandle::acceptfrom CommunicationPolicy::accept (senf::CommunicationPolicyBase)

A ServerSocketHandle is only meaningful for connection oriented addressable protocols (CommunicationPolicy is ConnectedCommunicationPolicy and AddressingPolicy is not NoAddressingPolicy).

It is important to note, that not all members are always accessible. Which are depends on the Policy template argument. If any of the policy axis is left unspecified the corresponding members will not be callable (you will get a compile time error). Even if every policy axis is defined, some members might (and will) not exist if they are meaningless for the protocol of the socket. This depends on the exact policy.

To find out, which members are available, you have to check the documentation of the policy classes. You can also find a summary of all members available in the leaf protocol class documentation.

Definition at line 36 of file ClientSocketHandle.hh.

Member Typedef Documentation

◆ Address

template<class SPolicy>
typedef SPolicy::AddressingPolicy::Address senf::ServerSocketHandle< SPolicy >::Address

Address type from the addressing policy.

Definition at line 72 of file ServerSocketHandle.hh.

◆ AddressParam

template<class SPolicy>
typedef boost::call_traits<Address>::param_type senf::ServerSocketHandle< SPolicy >::AddressParam

'Best' type for passing address as parameter

Depending on the type of Address, this will be either Address or Address const &. See call_traits documentation in the Boost.Utility library.

Definition at line 79 of file ServerSocketHandle.hh.

◆ ClientHandle

template<class SPolicy>
typedef ClientSocketHandle<SPolicy> senf::ServerSocketHandle< SPolicy >::ClientHandle

Corresponding client socket handle with the same policy.

Definition at line 81 of file ServerSocketHandle.hh.

Constructor & Destructor Documentation

◆ ServerSocketHandle() [1/4]

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

◆ ServerSocketHandle() [2/4]

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

◆ ServerSocketHandle() [3/4]

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

◆ ServerSocketHandle() [4/4]

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

Member Function Documentation

◆ accept()

template<class SPolicy>
ClientHandle senf::ServerSocketHandle< SPolicy >::accept ( )

Accept new connection.

If the handle is non-blocking, accept will NOT block. If no connection is available to be returned, accept will return a ClientSocketHandle which is not valid()

Exceptions
senf::SystemExceptionThis variant ...
Returns
handle of new client connection

◆ acceptfrom() [1/2]

template<class SPolicy>
std::pair<ClientHandle, Address> senf::ServerSocketHandle< SPolicy >::acceptfrom ( )

Accept new connection.

This variant will additionally return the remote address of the client

Returns
std::pair with client handle and client address.
See also
accept()

◆ acceptfrom() [2/2]

template<class SPolicy>
ClientHandle senf::ServerSocketHandle< SPolicy >::acceptfrom ( Address addr)

Accept new connection.

This variant will additionally return the remote address of the client

Parameters
[out]addraddress
Returns
handle of new client connection
See also
accept()

◆ bind()

template<class SPolicy>
void senf::ServerSocketHandle< SPolicy >::bind ( AddressParam  addr)

Set local address.

For addressable protocols (AddressingPolicy is not NoAddressingPolicy), bind() will set the local address of the socket.

Parameters
[in]addrLocal socket address to assign
Exceptions
senf::SystemException

◆ cast_dynamic()

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

◆ cast_static()

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

◆ dumpState()

template<class SPolicy>
std::string senf::ServerSocketHandle< SPolicy >::dumpState ( unsigned  lod = 0)

◆ listen()

template<class SPolicy>
void senf::ServerSocketHandle< SPolicy >::listen ( unsigned  backlog = 0)

Allow clients to connect to this server socket.

Todo:
This is very protocol specific, I don't want it in the policy interface. Especially the backlog argument seems quite protocol specific to me. However, we cannot listen() before we bind() so listen() cannot reside in the constructor. We need to find a good solution here.
Exceptions
senf::SystemException

◆ local() [1/2]

template<class SPolicy>
Address senf::ServerSocketHandle< SPolicy >::local ( )

Query local address.

This member will return the address of the local socket in addressable protocols (AddressingPolicy is not NoAddressingPolicy).

There are two Variants of this member, one will return the address by value, the other takes a reference argument to elide the copy operation.

Exceptions
senf::SystemException

◆ local() [2/2]

template<class SPolicy>
void senf::ServerSocketHandle< SPolicy >::local ( Address addr)

Query local address.

See also
local()

◆ operator=()

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

◆ state()

template<class SPolicy>
void senf::ServerSocketHandle< SPolicy >::state ( SocketStateMap &  map,
unsigned  lod = 0 
)

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