7 #ifndef PACKET_QUEUE_RING_H
8 #define PACKET_QUEUE_RING_H
12 #include <boost/circular_buffer.hpp>
13 #include <boost/scoped_ptr.hpp>
25 template<
typename PacketTypePtr>
38 queue_.set_capacity(capacity);
39 mutex_.reset(
new std::mutex);
109 std::lock_guard<std::mutex> lock(*mutex_);
111 queue_.push_back(packet);
113 queue_.push_front(packet);
127 PacketTypePtr packet;
128 std::lock_guard<std::mutex> lock(*mutex_);
130 if (queue_.empty()) {
135 packet = queue_.front();
138 packet = queue_.back();
156 PacketTypePtr packet;
157 if (!queue_.empty()) {
166 std::lock_guard<std::mutex> lock(*mutex_);
167 return(queue_.empty());
172 return (queue_.capacity());
182 if (capacity < MIN_RING_CAPACITY) {
184 <<
" is invalid. It must be at least "
185 << MIN_RING_CAPACITY);
189 queue_.set_capacity(capacity);
194 return (queue_.size());
213 boost::circular_buffer<PacketTypePtr> queue_;
216 boost::scoped_ptr<std::mutex> mutex_;
263 #endif // PACKET_QUEUE_RING_H
virtual const PacketTypePtr peek(const QueueEnd &from=QueueEnd::FRONT) const
Gets the packet currently at one end of the queue.
Interface for managing a queue of inbound DHCP packets.
boost::shared_ptr< Element > ElementPtr
virtual void setCapacity(size_t capacity)
Sets the maximum number of packets allowed in the buffer.
QueueEnd
Enumerates choices between the two ends of the queue.
Provides a ring-buffer implementation of the PacketQueue interface.
virtual PacketTypePtr popPacket(const QueueEnd &from=QueueEnd::FRONT)
Pops a packet from the queue.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual bool shouldDropPacket(PacketTypePtr, const SocketInfo &)
Determines if a packet should be discarded.
virtual int eatPackets(const QueueEnd &)
Discards packets from one end of the queue.
DHCPv4 packet queue buffer implementation.
virtual data::ElementPtr getInfo() const
Fetches pertinent information.
virtual void clear()
Discards all packets currently in the buffer.
virtual PacketTypePtr dequeuePacket()
Dequeues the next packet from the queue.
Defines the logger used by the top-level component of kea-dhcp-ddns.
virtual void pushPacket(PacketTypePtr &packet, const QueueEnd &to=QueueEnd::BACK)
Pushes a packet onto the queue.
static ElementPtr create(const Position &pos=ZERO_POSITION())
PacketQueueRing(const std::string &queue_type, size_t capacity)
Constructor.
PacketQueueRing6(const std::string &queue_type, size_t capacity)
Constructor.
virtual size_t getCapacity() const
Returns the maximum number of packets allowed in the buffer.
virtual size_t getSize() const
Returns the current number of packets in the buffer.
virtual void enqueuePacket(PacketTypePtr packet, const SocketInfo &source)
Adds a packet to the queue.
virtual ~PacketQueueRing()
virtual Destructor
static const size_t MIN_RING_CAPACITY
Minimum queue capacity permitted.
DHCPv6 packet queue buffer implementation.
virtual ~PacketQueueRing4()
virtual Destructor
virtual ~PacketQueueRing6()
virtual Destructor
virtual data::ElementPtr getInfo() const
Fetches operational information about the current state of the queue.
virtual bool empty() const
Returns True if the queue is empty.
Holds information about socket.
PacketQueueRing4(const std::string &queue_type, size_t capacity)
Constructor.