BIND 10 trac2903, updated. 4933a1c6284498e2656909d15a84657b5b6ecb8b [2903] make some more repeatedly-used variables class members.
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Apr 26 21:40:54 UTC 2013
The branch, trac2903 has been updated
via 4933a1c6284498e2656909d15a84657b5b6ecb8b (commit)
from de20a4c519712d5076b3e26c6eb1e4a40f689ed8 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 4933a1c6284498e2656909d15a84657b5b6ecb8b
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Fri Apr 26 14:39:13 2013 -0700
[2903] make some more repeatedly-used variables class members.
this will be slightly more efficient as we can avoid construction overhead
per call. also use asio::mutable_buffers_1() instead of asio::buffer();
the latter is a wrapper for the former, so the direct call should be
(in theory) more efficient.
-----------------------------------------------------------------------
Summary of changes:
src/lib/asiodns/sync_udp_server.cc | 22 ++++++++--------------
src/lib/asiodns/sync_udp_server.h | 9 +++++++++
2 files changed, 17 insertions(+), 14 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/asiodns/sync_udp_server.cc b/src/lib/asiodns/sync_udp_server.cc
index 9233f9e..3df3c25 100644
--- a/src/lib/asiodns/sync_udp_server.cc
+++ b/src/lib/asiodns/sync_udp_server.cc
@@ -42,7 +42,8 @@ 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)),
- udp_endpoint_(sender_), lookup_callback_(lookup), stopped_(false)
+ udp_endpoint_(sender_), lookup_callback_(lookup), stopped_(false),
+ recv_callback_(boost::bind(&SyncUDPServer::handleRead, this, _1, _2))
{
if (af != AF_INET && af != AF_INET6) {
isc_throw(InvalidParameter, "Address family must be either AF_INET "
@@ -67,9 +68,8 @@ SyncUDPServer::SyncUDPServer(asio::io_service& io_service, const int fd,
void
SyncUDPServer::scheduleRead() {
- socket_->async_receive_from(asio::buffer(data_, MAX_LENGTH), sender_,
- boost::bind(&SyncUDPServer::handleRead, this,
- _1, _2));
+ socket_->async_receive_from(asio::mutable_buffers_1(data_, MAX_LENGTH),
+ sender_, recv_callback_);
}
void
@@ -116,14 +116,12 @@ SyncUDPServer::handleRead(const asio::error_code& ec, const size_t length) {
if (done_) {
// Good, there's an answer.
-
- asio::error_code ec;
socket_->send_to(asio::const_buffers_1(output_buffer_->getData(),
output_buffer_->getLength()),
- sender_, 0, ec);
- if (ec) {
+ sender_, 0, ecode_);
+ if (ecode_) {
LOG_ERROR(logger, ASIODNS_UDP_SYNC_SEND_FAIL).
- arg(sender_.address().to_string()).arg(ec.message());
+ arg(sender_.address().to_string()).arg(ecode_.message());
}
}
@@ -141,10 +139,6 @@ SyncUDPServer::operator()(asio::error_code, size_t) {
/// Stop the UDPServer
void
SyncUDPServer::stop() {
- // passing error_code to avoid getting exception; we simply ignore any
- // error on close().
- asio::error_code ec;
-
/// Using close instead of cancel, because cancel
/// will only cancel the asynchronized event already submitted
/// to io service, the events post to io service after
@@ -153,7 +147,7 @@ SyncUDPServer::stop() {
/// for it won't be scheduled by io service not matter it is
/// submit to io service before or after close call. And we will
/// get bad_descriptor error.
- socket_->close(ec);
+ socket_->close(ecode_); // pass error_code just to avoid getting exception.
stopped_ = true;
}
diff --git a/src/lib/asiodns/sync_udp_server.h b/src/lib/asiodns/sync_udp_server.h
index f6aafce..77b9c14 100644
--- a/src/lib/asiodns/sync_udp_server.h
+++ b/src/lib/asiodns/sync_udp_server.h
@@ -30,6 +30,7 @@
#include <util/buffer.h>
#include <exceptions/exceptions.h>
+#include <boost/function.hpp>
#include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp>
@@ -150,6 +151,14 @@ private:
// This turns true when the server stops. Allows for not sending the
// answer after we closed the socket.
bool stopped_;
+ // Placeholder for error code object. It will be passed to ASIO library
+ // to have it set in case of error.
+ asio::error_code ecode_;
+ // The callback functor for internal asynchronous read event. This is
+ // stateless (and it will be copied in the ASIO library anyway), so
+ // can be const
+ const boost::function<void(const asio::error_code&, size_t)>
+ recv_callback_;
// Auxiliary functions
More information about the bind10-changes
mailing list