13#include <boost/algorithm/string/predicate.hpp>
20using namespace isc::util;
24 if (boost::iequals(protocol_str,
"UDP")) {
28 if (boost::iequals(protocol_str,
"TCP")) {
33 "Invalid NameChangeRequest protocol: " << protocol_str);
46 std::ostringstream stream;
47 stream <<
"UNKNOWN(" << protocol <<
")";
48 return (stream.str());
54 : listening_(false), io_pending_(false), recv_handler_(recv_handler) {
116 (*recv_handler_)(result, ncr);
117 }
catch (
const std::exception& ex) {
153 (*recv_handler_)(
ERROR, empty);
154 }
catch (
const std::exception& std_ex) {
165 size_t send_queue_max)
166 : sending_(false), send_handler_(send_handler),
167 send_queue_max_(send_queue_max), mutex_(new mutex()) {
183 lock_guard<mutex> lock(*mutex_);
184 startSendingInternal(io_service);
186 startSendingInternal(io_service);
197 ncr_to_send_.reset();
221 }
catch (
const std::exception& ex) {
242 }
catch (
const std::exception& ex) {
264 lock_guard<mutex> lock(*mutex_);
265 sendRequestInternal(ncr);
267 sendRequestInternal(ncr);
273 if (send_queue_.size() >= send_queue_max_) {
275 "send queue has reached maximum capacity: "
280 send_queue_.push_back(ncr);
297 if (!send_queue_.empty()) {
298 ncr_to_send_ = send_queue_.front();
310 }
catch (
const std::exception& ex) {
313 send_queue_.pop_front();
315 invokeSendHandlerInternal(
ERROR);
323 lock_guard<mutex> lock(*mutex_);
324 invokeSendHandlerInternal(result);
326 invokeSendHandlerInternal(result);
335 send_queue_.pop_front();
344 (*send_handler_)(result, ncr_to_send_);
345 }
catch (
const std::exception& ex) {
351 ncr_to_send_.reset();
358 }
catch (
const isc::Exception& isc_ex) {
373 (*send_handler_)(
ERROR, ncr_to_send_);
374 }
catch (
const std::exception& std_ex) {
384 lock_guard<mutex> lock(*mutex_);
392NameChangeSender::skipNextInternal() {
393 if (!send_queue_.empty()) {
395 send_queue_.pop_front();
406 lock_guard<mutex> lock(*mutex_);
417 " queue size must be greater than zero");
420 send_queue_max_ = new_max;
426 lock_guard<mutex> lock(*mutex_);
427 return (getQueueSizeInternal());
429 return (getQueueSizeInternal());
434NameChangeSender::getQueueSizeInternal()
const {
435 return (send_queue_.size());
441 lock_guard<mutex> lock(*mutex_);
442 return (peekAtInternal(index));
444 return (peekAtInternal(index));
449NameChangeSender::peekAtInternal(
const size_t index)
const {
450 auto size = getQueueSizeInternal();
453 "NameChangeSender::peekAt peek beyond end of queue attempted"
454 <<
" index: " << index <<
" queue size: " << size);
457 return (send_queue_.at(index));
463 lock_guard<mutex> lock(*mutex_);
464 return ((ncr_to_send_) ?
true :
false);
466 return ((ncr_to_send_) ?
true :
false);
474 " source sender is actively sending");
479 " target sender is actively sending");
484 " source queue count exceeds target queue max");
488 lock_guard<mutex> lock(*mutex_);
489 assumeQueueInternal(source_sender);
491 assumeQueueInternal(source_sender);
497 if (!send_queue_.empty()) {
499 " target queue is not empty");
514 " sender io service is null");
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when a function is not implemented.
virtual void open(const isc::asiolink::IOServicePtr &io_service)=0
Abstract method which opens the IO source for reception.
boost::shared_ptr< RequestReceiveHandler > RequestReceiveHandlerPtr
Defines a smart pointer to an instance of a request receive handler.
void stopListening()
Closes the IO source and stops listen logic.
virtual void close()=0
Abstract method which closes the IO source.
NameChangeListener(RequestReceiveHandlerPtr recv_handler)
Constructor.
Result
Defines the outcome of an asynchronous NCR receive.
virtual void doReceive()=0
Initiates an IO layer asynchronous read.
void invokeRecvHandler(const Result result, NameChangeRequestPtr &ncr)
Calls the NCR receive handler registered with the listener.
bool amListening() const
Returns true if the listener is listening, false otherwise.
void receiveNext()
Initiates an asynchronous receive.
void startListening(const isc::asiolink::IOServicePtr &io_service)
Prepares the IO for reception and initiates the first receive.
void scheduleNextReceive()
Schedules the next asynchronous receive if still listening.
Abstract interface for sending NameChangeRequests.
asiolink::IOServicePtr io_service_
Pointer to the IOService currently being used by the sender.
void stopSending()
Closes the IO sink and stops send logic.
virtual int getSelectFd()=0
Returns a file descriptor suitable for use with select.
void startSending(const isc::asiolink::IOServicePtr &io_service)
Prepares the IO for transmission.
NameChangeSender(RequestSendHandlerPtr send_handler, size_t send_queue_max=MAX_QUEUE_DEFAULT)
Constructor.
void assumeQueue(NameChangeSender &source_sender)
Move all queued requests from a given sender into the send queue.
Result
Defines the outcome of an asynchronous NCR send.
size_t getQueueMaxSize() const
Returns the maximum number of entries allowed in the send queue.
size_t getQueueSize() const
Returns the number of entries currently in the send queue.
const NameChangeRequestPtr & peekAt(const size_t index) const
Returns the entry at a given position in the queue.
virtual bool ioReady()=0
Returns whether or not the sender has IO ready to process.
void skipNext()
Removes the request at the front of the send queue.
boost::shared_ptr< RequestSendHandler > RequestSendHandlerPtr
Defines a smart pointer to an instance of a request send handler.
void clearSendQueue()
Flushes all entries in the send queue.
bool amSending() const
Returns true if the sender is in send mode, false otherwise.
virtual void doSend(NameChangeRequestPtr &ncr)=0
Initiates an IO layer asynchronous send.
void setQueueMaxSize(const size_t new_max)
Sets the maximum queue size to the given value.
void invokeSendHandler(const NameChangeSender::Result result)
Calls the NCR send completion handler registered with the sender.
virtual void open(const isc::asiolink::IOServicePtr &io_service)=0
Abstract method which opens the IO sink for transmission.
virtual void close()=0
Abstract method which closes the IO sink.
void sendRequest(NameChangeRequestPtr &ncr)
Queues the given request to be sent.
virtual void runReadyIO()
Processes sender IO events.
SendQueue & getSendQueue()
Returns a reference to the send queue.
bool isSendInProgress() const
Returns true when a send is in progress.
void sendNext()
Dequeues and sends the next request on the send queue in a thread safe context.
Exception thrown if an NcrListenerError encounters a general error.
Exception thrown if an error occurs during IO source open.
Exception thrown if an error occurs initiating an IO receive.
Thrown when a NameChangeSender encounters an error.
Exception thrown if an error occurs during IO source open.
Exception thrown if an error occurs initiating an IO send.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
isc::log::Logger dhcp_ddns_logger("libdhcp-ddns")
Defines the logger used within lib dhcp_ddns.
NameChangeProtocol stringToNcrProtocol(const std::string &protocol_str)
Function which converts text labels to NameChangeProtocol enums.
const isc::log::MessageID DHCP_DDNS_NCR_SEND_CLOSE_ERROR
const isc::log::MessageID DHCP_DDNS_NCR_SEND_NEXT_ERROR
NameChangeProtocol
Defines the list of socket protocols supported.
const isc::log::MessageID DHCP_DDNS_NCR_FLUSH_IO_ERROR
std::string ncrProtocolToString(NameChangeProtocol protocol)
Function which converts NameChangeProtocol enums to text labels.
const isc::log::MessageID DHCP_DDNS_UNCAUGHT_NCR_SEND_HANDLER_ERROR
const isc::log::MessageID DHCP_DDNS_UNCAUGHT_NCR_RECV_HANDLER_ERROR
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
const isc::log::MessageID DHCP_DDNS_NCR_LISTEN_CLOSE_ERROR
const isc::log::MessageID DHCP_DDNS_NCR_RECV_NEXT_ERROR
Defines the logger used by the top-level component of kea-lfc.
This file defines abstract classes for exchanging NameChangeRequests.