Kea
1.9.9-git
|
The IOSocket
class is an abstract base class to represent various types of network sockets.
More...
#include <io_socket.h>
Public Types | |
Types of objects encapsulating socket options. | |
typedef boost::asio::socket_base::reuse_address | ReuseAddress |
Represents SO_REUSEADDR socket option. More... | |
Public Member Functions | |
virtual int | getNative () const =0 |
Return the "native" representation of the socket. More... | |
virtual int | getProtocol () const =0 |
Return the transport protocol of the socket. More... | |
Static Public Member Functions | |
static IOSocket & | getDummyTCPSocket () |
Return a non-usable "dummy" TCP socket for testing. More... | |
static IOSocket & | getDummyUDPSocket () |
Return a non-usable "dummy" UDP socket for testing. More... | |
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. More... | |
virtual | ~IOSocket () |
The destructor. More... | |
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.
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.
|
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.
|
inlinevirtual |
The destructor.
Definition at line 65 of file io_socket.h.
|
static |
Return a non-usable "dummy" TCP socket for testing.
See getDummyUDPSocket()
. This method is its TCP version.
IOSocket
object whose getProtocol()
returns IPPROTO_TCP
. Definition at line 51 of file io_socket.cc.
|
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.
IOSocket
object whose getProtocol()
returns IPPROTO_UDP
. Definition at line 45 of file io_socket.cc.
|
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.
Implemented in isc::asiolink::DummyAsioSocket< C >, isc::asiolink::IOAsioSocket< C >, isc::asiolink::IOAsioSocket< SocketCallback >, isc::asiolink::TCPSocket< C >, isc::asiolink::TCPSocket< SocketCallback >, isc::asiolink::UDPSocket< C >, isc::asiolink::TLSSocket< C >, isc::asiolink::TLSSocket< SocketCallback >, isc::asiolink::IOAcceptor< ProtocolType, CallbackType >, isc::asiolink::IOAcceptor< boost::asio::local::stream_protocol, std::function< void(const boost::system::error_code &)> >, isc::asiolink::IOAcceptor< boost::asio::ip::tcp, C >, isc::asiolink::UnixDomainSocket, and isc::asiolink::DummySocket.
|
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.
Implemented in isc::asiolink::DummyAsioSocket< C >, isc::asiolink::IOAsioSocket< C >, isc::asiolink::IOAsioSocket< SocketCallback >, isc::asiolink::TCPSocket< C >, isc::asiolink::TCPSocket< SocketCallback >, isc::asiolink::UDPSocket< C >, isc::asiolink::TLSSocket< C >, isc::asiolink::TLSSocket< SocketCallback >, isc::asiolink::UnixDomainSocket, isc::asiolink::TCPAcceptor< C >, isc::asiolink::UnixDomainSocketAcceptor, and isc::asiolink::DummySocket.