Commit 4933a1c6 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[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.
parent de20a4c5
......@@ -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,
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_);
......@@ -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;
sender_, 0, ec);
if (ec) {
sender_, 0, ecode_);
if (ecode_) {
......@@ -141,10 +139,6 @@ SyncUDPServer::operator()(asio::error_code, size_t) {
/// Stop the UDPServer
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(ecode_); // pass error_code just to avoid getting exception.
stopped_ = true;
......@@ -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)>
// Auxiliary functions
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