7#ifndef PACKET_STORAGE_H
8#define PACKET_STORAGE_H
10#include <boost/noncopyable.hpp>
11#include <boost/shared_ptr.hpp>
49 typedef typename std::list<PacketPtr> PacketContainer;
51 typedef typename PacketContainer::iterator PacketContainerIterator;
62 storage_.push_back(
packet);
63 if (storage_.size() == 1) {
64 current_pointer_ = storage_.begin();
77 void clear(
const uint64_t num = 0) {
79 PacketContainerIterator last = storage_.begin();
80 std::advance(last, num >
size() ?
size() : num);
81 current_pointer_ = storage_.erase(storage_.begin(), last);
84 current_pointer_ = storage_.begin();
92 return (storage_.empty());
103 if (storage_.empty()) {
105 }
else if (current_pointer_ == storage_.end()) {
106 current_pointer_ = storage_.begin();
109 current_pointer_ = storage_.erase(current_pointer_);
126 current_pointer_ = storage_.begin();
128 std::advance(current_pointer_, rand() % (
size() - 1));
131 current_pointer_ = storage_.erase(current_pointer_);
139 return (storage_.size());
144 std::list<PacketPtr> storage_;
145 PacketContainerIterator current_pointer_;
read_packet FORK if not parent: break YIELD answer=DNSLookup(packet, this) response=DNSAnswer(answer) YIELD send(response) At each "YIELD" point, the coroutine initiates an asynchronous operation, then pauses and turns over control to some other task on the ASIO service queue. When the operation completes, the coroutine resumes. The DNSLookup and DNSAnswer define callback methods used by a DNS Server to communicate with the module that called it. They are abstract-only classes whose concrete implementations are supplied by the calling module. The DNSLookup callback always runs asynchronously. Concrete implementations must be sure to call the server 's "resume" method when it is finished. In an authoritative server, the DNSLookup implementation would examine the query, look up the answer, then call "resume"(See the diagram in doc/auth_process.jpg). In a recursive server, the DNSLookup implementation would initiate a DNSQuery, which in turn would be responsible for calling the server 's "resume" method(See the diagram in doc/recursive_process.jpg). A DNSQuery object is intended to handle resolution of a query over the network when the local authoritative data sources or cache are not sufficient. The plan is that it will make use of subsidiary DNSFetch calls to get data from particular authoritative servers, and when it has gotten a complete answer, it calls "resume". In current form, however, DNSQuery is much simpler packet
void append(const PacketPtr &packet)
Appends the new packet object to the collection.
uint64_t size() const
Returns number of packets in the storage.
void clear(const uint64_t num=0)
Removes packets from the storage.
bool empty() const
Checks if the storage has no packets.
PacketPtr getNext()
Returns next packet from the storage.
boost::shared_ptr< T > PacketPtr
A type which represents the pointer to a packet.
PacketPtr getRandom()
Returns random packet from the storage.
PacketStorage()
Constructor.
Defines the logger used by the top-level component of kea-lfc.