Socket Protocol base class. More...

#include <senf/Socket/SocketProtocol.hh>

Inherits noncopyable.

Inherited by senf::ConcreteSocketProtocol< ConnectedRawV4Socket_Policy, ConnectedRawV4SocketProtocol > [virtual], senf::ConcreteSocketProtocol< ConnectedRawV6Socket_Policy, ConnectedRawV6SocketProtocol > [virtual], senf::ConcreteSocketProtocol< ConnectedUDPv4Socket_Policy, ConnectedUDPv4SocketProtocol > [virtual], senf::ConcreteSocketProtocol< ConnectedUDPv6Socket_Policy, ConnectedUDPv6SocketProtocol > [virtual], senf::ConcreteSocketProtocol< ConnectedUNDatagramSocket_Policy, ConnectedUNDatagramSocketProtocol > [virtual], senf::ConcreteSocketProtocol< DVBDemux_Policy, DVBDemuxPESSocketProtocol > [virtual], senf::ConcreteSocketProtocol< DVBDemux_Policy, DVBDemuxSectionSocketProtocol > [virtual], senf::ConcreteSocketProtocol< DVBDemux_Policy, DVBDvrSocketProtocol > [virtual], senf::ConcreteSocketProtocol< DVBFrontend_Policy, DVBFrontendSocketProtocol > [virtual], senf::ConcreteSocketProtocol< MakeSocketPolicy< ConnectedMMapPacket_Policy, P1, P2 >::policy, ConnectedMMapPacketSocketProtocol< P1, P2 > > [virtual], senf::ConcreteSocketProtocol< Packet_Policy, PacketSocketProtocol > [virtual], senf::ConcreteSocketProtocol< RawV4Socket_Policy, RawV4SocketProtocol > [virtual], senf::ConcreteSocketProtocol< RawV6Socket_Policy, RawV6SocketProtocol > [virtual], senf::ConcreteSocketProtocol< Tap_Policy, TapSocketProtocol > [virtual], senf::ConcreteSocketProtocol< TCPv4Socket_Policy, TCPv4SocketProtocol > [virtual], senf::ConcreteSocketProtocol< TCPv6Socket_Policy, TCPv6SocketProtocol > [virtual], senf::ConcreteSocketProtocol< UDPv4Socket_Policy, UDPv4SocketProtocol > [virtual], senf::ConcreteSocketProtocol< UDPv6Socket_Policy, UDPv6SocketProtocol > [virtual], senf::ConcreteSocketProtocol< UNDatagramSocket_Policy, UNDatagramSocketProtocol > [virtual], senf::AddressableBSDSocketProtocol [virtual], senf::BSDSocketProtocol [virtual], senf::ConcreteSocketProtocol< SocketPolicy, Self > [virtual], senf::DatagramSocketProtocol [virtual], senf::DVBDemuxSocketProtocol [virtual], senf::DVBSocketProtocol [virtual], senf::INetSocketProtocol [virtual], senf::LinuxPacketSocketProtocol [virtual], senf::MMapReadableSocketProtocol [virtual], senf::MMapSocketProtocol [virtual], senf::MulticastSocketProtocol [virtual], senf::ReadableLinuxPacketProtocol [virtual], and senf::UNSocketProtocol [virtual].

Public Member Functions

virtual SocketPolicyBase const & policy () const =0
 Access the policy instance. More...
 
virtual unsigned available () const =0
 Return (maximum) number of bytes available for reading without < blocking. More...
 
virtual bool eof () const =0
 Check for end-of-file condition. More...
 
virtual void close ()
 Close socket. More...
 
virtual void terminate () const
 Forcibly close socket. More...
 
virtual void state (SocketStateMap &map, unsigned lod) const
 Return socket state information. More...
 
int fd () const
 Get file descriptor. More...
 

Protected Member Functions

FileHandle fh () const
 Get a FileHandle for this instance. More...
 
void fd (int) const
 Initialize file descriptor. More...
 

Structors and default members

 SocketProtocol ()
 
virtual ~SocketProtocol ()=0
 

Detailed Description

Socket Protocol base class.

This is the base class of all socket protocol classes. Every protocol class must directly or indirectly inherit from SocketProtocol

Attention
SocketProtocol must always be inherited using public virtual inheritance.

Definition at line 96 of file SocketProtocol.hh.

Constructor & Destructor Documentation

◆ SocketProtocol()

senf::SocketProtocol::SocketProtocol ( )

◆ ~SocketProtocol()

virtual senf::SocketProtocol::~SocketProtocol ( )
pure virtual

Member Function Documentation

◆ available()

virtual unsigned senf::SocketProtocol::available ( ) const
pure virtual

Return (maximum) number of bytes available for reading without < blocking.

This member will check in a (very, sigh) protocol dependent way, how many bytes may be read from a socket in a single (non-blocking) read operation. If the socket does not support reading (viz. NotReadablePolicy is set), this member should always return 0.

Depending on the protocol, it may not be possible to return a good value. In this case, an upper bound may be returned (e.g.: When reading from a socket which returns ethernet frames, returning 1500 from available() is ok). However, this should only be done as a last resort. Also beware, that this number should not be too large since the socket layer will always need to allocate that number of bytes for the data to be read.

Implemented in senf::DVBDvrSocketProtocol, senf::DVBDemuxPESSocketProtocol, senf::DVBFrontendSocketProtocol, senf::TapSocketProtocol, senf::DVBDemuxSectionSocketProtocol, senf::ReadableLinuxPacketProtocol, senf::TCPSocketProtocol, senf::MMapReadableSocketProtocol, senf::UNSocketProtocol, senf::UDPSocketProtocol, and senf::RawINetSocketProtocol.

◆ close()

void senf::SocketProtocol::close ( )
virtual

Close socket.

This override will automatically shutdown() the socket whenever it is closed.

Exceptions
senf::SystemException
Fix:
Move into (at least) BSDSOcketProtocol

Reimplemented in senf::DVBSocketProtocol, senf::TCPSocketProtocol, senf::UNSocketProtocol, and senf::MMapSocketProtocol.

Definition at line 28 of file SocketProtocol.cc.

◆ eof()

virtual bool senf::SocketProtocol::eof ( ) const
pure virtual

Check for end-of-file condition.

This is another check which (like available()) is extremely protocol dependent. This member will return true only, if at end-of-file. If the protocol does not support the notion of EOF, this member should always return false.

Implemented in senf::DVBFrontendSocketProtocol, senf::TapSocketProtocol, senf::TCPSocketProtocol, senf::LinuxPacketSocketProtocol, senf::UNSocketProtocol, senf::DVBDemuxSocketProtocol, senf::UDPSocketProtocol, and senf::RawINetSocketProtocol.

◆ fd() [1/2]

int senf::SocketProtocol::fd ( ) const

Get file descriptor.

Returns the file descriptor this protocol instance references. This is the same as fh().fd() but is implemented here since it is needed so often.

◆ fd() [2/2]

void senf::SocketProtocol::fd ( int  ) const
protected

Initialize file descriptor.

Assigns the file descriptor to the file handle, this protocol instance references. Only valid, if the file handle has not yet been assigned any descriptor (To change the file descriptor association later, use ::dup2()).

◆ fh()

FileHandle senf::SocketProtocol::fh ( ) const
protected

Get a FileHandle for this instance.

This member will re turn a FileHandle instance for this protocol instance. You may cast this FileHandle instance to a ClientSocketHandle / ServerSocketHandle as long as you know some of the socket policy using static_socket_cast or dynamic_socket_cast

◆ policy()

virtual SocketPolicyBase const& senf::SocketProtocol::policy ( ) const
pure virtual

Access the policy instance.

Implemented in senf::ConcreteSocketProtocol< SocketPolicy, Self >, senf::ConcreteSocketProtocol< ConnectedRawV4Socket_Policy, ConnectedRawV4SocketProtocol >, senf::ConcreteSocketProtocol< Tap_Policy, TapSocketProtocol >, senf::ConcreteSocketProtocol< DVBFrontend_Policy, DVBFrontendSocketProtocol >, senf::ConcreteSocketProtocol< ConnectedUDPv4Socket_Policy, ConnectedUDPv4SocketProtocol >, senf::ConcreteSocketProtocol< ConnectedUNDatagramSocket_Policy, ConnectedUNDatagramSocketProtocol >, senf::ConcreteSocketProtocol< ConnectedRawV6Socket_Policy, ConnectedRawV6SocketProtocol >, senf::ConcreteSocketProtocol< Packet_Policy, PacketSocketProtocol >, senf::ConcreteSocketProtocol< RawV6Socket_Policy, RawV6SocketProtocol >, senf::ConcreteSocketProtocol< DVBDemux_Policy, DVBDvrSocketProtocol >, senf::ConcreteSocketProtocol< UDPv4Socket_Policy, UDPv4SocketProtocol >, senf::ConcreteSocketProtocol< TCPv4Socket_Policy, TCPv4SocketProtocol >, senf::ConcreteSocketProtocol< TCPv6Socket_Policy, TCPv6SocketProtocol >, senf::ConcreteSocketProtocol< DVBDemux_Policy, DVBDemuxSectionSocketProtocol >, senf::ConcreteSocketProtocol< MakeSocketPolicy< ConnectedMMapPacket_Policy, P1, P2 >::policy, ConnectedMMapPacketSocketProtocol< P1, P2 > >, senf::ConcreteSocketProtocol< RawV4Socket_Policy, RawV4SocketProtocol >, senf::ConcreteSocketProtocol< UDPv6Socket_Policy, UDPv6SocketProtocol >, senf::ConcreteSocketProtocol< UNDatagramSocket_Policy, UNDatagramSocketProtocol >, senf::ConcreteSocketProtocol< ConnectedUDPv6Socket_Policy, ConnectedUDPv6SocketProtocol >, and senf::ConcreteSocketProtocol< DVBDemux_Policy, DVBDemuxPESSocketProtocol >.

◆ state()

void senf::SocketProtocol::state ( SocketStateMap &  map,
unsigned  lod 
) const
virtual

Return socket state information.

This member is called to add state information to the status map. The protocol map should provide as detailed information as possible. The amount of information to be added to the map is selected by the lod value with a default value of 0. The interpretation of the lod value is completely implementation defined.

Every class derived from SocketProtocol should reimplement state(). The reimplemented method should call (all) baseclass-implementations of this member.

The map Argument is a map which associates std:string keys with std:string-like values. The map keys are interpreted as hierarchical strings with '.' as a separator (like hostnames or struct or class members). They are automatically sorted correctly.

The values are std:string with one additional feature: they allow assignment or conversion from any type as long as that type is streamable. This simplifies assigning non-string values to the map:

map["socket.protocol.ip.address"] << peer();
map["socket.protocol.tcp.backlog"] << backlog();
                                         This will work even if peer() returns an ip-address
                                         object or backlog() returns an integer. The values are
                                         automatically converted to their string representation.

                                         Additionally, if the slot the date is written to is not
                                         empty, the <tt>\<\<</tt> operator will add add a comma
                                         as separator.  

Definition at line 49 of file SocketProtocol.cc.

◆ terminate()

void senf::SocketProtocol::terminate ( ) const
virtual

Forcibly close socket.

This override will automatically shutdown() the socket whenever it is called. Additionally it will disable SO_LINGER to ensure, that v_terminate will not block. Like the overridden method, this member will ignore failures and will never throw. It is therefore safe to be called from a destructor.

Fix:
Move into (at least) BSDSocketProtocol

Reimplemented in senf::UNSocketProtocol, and senf::MMapSocketProtocol.

Definition at line 34 of file SocketProtocol.cc.


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