senf::SocketProtocol Class Reference
[The Protocol Classes]

Socket Protocol base class. More...

#include <senf/Socket/SocketProtocol.hh>

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< 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::MulticastSocketProtocol [virtual],
senf::UNSocketProtocol [virtual].

List of all members.


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 118 of file SocketProtocol.hh.


Public Member Functions

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

Structors and default members

  SocketProtocol ()
virtual  ~SocketProtocol ()=0

Protected Member Functions

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

Constructor & Destructor Documentation

senf::SocketProtocol::
SocketProtocol ()

Definition at line 57 of file SocketProtocol.cci.

senf::SocketProtocol::
~SocketProtocol ()

Definition at line 60 of file SocketProtocol.cci.


Member Function Documentation

virtual unsigned senf::SocketProtocol::
available ()

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::DVBDemuxSectionSocketProtocol, senf::DVBDemuxPESSocketProtocol, senf::DVBDvrSocketProtocol, senf::DVBFrontendSocketProtocol, senf::RawINetSocketProtocol, senf::TCPSocketProtocol, senf::UDPSocketProtocol, senf::PacketSocketProtocol, senf::TapSocketProtocol, and senf::UNSocketProtocol.

void senf::SocketProtocol::
close ()

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, and senf::UNSocketProtocol.

Definition at line 37 of file SocketProtocol.cc.

virtual bool senf::SocketProtocol::
eof ()

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::DVBDemuxSocketProtocol, senf::DVBFrontendSocketProtocol, senf::RawINetSocketProtocol, senf::TCPSocketProtocol, senf::UDPSocketProtocol, senf::PacketSocketProtocol, senf::TapSocketProtocol, and senf::UNSocketProtocol.

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

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

Definition at line 50 of file SocketProtocol.cci.

int senf::SocketProtocol::
fd ()

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.

Definition at line 44 of file SocketProtocol.cci.

senf::FileHandle senf::SocketProtocol::
fh ()

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

Definition at line 38 of file SocketProtocol.cci.

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

Access the policy instance.

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

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

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 << operator will add add a comma as separator.

Definition at line 58 of file SocketProtocol.cc.

void senf::SocketProtocol::
terminate ()

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.

Definition at line 43 of file SocketProtocol.cc.


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