Commit b47cd4c0 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2903] more cleanups for SyncUDPServer: avoid constructing objs for each cback.

parent a354d4ed
......@@ -42,8 +42,7 @@ SyncUDPServer::SyncUDPServer(asio::io_service& io_service, const int fd,
const int af, DNSLookup* lookup) :
output_buffer_(new isc::util::OutputBuffer(0)),
query_(new isc::dns::Message(isc::dns::Message::PARSE)),
answer_(new isc::dns::Message(isc::dns::Message::RENDER)),
lookup_callback_(lookup), stopped_(false)
udp_endpoint_(sender_), lookup_callback_(lookup), stopped_(false)
if (af != AF_INET && af != AF_INET6) {
isc_throw(InvalidParameter, "Address family must be either AF_INET "
......@@ -63,6 +62,7 @@ SyncUDPServer::SyncUDPServer(asio::io_service& io_service, const int fd,
// convert it
isc_throw(IOError, exception.what());
udp_socket_.reset(new UDPSocket<DummyIOCallback>(*socket_));
......@@ -93,18 +93,12 @@ SyncUDPServer::handleRead(const asio::error_code& ec, const size_t length) {
// OK, we have a real packet of data. Let's dig into it!
// XXX: This is taken (and ported) from UDPSocket class. What the hell does
// it really mean?
// The UDP socket class has been extended with asynchronous functions
// and takes as a template parameter a completion callback class. As
// UDPServer does not use these extended functions (only those defined
// in the IOSocket base class) - but needs a UDPSocket to get hold of
// the underlying Boost UDP socket - DummyIOCallback is used. This
// provides the appropriate operator() but is otherwise functionless.
UDPSocket<DummyIOCallback> socket(*socket_);
UDPEndpoint endpoint(sender_);
IOMessage message(data_, length, socket, endpoint);
// Make sure the buffers are fresh. Note that we don't touch query_
// because it's supposed to be cleared in lookup_callback_. We should
......@@ -113,14 +107,14 @@ SyncUDPServer::handleRead(const asio::error_code& ec, const size_t length) {
// implementation should be careful that it's the responsibility of
// the callback implementation. See also #2239).
// Mark that we don't have an answer yet.
done_ = false;
resume_called_ = false;
// Call the actual lookup
(*lookup_callback_)(message, query_, answer_, output_buffer_, this);
(*lookup_callback_)(IOMessage(data_, length, *udp_socket_, udp_endpoint_),
query_, answer_, output_buffer_, this);
if (!resume_called_) {
......@@ -25,10 +25,13 @@
#include <dns/message.h>
#include <asiolink/simple_callback.h>
#include <asiolink/dummy_io_cb.h>
#include <asiolink/udp_socket.h>
#include <util/buffer.h>
#include <exceptions/exceptions.h>
#include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp>
#include <stdint.h>
......@@ -124,12 +127,15 @@ private:
// If it was OK to have just a buffer, not the wrapper class,
// we could reuse the data_
isc::util::OutputBufferPtr output_buffer_;
// Objects to hold the query message and the answer
// Objects to hold the query message and the answer: these are not used
isc::dns::MessagePtr query_, answer_;
// The socket used for the communication
std::auto_ptr<asio::ip::udp::socket> socket_;
boost::scoped_ptr<asiolink::UDPSocket<asiolink::DummyIOCallback> >
// Place the socket puts the sender of a packet when it is received
asio::ip::udp::endpoint sender_;
asiolink::UDPEndpoint udp_endpoint_;
// Callback
const DNSLookup* lookup_callback_;
// Answers from the lookup callback (not sent directly, but signalled
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment