diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/asiolink/io_socket.cc | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/lib/asiolink/io_socket.cc b/src/lib/asiolink/io_socket.cc new file mode 100644 index 0000000..f7792a9 --- /dev/null +++ b/src/lib/asiolink/io_socket.cc @@ -0,0 +1,57 @@ +// Copyright (C) 2010-2016 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include <config.h> +#include <asiolink/asio_wrapper.h> +#include <asiolink/io_socket.h> + +namespace isc { +namespace asiolink { + +/// \brief The \c DummySocket class is a concrete derived class of +/// \c IOSocket that is not associated with any real socket. +/// +/// This main purpose of this class is tests, where it may be desirable to +/// instantiate an \c IOSocket object without involving system resource +/// allocation such as real network sockets. +class DummySocket : public IOSocket { +private: + DummySocket(const DummySocket& source); + DummySocket& operator=(const DummySocket& source); +public: + /// \brief Constructor from the protocol number. + /// + /// The protocol must validly identify a standard network protocol. + /// For example, to specify TCP \c protocol must be \c IPPROTO_TCP. + /// + /// \param protocol The network protocol number for the socket. + DummySocket(const int protocol) : protocol_(protocol) {} + + /// \brief A dummy derived method of \c IOSocket::getNative(). + /// + /// This version of method always returns -1 as the object is not + /// associated with a real (native) socket. + virtual int getNative() const { return (-1); } + + virtual int getProtocol() const { return (protocol_); } +private: + const int protocol_; +}; + +IOSocket& +IOSocket::getDummyUDPSocket() { + static DummySocket socket(IPPROTO_UDP); + return (socket); +} + +IOSocket& +IOSocket::getDummyTCPSocket() { + static DummySocket socket(IPPROTO_TCP); + return (socket); +} + +} // namespace asiolink +} // namespace isc |