15namespace ph = std::placeholders;
24 : handler_(handler), data_(new
Data(buffer, buf_size, data_source)) {
36 const size_t bytes_transferred) {
47 handler_(!error_code,
this);
56 if (len > data_->buf_size_) {
60 memcpy (data_->buffer_.get(), src, len);
61 data_->put_len_ = len;
69 const bool reuse_address)
71 port_(port), format_(format), reuse_address_(reuse_address) {
79 this, ph::_1, ph::_2)));
93 io_service_ = io_service;
97 asio_socket_.reset(
new boost::asio::ip::udp::
98 socket(io_service_->getInternalIOService(),
99 (ip_address_.
isV4() ? boost::asio::ip::udp::v4() :
100 boost::asio::ip::udp::v6())));
103 if (reuse_address_) {
104 asio_socket_->set_option(boost::asio::socket_base::reuse_address(
true));
109 }
catch (
const boost::system::system_error& ex) {
110 asio_socket_.reset();
123 socket_->asyncReceive(recv_buffer.get(), recv_callback_->getBufferSize(),
124 0, recv_callback_->getDataSource().get(),
136 if (asio_socket_->is_open()) {
138 asio_socket_->close();
139 }
catch (
const boost::system::system_error& ex) {
148 asio_socket_.reset();
172 static_cast<int64_t
>(1));
177 static_cast<int64_t
>(1));
185 boost::system::error_code error_code = callback->
getErrorCode();
186 if (error_code.value() == boost::asio::error::operation_aborted) {
194 .arg(error_code.message());
196 static_cast<int64_t
>(1));
213 const size_t send_que_max,
const bool reuse_address)
215 ip_address_(ip_address), port_(port), server_address_(server_address),
216 server_port_(server_port), format_(format),
217 reuse_address_(reuse_address) {
225 this, ph::_1, ph::_2)));
242 asio_socket_.reset(
new boost::asio::ip::udp::
244 (ip_address_.
isV4() ? boost::asio::ip::udp::v4() :
245 boost::asio::ip::udp::v6())));
248 if (reuse_address_) {
249 asio_socket_->set_option(boost::asio::socket_base::reuse_address(
true));
254 }
catch (
const boost::system::system_error& ex) {
255 asio_socket_.reset();
265 UDPEndpoint(server_address_, server_port_));
267 send_callback_->setDataSource(server_endpoint_);
281 if (asio_socket_->is_open()) {
283 asio_socket_->close();
284 }
catch (
const boost::system::system_error& ex) {
293 asio_socket_.reset();
302 watch_socket_.reset();
309 ncr->toFormat(format_, ncr_buffer);
316 socket_->asyncSend(send_callback_->getData(), send_callback_->getPutLen(),
317 send_callback_->getDataSource().get(), *send_callback_);
324 watch_socket_->markReady();
330 if (!watch_socket_) {
335 watch_socket_->clearReady();
336 }
catch (
const std::exception& ex) {
352 boost::system::error_code error_code = send_callback->
getErrorCode();
353 if (error_code.value() == boost::asio::error::operation_aborted) {
355 .arg(error_code.message());
359 .arg(error_code.message());
372 " not in send mode");
375 return (watch_socket_->getSelectFd());
381 return (watch_socket_->isReady());
388NameChangeUDPSender::closeWatchSocket() {
390 std::string error_string;
391 watch_socket_->closeSocket(error_string);
392 if (!error_string.empty()) {
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.
The IOAddress class represents an IP addresses (version agnostic)
bool isV4() const
Convenience function to check for an IPv4 address.
The UDPEndpoint class is a concrete derived class of IOEndpoint that represents an endpoint of a UDP ...
const boost::asio::ip::udp::endpoint & getASIOEndpoint() const
Abstract interface for receiving NameChangeRequests.
void stopListening()
Closes the IO source and stops listen logic.
boost::shared_ptr< RequestReceiveHandler > RequestReceiveHandlerPtr
Defines a smart pointer to an instance of a request receive handler.
void invokeRecvHandler(const Result result, NameChangeRequestPtr &ncr)
Calls the NCR receive handler registered with the listener.
Result
Defines the outcome of an asynchronous NCR receive.
void receiveNext()
Initiates an asynchronous receive.
static NameChangeRequestPtr fromFormat(const NameChangeFormat format, isc::util::InputBuffer &buffer)
Static method for creating a NameChangeRequest from a buffer containing a marshalled request in a giv...
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.
bool amSending() const
Returns true if the sender is in send mode, false otherwise.
boost::shared_ptr< RequestSendHandler > RequestSendHandlerPtr
Defines a smart pointer to an instance of a request send handler.
void invokeSendHandler(const NameChangeSender::Result result)
Calls the NCR send completion handler registered with the sender.
Result
Defines the outcome of an asynchronous NCR send.
NameChangeUDPListener(const isc::asiolink::IOAddress &ip_address, const uint32_t port, const NameChangeFormat format, RequestReceiveHandlerPtr ncr_recv_handler, const bool reuse_address=false)
Constructor.
virtual void close()
Closes the UDPSocket.
virtual void open(const isc::asiolink::IOServicePtr &io_service)
Opens a UDP socket using the given IOService.
virtual ~NameChangeUDPListener()
Destructor.
static const size_t RECV_BUF_MAX
Defines the maximum size packet that can be received.
void receiveCompletionHandler(const bool successful, const UDPCallback *recv_callback)
Implements the NameChangeRequest level receive completion handler.
void doReceive()
Initiates an asynchronous read on the socket.
void sendCompletionHandler(const bool successful, const UDPCallback *send_callback)
Implements the NameChangeRequest level send completion handler.
virtual bool ioReady()
Returns whether or not the sender has IO ready to process.
static const size_t SEND_BUF_MAX
Defines the maximum size packet that can be sent.
virtual void open(const isc::asiolink::IOServicePtr &io_service)
Opens a UDP socket using the given IOService.
virtual int getSelectFd()
Returns a file descriptor suitable for use with select.
virtual void close()
Closes the UDPSocket.
virtual void doSend(NameChangeRequestPtr &ncr)
Sends a given request asynchronously over the socket.
NameChangeUDPSender(const isc::asiolink::IOAddress &ip_address, const uint32_t port, const isc::asiolink::IOAddress &server_address, const uint32_t server_port, const NameChangeFormat format, RequestSendHandlerPtr ncr_send_handler, const size_t send_que_max=NameChangeSender::MAX_QUEUE_DEFAULT, const bool reuse_address=false)
Constructor.
virtual ~NameChangeUDPSender()
Destructor.
Exception thrown when NameChangeRequest marshalling error occurs.
Thrown when a UDP level exception occurs.
Implements the callback class passed into UDPSocket calls.
size_t getBytesTransferred() const
Returns the number of bytes transferred by the completed IO service.
void setErrorCode(const boost::system::error_code value)
Sets the completed IO layer service outcome status.
const uint8_t * getData() const
Returns a pointer the data transfer buffer content.
void putData(const uint8_t *src, size_t len)
Copies data into the data transfer buffer.
UDPCallback(RawBufferPtr &buffer, const size_t buf_size, UDPEndpointPtr &data_source, const UDPCompletionHandler &handler)
Used as the callback object for UDPSocket services.
void setBytesTransferred(const size_t value)
Sets the number of bytes transferred.
void operator()(const boost::system::error_code error_code, const size_t bytes_transferred)
Operator that will be invoked by the asiolink layer.
boost::system::error_code getErrorCode() const
Returns the completed IO layer service outcome status.
static StatsMgr & instance()
Statistics Manager accessor method.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
const uint8_t * getData() const
Return a pointer to the head of the data stored in the buffer.
size_t getLength() const
Return the length of data written in the buffer.
Provides an IO "ready" semaphore for use with select() or poll() WatchSocket exposes a single open fi...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
void addValue(const std::string &name, const int64_t value)
Records incremental integer observation.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
const isc::log::MessageID DHCP_DDNS_NCR_UDP_RECV_ERROR
isc::log::Logger dhcp_ddns_logger("libdhcp-ddns")
Defines the logger used within lib dhcp_ddns.
NameChangeFormat
Defines the list of data wire formats supported.
const isc::log::MessageID DHCP_DDNS_NCR_UDP_SEND_CANCELED
const isc::log::MessageID DHCP_DDNS_NCR_UDP_SEND_ERROR
const isc::log::MessageID DHCP_DDNS_NCR_UDP_CLEAR_READY_ERROR
std::function< void(const bool, const UDPCallback *)> UDPCompletionHandler
Defines a function pointer for NameChangeRequest completion handlers.
const isc::log::MessageID DHCP_DDNS_NCR_UDP_RECV_CANCELED
isc::asiolink::UDPSocket< UDPCallback > NameChangeUDPSocket
Convenience type for UDP socket based listener.
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
const isc::log::MessageID DHCP_DDNS_INVALID_NCR
boost::shared_array< uint8_t > RawBufferPtr
Defines a dynamically allocated shared array.
boost::shared_ptr< asiolink::UDPEndpoint > UDPEndpointPtr
const isc::log::MessageID DHCP_DDNS_UDP_SENDER_WATCH_SOCKET_CLOSE_ERROR
const int DBGLVL_TRACE_BASIC
Trace basic operations.
Defines the logger used by the top-level component of kea-lfc.
This file provides UDP socket based implementation for sending and receiving NameChangeRequests.
Container class which stores service invocation related data.