From: JINMEI Tatuya Date: Fri, 26 Apr 2013 07:19:14 +0000 (-0700) Subject: [2903] more cleanups for SyncUDPServer: avoid constructing objs for each cback. X-Git-Tag: bind10-1.1.0beta2-release~8^2~9^2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b47cd4c09f84751609f52a4a989889a7aa475b2a;p=thirdparty%2Fkea.git [2903] more cleanups for SyncUDPServer: avoid constructing objs for each cback. --- diff --git a/src/lib/asiodns/sync_udp_server.cc b/src/lib/asiodns/sync_udp_server.cc index 803271cb58..f473bf5c01 100644 --- a/src/lib/asiodns/sync_udp_server.cc +++ b/src/lib/asiodns/sync_udp_server.cc @@ -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(*socket_)); } void @@ -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 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). output_buffer_->clear(); - answer_->clear(isc::dns::Message::RENDER); // 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_) { isc_throw(isc::Unexpected, diff --git a/src/lib/asiodns/sync_udp_server.h b/src/lib/asiodns/sync_udp_server.h index b9935bfc1f..372c458079 100644 --- a/src/lib/asiodns/sync_udp_server.h +++ b/src/lib/asiodns/sync_udp_server.h @@ -25,10 +25,13 @@ #include #include +#include +#include #include #include #include +#include #include @@ -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 socket_; + boost::scoped_ptr > + udp_socket_; // 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