Kea  1.9.9-git
receiver.h
Go to the documentation of this file.
1 // Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef PERFDHCP_RECEIVER_H
8 #define PERFDHCP_RECEIVER_H
9 
10 #include <perfdhcp/perf_socket.h>
12 
13 #include <dhcp/pkt.h>
14 
15 #include <queue>
16 #include <thread>
17 #include <mutex>
18 #include <atomic>
19 
20 namespace isc {
21 namespace perfdhcp {
22 
34 class Receiver {
35 private:
37  std::atomic_flag run_flag_;
38 
40  std::unique_ptr<std::thread> recv_thread_;
41 
43  std::queue<dhcp::PktPtr> pkt_queue_;
44 
46  std::mutex pkt_queue_mutex_;
47 
48  BasePerfSocket &socket_;
49 
51  bool single_threaded_;
52 
53  uint8_t ip_version_;
54 
55 public:
61  Receiver(BasePerfSocket &socket, bool single_threaded, uint8_t ip_version) :
62  socket_(socket),
63  single_threaded_(single_threaded),
64  ip_version_(ip_version) {
65  run_flag_.clear();
66  }
67 
69  ~Receiver();
70 
74  void start();
75 
79  void stop();
80 
86 
87 private:
89  void run();
90 
94  void receivePackets();
95 
97  dhcp::PktPtr readPktFromSocket();
98 };
99 
100 }
101 }
102 
103 #endif /* PERFDHCP_RECEIVER_H */
dhcp::PktPtr getPkt()
Get DHCP packet.
Definition: receiver.cc:58
~Receiver()
Destructor.
Definition: receiver.cc:49
void stop()
Stop a receiving thread in multi-thread mode.
Definition: receiver.cc:36
Receiver(BasePerfSocket &socket, bool single_threaded, uint8_t ip_version)
Receiver constructor.
Definition: receiver.h:61
void start()
Start a receiving thread in multi-thread mode.
Definition: receiver.cc:24
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
Definition: pkt.h:797
Defines the logger used by the top-level component of kea-dhcp-ddns.
Socket wrapper structure.
Definition: perf_socket.h:26
A receiving DHCP packets class.
Definition: receiver.h:34