Kea 2.5.5
ncr_io.h
Go to the documentation of this file.
1// Copyright (C) 2013-2020 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 NCR_IO_H
8#define NCR_IO_H
9
49
50#include <asiolink/io_address.h>
51#include <asiolink/io_service.h>
52#include <dhcp_ddns/ncr_msg.h>
54
55#include <boost/scoped_ptr.hpp>
56
57#include <deque>
58#include <mutex>
59
60namespace isc {
61namespace dhcp_ddns {
62
71};
72
82extern NameChangeProtocol stringToNcrProtocol(const std::string& protocol_str);
83
90extern std::string ncrProtocolToString(NameChangeProtocol protocol);
91
94public:
95 NcrListenerError(const char* file, size_t line, const char* what) :
96 isc::Exception(file, line, what) { };
97};
98
101public:
102 NcrListenerOpenError(const char* file, size_t line, const char* what) :
103 isc::Exception(file, line, what) { };
104};
105
108public:
109 NcrListenerReceiveError(const char* file, size_t line, const char* what) :
110 isc::Exception(file, line, what) { };
111};
112
113
168public:
169
171 enum Result {
175 ERROR
176 };
177
184 public:
185
198 virtual void operator ()(const Result result,
199 NameChangeRequestPtr& ncr) = 0;
200
202 }
203 };
204
209 NameChangeListener(RequestReceiveHandler& recv_handler);
210
213 };
214
226
231 void stopListening();
232
233protected:
243 void receiveNext();
244
270 void invokeRecvHandler(const Result result, NameChangeRequestPtr& ncr);
271
281 virtual void open(isc::asiolink::IOService& io_service) = 0;
282
290 virtual void close() = 0;
291
300 virtual void doReceive() = 0;
301
302public:
303
312 bool amListening() const {
313 return (listening_);
314 }
315
327 bool isIoPending() const {
328 return (io_pending_);
329 }
330
331private:
338 void setListening(bool value) {
339 listening_ = value;
340 }
341
343 bool listening_;
344
346 bool io_pending_;
347
349 RequestReceiveHandler& recv_handler_;
350};
351
353typedef boost::shared_ptr<NameChangeListener> NameChangeListenerPtr;
354
355
358public:
359 NcrSenderError(const char* file, size_t line, const char* what) :
360 isc::Exception(file, line, what) { };
361};
362
365public:
366 NcrSenderOpenError(const char* file, size_t line, const char* what) :
367 isc::Exception(file, line, what) { };
368};
369
372public:
373 NcrSenderQueueFull(const char* file, size_t line, const char* what) :
374 isc::Exception(file, line, what) { };
375};
376
379public:
380 NcrSenderSendError(const char* file, size_t line, const char* what) :
381 isc::Exception(file, line, what) { };
382};
383
384
412
461
467public:
468
470 typedef std::deque<NameChangeRequestPtr> SendQueue;
471
473 static const size_t MAX_QUEUE_DEFAULT = 1024;
474
476 enum Result {
480 ERROR
481 };
482
489 public:
490
502 virtual void operator ()(const Result result,
503 NameChangeRequestPtr& ncr) = 0;
504
506 }
507 };
508
516 NameChangeSender(RequestSendHandler& send_handler,
517 size_t send_queue_max = MAX_QUEUE_DEFAULT);
518
521 }
522
532 void startSending(isc::asiolink::IOService & io_service);
533
538 void stopSending();
539
551
564 void assumeQueue(NameChangeSender& source_sender);
565
579 virtual int getSelectFd() = 0;
580
584 virtual bool ioReady() = 0;
585
586private:
587
591 void startSendingInternal(isc::asiolink::IOService & io_service);
592
598 void sendRequestInternal(NameChangeRequestPtr& ncr);
599
606 void assumeQueueInternal(NameChangeSender& source_sender);
607
612 void invokeSendHandlerInternal(const NameChangeSender::Result result);
613
616 void skipNextInternal();
617
622 size_t getQueueSizeInternal() const;
623
631 const NameChangeRequestPtr& peekAtInternal(const size_t index) const;
632
633protected:
634
641 void sendNext();
642
670
680 virtual void open(isc::asiolink::IOService& io_service) = 0;
681
689 virtual void close() = 0;
690
701 virtual void doSend(NameChangeRequestPtr& ncr) = 0;
702
703public:
704
716 void skipNext();
717
725 void clearSendQueue();
726
733 bool amSending() const {
734 return (sending_);
735 }
736
743 bool isSendInProgress() const;
744
748 size_t getQueueMaxSize() const {
749 return (send_queue_max_);
750 }
751
760 void setQueueMaxSize(const size_t new_max);
761
765 size_t getQueueSize() const;
766
778 const NameChangeRequestPtr& peekAt(const size_t index) const;
779
799 virtual void runReadyIO();
800
801protected:
802
807 return (send_queue_);
808 }
809
810private:
811
818 void setSending(bool value) {
819 sending_ = value;
820 }
821
823 bool sending_;
824
826 RequestSendHandler& send_handler_;
827
829 size_t send_queue_max_;
830
832 SendQueue send_queue_;
833
835 NameChangeRequestPtr ncr_to_send_;
836
841 asiolink::IOService* io_service_;
842
844 const boost::scoped_ptr<std::mutex> mutex_;
845};
846
848typedef boost::shared_ptr<NameChangeSender> NameChangeSenderPtr;
849
850} // namespace dhcp_ddns
851} // namespace isc
852
853#endif
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.
Abstract class for defining application layer receive callbacks.
Definition: ncr_io.h:183
virtual void operator()(const Result result, NameChangeRequestPtr &ncr)=0
Function operator implementing a NCR receive callback.
Abstract interface for receiving NameChangeRequests.
Definition: ncr_io.h:167
void stopListening()
Closes the IO source and stops listen logic.
Definition: ncr_io.cc:94
virtual void close()=0
Abstract method which closes the IO source.
bool isIoPending() const
Returns true if the listener has an IO call in progress.
Definition: ncr_io.h:327
virtual void open(isc::asiolink::IOService &io_service)=0
Abstract method which opens the IO source for reception.
void startListening(isc::asiolink::IOService &io_service)
Prepares the IO for reception and initiates the first receive.
Definition: ncr_io.cc:61
virtual void doReceive()=0
Initiates an IO layer asynchronous read.
NameChangeListener(RequestReceiveHandler &recv_handler)
Constructor.
Definition: ncr_io.cc:54
void invokeRecvHandler(const Result result, NameChangeRequestPtr &ncr)
Calls the NCR receive handler registered with the listener.
Definition: ncr_io.cc:111
virtual ~NameChangeListener()
Destructor.
Definition: ncr_io.h:212
bool amListening() const
Returns true if the listener is listening, false otherwise.
Definition: ncr_io.h:312
Result
Defines the outcome of an asynchronous NCR receive.
Definition: ncr_io.h:171
void receiveNext()
Initiates an asynchronous receive.
Definition: ncr_io.cc:88
Abstract class for defining application layer send callbacks.
Definition: ncr_io.h:488
virtual void operator()(const Result result, NameChangeRequestPtr &ncr)=0
Function operator implementing a NCR send callback.
Abstract interface for sending NameChangeRequests.
Definition: ncr_io.h:466
void stopSending()
Closes the IO sink and stops send logic.
Definition: ncr_io.cc:207
virtual int getSelectFd()=0
Returns a file descriptor suitable for use with select.
Definition: ncr_io.cc:480
void assumeQueue(NameChangeSender &source_sender)
Move all queued requests from a given sender into the send queue.
Definition: ncr_io.cc:445
size_t getQueueMaxSize() const
Returns the maximum number of entries allowed in the send queue.
Definition: ncr_io.h:748
size_t getQueueSize() const
Returns the number of entries currently in the send queue.
Definition: ncr_io.cc:398
const NameChangeRequestPtr & peekAt(const size_t index) const
Returns the entry at a given position in the queue.
Definition: ncr_io.cc:413
virtual bool ioReady()=0
Returns whether or not the sender has IO ready to process.
virtual void open(isc::asiolink::IOService &io_service)=0
Abstract method which opens the IO sink for transmission.
void skipNext()
Removes the request at the front of the send queue.
Definition: ncr_io.cc:356
std::deque< NameChangeRequestPtr > SendQueue
Defines the type used for the request send queue.
Definition: ncr_io.h:470
void clearSendQueue()
Flushes all entries in the send queue.
Definition: ncr_io.cc:374
bool amSending() const
Returns true if the sender is in send mode, false otherwise.
Definition: ncr_io.h:733
NameChangeSender(RequestSendHandler &send_handler, size_t send_queue_max=MAX_QUEUE_DEFAULT)
Constructor.
Definition: ncr_io.cc:160
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.
Definition: ncr_io.cc:388
static const size_t MAX_QUEUE_DEFAULT
Defines a default maximum number of entries in the send queue.
Definition: ncr_io.h:473
virtual ~NameChangeSender()
Destructor.
Definition: ncr_io.h:520
void invokeSendHandler(const NameChangeSender::Result result)
Calls the NCR send completion handler registered with the sender.
Definition: ncr_io.cc:295
virtual void close()=0
Abstract method which closes the IO sink.
void sendRequest(NameChangeRequestPtr &ncr)
Queues the given request to be sent.
Definition: ncr_io.cc:239
virtual void runReadyIO()
Processes sender IO events.
Definition: ncr_io.cc:485
SendQueue & getSendQueue()
Returns a reference to the send queue.
Definition: ncr_io.h:806
bool isSendInProgress() const
Returns true when a send is in progress.
Definition: ncr_io.cc:435
Result
Defines the outcome of an asynchronous NCR send.
Definition: ncr_io.h:476
void sendNext()
Dequeues and sends the next request on the send queue in a thread safe context.
Definition: ncr_io.cc:272
void startSending(isc::asiolink::IOService &io_service)
Prepares the IO for transmission.
Definition: ncr_io.cc:170
Exception thrown if an NcrListenerError encounters a general error.
Definition: ncr_io.h:93
NcrListenerError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:95
Exception thrown if an error occurs during IO source open.
Definition: ncr_io.h:100
NcrListenerOpenError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:102
Exception thrown if an error occurs initiating an IO receive.
Definition: ncr_io.h:107
NcrListenerReceiveError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:109
Thrown when a NameChangeSender encounters an error.
Definition: ncr_io.h:357
NcrSenderError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:359
Exception thrown if an error occurs during IO source open.
Definition: ncr_io.h:364
NcrSenderOpenError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:366
Exception thrown if an error occurs initiating an IO send.
Definition: ncr_io.h:371
NcrSenderQueueFull(const char *file, size_t line, const char *what)
Definition: ncr_io.h:373
Exception thrown if an error occurs initiating an IO send.
Definition: ncr_io.h:378
NcrSenderSendError(const char *file, size_t line, const char *what)
Definition: ncr_io.h:380
NameChangeProtocol stringToNcrProtocol(const std::string &protocol_str)
Function which converts text labels to NameChangeProtocol enums.
Definition: ncr_io.cc:23
boost::shared_ptr< NameChangeListener > NameChangeListenerPtr
Defines a smart pointer to an instance of a listener.
Definition: ncr_io.h:353
NameChangeProtocol
Defines the list of socket protocols supported.
Definition: ncr_io.h:68
std::string ncrProtocolToString(NameChangeProtocol protocol)
Function which converts NameChangeProtocol enums to text labels.
Definition: ncr_io.cc:36
boost::shared_ptr< NameChangeSender > NameChangeSenderPtr
Defines a smart pointer to an instance of a sender.
Definition: ncr_io.h:848
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition: ncr_msg.h:242
Defines the logger used by the top-level component of kea-lfc.
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...