 |
Kea
1.5.0
|
Go to the documentation of this file.
12 #include <boost/algorithm/string/predicate.hpp>
18 if (boost::iequals(protocol_str,
"UDP")) {
22 if (boost::iequals(protocol_str,
"TCP")) {
27 "Invalid NameChangeRequest protocol: " << protocol_str);
40 std::ostringstream stream;
41 stream <<
"UNKNOWN(" << protocol <<
")";
42 return (stream.str());
50 : listening_(false), io_pending_(false), recv_handler_(recv_handler) {
113 recv_handler_(result, ncr);
114 }
catch (
const std::exception& ex) {
142 recv_handler_(
ERROR, empty);
143 }
catch (
const std::exception& ex) {
145 DHCP_DDNS_UNCAUGHT_NCR_RECV_HANDLER_ERROR)
155 size_t send_queue_max)
156 : sending_(false), send_handler_(send_handler),
157 send_queue_max_(send_queue_max), io_service_(NULL) {
171 ncr_to_send_.reset();
176 io_service_ = &io_service;
198 if (
ioReady() && io_service_ != NULL) {
201 }
catch (
const std::exception& ex) {
205 DHCP_DDNS_NCR_FLUSH_IO_ERROR).arg(ex.what());
216 DHCP_DDNS_NCR_SEND_CLOSE_ERROR).arg(ex.
what());
232 if (send_queue_.size() >= send_queue_max_) {
234 "send queue has reached maximum capacity: "
235 << send_queue_max_ );
239 send_queue_.push_back(ncr);
256 if (!send_queue_.empty()) {
257 ncr_to_send_ = send_queue_.front();
273 send_queue_.pop_front();
282 send_handler_(result, ncr_to_send_);
283 }
catch (
const std::exception& ex) {
289 ncr_to_send_.reset();
311 send_handler_(
ERROR, ncr_to_send_);
312 }
catch (
const std::exception& ex) {
314 DHCP_DDNS_UNCAUGHT_NCR_SEND_HANDLER_ERROR).arg(ex.what());
321 if (!send_queue_.empty()) {
323 send_queue_.pop_front();
340 " queue size must be greater than zero");
343 send_queue_max_ = new_max;
350 "NameChangeSender::peekAt peek beyond end of queue attempted"
351 <<
" index: " << index <<
" queue size: " <<
getQueueSize());
354 return (send_queue_.at(index));
362 " source sender is actively sending");
367 " target sender is actively sending");
372 " source queue count exceeds target queue max");
375 if (!send_queue_.empty()) {
377 " target queue is not empty");
392 " sender io service is null");
virtual void close()=0
Abstract method which closes the IO source.
void setQueueMaxSize(const size_t new_max)
Sets the maximum queue size to the given value.
size_t getQueueMaxSize() const
Returns the maximum number of entries allowed in the send queue.
void assumeQueue(NameChangeSender &source_sender)
Move all queued requests from a given sender into the send queue.
Abstract interface for sending NameChangeRequests.
NameChangeListener(RequestReceiveHandler &recv_handler)
Constructor.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
NameChangeSender(RequestSendHandler &send_handler, size_t send_queue_max=MAX_QUEUE_DEFAULT)
Constructor.
void skipNext()
Removes the request at the front of the send queue.
boost::asio::io_service & get_io_service()
Return the native io_service object used in this wrapper.
virtual void doReceive()=0
Initiates an IO layer asynchronous read.
Result
Defines the outcome of an asynchronous NCR send.
void stopSending()
Closes the IO sink and stops send logic.
The IOService class is a wrapper for the ASIO io_service class.
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
void clearSendQueue()
Flushes all entries in the send queue.
virtual void open(isc::asiolink::IOService &io_service)=0
Abstract method which opens the IO sink for transmission.
Abstract class for defining application layer send callbacks.
Exception thrown if an error occurs during IO source open.
void stopListening()
Closes the IO source and stops listen logic.
virtual bool ioReady()=0
Returns whether or not the sender has IO ready to process.
Abstract class for defining application layer receive callbacks.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void sendRequest(NameChangeRequestPtr &ncr)
Queues the given request to be sent.
bool amListening() const
Returns true if the listener is listening, false otherwise.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
virtual void close()=0
Abstract method which closes the IO sink.
Exception thrown if an error occurs during IO source open.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
void startListening(isc::asiolink::IOService &io_service)
Prepares the IO for reception and initiates the first receive.
const NameChangeRequestPtr & peekAt(const size_t index) const
Returns the entry at a given position in the queue.
void invokeSendHandler(const NameChangeSender::Result result)
Calls the NCR send completion handler registered with the sender.
virtual void open(isc::asiolink::IOService &io_service)=0
Abstract method which opens the IO source for reception.
virtual void doSend(NameChangeRequestPtr &ncr)=0
Initiates an IO layer asynchronous send.
void sendNext()
Dequeues and sends the next request on the send queue.
Exception thrown if an NcrListenerError encounters a general error.
void startSending(isc::asiolink::IOService &io_service)
Prepares the IO for transmission.
Thrown when a NameChangeSender encounters an error.
std::string ncrProtocolToString(NameChangeProtocol protocol)
Function which converts NameChangeProtocol enums to text labels.
isc::log::Logger dhcp_ddns_logger("libdhcp-ddns")
Defines the logger used within lib dhcp_ddns.
Exception thrown if an error occurs initiating an IO receive.
bool amSending() const
Returns true if the sender is in send mode, false otherwise.
Result
Defines the outcome of an asynchronous NCR receive.
Exception thrown if an error occurs initiating an IO send.
This file defines abstract classes for exchanging NameChangeRequests.
A generic exception that is thrown when a function is not implemented.
void invokeRecvHandler(const Result result, NameChangeRequestPtr &ncr)
Calls the NCR receive handler registered with the listener.
virtual void runReadyIO()
Processes sender IO events.
virtual int getSelectFd()=0
Returns a file descriptor suitable for use with select.
size_t getQueueSize() const
Returns the number of entries currently in the send queue.
NameChangeProtocol stringToNcrProtocol(const std::string &protocol_str)
Function which converts labels to NameChangeProtocol enum values.
SendQueue & getSendQueue()
Returns a reference to the send queue.
void receiveNext()
Initiates an asynchronous receive.
NameChangeProtocol
Defines the list of socket protocols supported.