Kea 2.7.5
isc::asiolink::IOSocket Class Referenceabstract

The IOSocket class is an abstract base class to represent various types of network sockets. More...

#include <io_socket.h>

+ Inheritance diagram for isc::asiolink::IOSocket:

Public Types

Types of objects encapsulating socket options.
typedef boost::asio::socket_base::reuse_address ReuseAddress
 Represents SO_REUSEADDR socket option.
 

Constructors and Destructor

Note: The copy constructor and the assignment operator are intentionally defined as private, making this class non-copyable.

 IOSocket ()
 The default constructor.
 
virtual ~IOSocket ()
 The destructor.
 
virtual int getNative () const =0
 Return the "native" representation of the socket.
 
virtual int getProtocol () const =0
 Return the transport protocol of the socket.
 
static IOSocketgetDummyUDPSocket ()
 Return a non-usable "dummy" UDP socket for testing.
 
static IOSocketgetDummyTCPSocket ()
 Return a non-usable "dummy" TCP socket for testing.
 

Detailed Description

The IOSocket class is an abstract base class to represent various types of network sockets.

This class is a wrapper for the ASIO socket classes such as ip::tcp::socket and ip::udp::socket.

Derived class implementations are completely hidden within the implementation. User applications only get access to concrete IOSocket objects via the abstract interfaces.

We may revisit this decision when we generalize the wrapper and more modules use it. Also, at that point we may define a separate (visible) derived class for testing purposes rather than providing factory methods (i.e., getDummy variants below).

Definition at line 37 of file io_socket.h.

Member Typedef Documentation

◆ ReuseAddress

typedef boost::asio::socket_base::reuse_address isc::asiolink::IOSocket::ReuseAddress

Represents SO_REUSEADDR socket option.

Definition at line 44 of file io_socket.h.

Constructor & Destructor Documentation

◆ IOSocket()

isc::asiolink::IOSocket::IOSocket ( )
inlineprotected

The default constructor.

This is intentionally defined as protected as this base class should never be instantiated (except as part of a derived class).

Definition at line 62 of file io_socket.h.

◆ ~IOSocket()

virtual isc::asiolink::IOSocket::~IOSocket ( )
inlinevirtual

The destructor.

Definition at line 65 of file io_socket.h.

Member Function Documentation

◆ getDummyTCPSocket()

IOSocket & isc::asiolink::IOSocket::getDummyTCPSocket ( )
static

Return a non-usable "dummy" TCP socket for testing.

See getDummyUDPSocket(). This method is its TCP version.

Returns
A reference to an IOSocket object whose getProtocol() returns IPPROTO_TCP.

Definition at line 51 of file io_socket.cc.

◆ getDummyUDPSocket()

IOSocket & isc::asiolink::IOSocket::getDummyUDPSocket ( )
static

Return a non-usable "dummy" UDP socket for testing.

This is a class method that returns a "mock" of UDP socket. This is not associated with any actual socket, and its only responsibility is to return IPPROTO_UDP from getProtocol(). The only feasible usage of this socket is for testing so that the test code can prepare some "UDP data" even without opening any actual socket.

This method never throws an exception.

Returns
A reference to an IOSocket object whose getProtocol() returns IPPROTO_UDP.

Definition at line 45 of file io_socket.cc.

◆ getNative()

virtual int isc::asiolink::IOSocket::getNative ( ) const
pure virtual

Return the "native" representation of the socket.

In practice, this is the file descriptor of the socket for UNIX-like systems so the current implementation simply uses int as the type of the return value. We may have to need revisit this decision later.

In general, the application should avoid using this method; it essentially discloses an implementation specific "handle" that can change the internal state of the socket (consider the application closes it, for example). But we sometimes need to perform very low-level operations that requires the native representation. Passing the file descriptor to a different process is one example. This method is provided as a necessary evil for such limited purposes.

This method never throws an exception.

Returns
The native representation of the socket. This is the socket file descriptor for UNIX-like systems.

Implemented in isc::asiolink::IOAcceptor< ProtocolType, CallbackType >, isc::asiolink::IOAcceptor< boost::asio::ip::tcp, C >, isc::asiolink::IOAcceptor< boost::asio::local::stream_protocol, std::function< void(const boost::system::error_code &)> >, isc::asiolink::DummyAsioSocket< C >, isc::asiolink::DummySocket, isc::asiolink::TCPSocket< C >, isc::asiolink::TCPSocket< SocketCallback >, isc::asiolink::TLSSocket< C >, isc::asiolink::TLSSocket< SocketCallback >, isc::asiolink::UDPSocket< C >, isc::asiolink::UnixDomainSocket, isc::asiolink::IOAsioSocket< C >, and isc::asiolink::IOAsioSocket< SocketCallback >.

◆ getProtocol()

virtual int isc::asiolink::IOSocket::getProtocol ( ) const
pure virtual

Return the transport protocol of the socket.

Currently, it returns IPPROTO_UDP for UDP sockets, and IPPROTO_TCP for TCP sockets.

This method never throws an exception.

Returns
IPPROTO_UDP for UDP sockets
IPPROTO_TCP for TCP sockets

Implemented in isc::asiolink::DummyAsioSocket< C >, isc::asiolink::DummySocket, isc::asiolink::TCPSocket< C >, isc::asiolink::TCPSocket< SocketCallback >, isc::asiolink::TLSSocket< C >, isc::asiolink::TLSSocket< SocketCallback >, isc::asiolink::UDPSocket< C >, isc::asiolink::UnixDomainSocket, isc::asiolink::IOAsioSocket< C >, isc::asiolink::TCPAcceptor< C >, isc::asiolink::UnixDomainSocketAcceptor, and isc::asiolink::IOAsioSocket< SocketCallback >.


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