 |
Kea
1.5.0
|
Go to the documentation of this file.
12 #include <boost/bind.hpp>
21 : handler_(handler), data_(new
Data(buffer, buf_size, data_source)) {
22 if (handler.empty()) {
33 const size_t bytes_transferred) {
44 handler_(!error_code,
this);
53 if (len > data_->buf_size_) {
57 memcpy (data_->buffer_.get(), src, len);
58 data_->put_len_ = len;
67 const bool reuse_address)
69 port_(port), format_(
format), reuse_address_(reuse_address) {
75 recv_callback_.reset(
new
93 asio_socket_.reset(
new boost::asio::ip::udp::
95 (ip_address_.
isV4() ? boost::asio::ip::udp::v4() :
96 boost::asio::ip::udp::v6())));
100 asio_socket_->set_option(boost::asio::socket_base::reuse_address(
true));
105 }
catch (boost::system::system_error& ex) {
106 asio_socket_.reset();
119 socket_->asyncReceive(recv_buffer.get(), recv_callback_->getBufferSize(),
120 0, recv_callback_->getDataSource().get(),
132 if (asio_socket_->is_open()) {
134 asio_socket_->close();
135 }
catch (boost::system::system_error& ex) {
144 asio_socket_.reset();
173 boost::system::error_code error_code = callback->
getErrorCode();
174 if (error_code.value() == boost::asio::error::operation_aborted) {
178 DHCP_DDNS_NCR_UDP_RECV_CANCELED);
182 .arg(error_code.message());
200 const size_t send_que_max,
const bool reuse_address)
202 ip_address_(ip_address), port_(port), server_address_(server_address),
203 server_port_(server_port), format_(
format),
204 reuse_address_(reuse_address) {
228 asio_socket_.reset(
new boost::asio::ip::udp::
230 (ip_address_.
isV4() ? boost::asio::ip::udp::v4() :
231 boost::asio::ip::udp::v6())));
234 if (reuse_address_) {
235 asio_socket_->set_option(boost::asio::socket_base::reuse_address(
true));
240 }
catch (boost::system::system_error& ex) {
249 UDPEndpoint(server_address_, server_port_));
251 send_callback_->setDataSource(server_endpoint_);
265 if (asio_socket_->is_open()) {
267 asio_socket_->close();
268 }
catch (boost::system::system_error& ex) {
277 asio_socket_.reset();
283 watch_socket_.reset();
290 ncr->toFormat(format_, ncr_buffer);
294 send_callback_->putData(
static_cast<const uint8_t*
>(ncr_buffer.
getData()),
298 socket_->asyncSend(send_callback_->getData(), send_callback_->getPutLen(),
299 send_callback_->getDataSource().get(), *send_callback_);
306 watch_socket_->markReady();
314 watch_socket_->clearReady();
315 }
catch (
const std::exception& ex) {
332 boost::system::error_code error_code = send_callback->
getErrorCode();
333 if (error_code.value() == boost::asio::error::operation_aborted) {
335 .arg(error_code.message());
339 .arg(error_code.message());
352 " not in send mode");
355 return(watch_socket_->getSelectFd());
361 return (watch_socket_->isReady());
368 NameChangeUDPSender::closeWatchSocket() {
370 std::string error_string;
371 watch_socket_->closeSocket(error_string);
372 if (!error_string.empty()) {
virtual void open(isc::asiolink::IOService &io_service)
Opens a UDP socket using the given IOService.
Abstract interface for sending NameChangeRequests.
static const size_t SEND_BUF_MAX
Defines the maximum size packet that can be sent.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
Thrown when a UDP level exception occurs.
virtual bool ioReady()
Returns whether or not the sender has IO ready to process.
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...
The IOAddress class represents an IP addresses (version agnostic)
boost::asio::io_service & get_io_service()
Return the native io_service object used in this wrapper.
Result
Defines the outcome of an asynchronous NCR send.
void stopSending()
Closes the IO sink and stops send logic.
Abstract interface for receiving NameChangeRequests.
The IOService class is a wrapper for the ASIO io_service class.
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
virtual ~NameChangeUDPListener()
Destructor.
Abstract class for defining application layer send callbacks.
static const size_t RECV_BUF_MAX
Defines the maximum size packet that can be received.
void putData(const uint8_t *src, size_t len)
Copies data into the data transfer buffer.
virtual ~NameChangeUDPSender()
Destructor.
void setBytesTransferred(const size_t value)
Sets the number of bytes transferred.
void stopListening()
Closes the IO source and stops listen logic.
Abstract class for defining application layer receive callbacks.
virtual void close()
Closes the UDPSocket.
boost::function< void(const bool, const UDPCallback *)> UDPCompletionHandler
Defines a function pointer for NameChangeRequest completion handlers.
const boost::asio::ip::udp::endpoint & getASIOEndpoint() const
Provides the ability to receive NameChangeRequests via UDP socket.
The UDPEndpoint class is a concrete derived class of IOEndpoint that represents an endpoint of a UDP ...
void receiveCompletionHandler(const bool successful, const UDPCallback *recv_callback)
Implements the NameChangeRequest level receive completion handler.
void sendCompletionHandler(const bool successful, const UDPCallback *send_callback)
Implements the NameChangeRequest level send completion handler.
Defines the logger used by the top-level component of kea-dhcp-ddns.
void doReceive()
Initiates an asynchronous read on the socket.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
std::string format(const std::string &format, const std::vector< std::string > &args)
Apply Formatting.
boost::shared_array< uint8_t > RawBufferPtr
Defines a dynamically allocated shared array.
size_t getLength() const
Return the length of data written in the buffer.
void invokeSendHandler(const NameChangeSender::Result result)
Calls the NCR send completion handler registered with the sender.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
virtual int getSelectFd()
Returns a file descriptor suitable for use with select.
Exception thrown when NameChangeRequest marshalling error occurs.
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, RequestSendHandler &ncr_send_handler, const size_t send_que_max=NameChangeSender::MAX_QUEUE_DEFAULT, const bool reuse_address=false)
Constructor.
const uint8_t * getData() const
Returns a pointer the data transfer buffer content.
virtual void doSend(NameChangeRequestPtr &ncr)
Sends a given request asynchronously over the socket.
NameChangeUDPListener(const isc::asiolink::IOAddress &ip_address, const uint32_t port, const NameChangeFormat format, RequestReceiveHandler &ncr_recv_handler, const bool reuse_address=false)
Constructor.
void operator()(const boost::system::error_code error_code, const size_t bytes_transferred)
Operator that will be invoked by the asiolink layer.
const int DBGLVL_TRACE_BASIC
Trace basic operations.
isc::asiolink::UDPSocket< UDPCallback > NameChangeUDPSocket
Convenience type for UDP socket based listener.
Container class which stores service invocation related data.
isc::log::Logger dhcp_ddns_logger("libdhcp-ddns")
Defines the logger used within lib dhcp_ddns.
virtual void close()
Closes the UDPSocket.
Provides an IO "ready" semaphore for use with select() or poll() WatchSocket exposes a single open fi...
bool amSending() const
Returns true if the sender is in send mode, false otherwise.
virtual void open(isc::asiolink::IOService &io_service)
Opens a UDP socket using the given IOService.
const void * getData() const
Return a pointer to the head of the data stored in the buffer.
Result
Defines the outcome of an asynchronous NCR receive.
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.
boost::system::error_code getErrorCode() const
Returns the completed IO layer service outcome status.
Provides the ability to send NameChangeRequests via UDP socket.
void setErrorCode(const boost::system::error_code value)
Sets the completed IO layer service outcome status.
Implements the callback class passed into UDPSocket calls.
bool isV4() const
Convenience function to check for an IPv4 address.
UDPCallback(RawBufferPtr &buffer, const size_t buf_size, UDPEndpointPtr &data_source, const UDPCompletionHandler &handler)
Used as the callback object for UDPSocket services.
boost::shared_ptr< asiolink::UDPEndpoint > UDPEndpointPtr
size_t getBytesTransferred() const
Returns the number of bytes transferred by the completed IO service.
NameChangeFormat
Defines the list of data wire formats supported.
void receiveNext()
Initiates an asynchronous receive.
This file provides UDP socket based implementation for sending and receiving NameChangeRequests.