blob: 8d399fbc23106fe0297bf0904a879e50f2f80c85 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
|