summaryrefslogtreecommitdiffstats
path: root/src/bin/perfdhcp/perf_socket.cc
diff options
context:
space:
mode:
authorMichal Nowikowski <godfryd@isc.org>2019-01-17 16:48:06 +0100
committerMichal Nowikowski <godfryd@isc.org>2019-01-18 10:05:12 +0100
commit1311cb038abc6431fc9103709db69ae75d0222ce (patch)
treefb31a2692f4fc5a8a5d1d96c22a23ba0c68614ec /src/bin/perfdhcp/perf_socket.cc
parent[#283,!135] Obsolete TestControl::receivePackets declaration removed (diff)
downloadkea-1311cb038abc6431fc9103709db69ae75d0222ce.tar.xz
kea-1311cb038abc6431fc9103709db69ae75d0222ce.zip
perfdhcp: renamed BetterSocket to PerfSocket, replaced std::mutex with isc::util::thread::Mutex
Diffstat (limited to 'src/bin/perfdhcp/perf_socket.cc')
-rw-r--r--src/bin/perfdhcp/perf_socket.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/bin/perfdhcp/perf_socket.cc b/src/bin/perfdhcp/perf_socket.cc
new file mode 100644
index 0000000000..c5b01cfa2e
--- /dev/null
+++ b/src/bin/perfdhcp/perf_socket.cc
@@ -0,0 +1,52 @@
+// Copyright (C) 2012-2018 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 <perfdhcp/perf_socket.h>
+
+#include <dhcp/iface_mgr.h>
+
+#include <boost/foreach.hpp>
+
+
+using namespace isc::dhcp;
+
+namespace isc {
+namespace perfdhcp {
+
+PerfSocket::PerfSocket(const int socket) :
+SocketInfo(asiolink::IOAddress("127.0.0.1"), 0, socket),
+ ifindex_(0), valid_(true) {
+ try {
+ initSocketData();
+ } catch (const Exception&) {
+ valid_ = false;
+ }
+}
+
+PerfSocket::~PerfSocket() {
+ IfacePtr iface = IfaceMgr::instance().getIface(ifindex_);
+ if (iface) {
+ iface->delSocket(sockfd_);
+ }
+}
+
+void
+PerfSocket::initSocketData() {
+ BOOST_FOREACH(IfacePtr iface, IfaceMgr::instance().getIfaces()) {
+ BOOST_FOREACH(SocketInfo s, iface->getSockets()) {
+ if (s.sockfd_ == sockfd_) {
+ ifindex_ = iface->getIndex();
+ addr_ = s.addr_;
+ return;
+ }
+ }
+ }
+ isc_throw(BadValue, "interface for specified socket descriptor not found");
+}
+
+}
+}