[svn] commit: r3393 - in /branches/vorner-recursor-timeouts/src/lib/asiolink: asiolink.cc internal/udpdns.h udpdns.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Oct 28 19:21:38 UTC 2010
Author: vorner
Date: Thu Oct 28 19:21:37 2010
New Revision: 3393
Log:
An interface change to pass back timeouts
This change will allow passing a timeout (and, in future, possibly more
errors) from UDPQuery. UDPQuery no longer needs a server to resume, it
can call anything that is passed there.
The interface change propagation is stopped directly above it by a hack.
Maybe it will propagate more or the Callback will be more general (not
just for UDPQuery).
Modified:
branches/vorner-recursor-timeouts/src/lib/asiolink/asiolink.cc
branches/vorner-recursor-timeouts/src/lib/asiolink/internal/udpdns.h
branches/vorner-recursor-timeouts/src/lib/asiolink/udpdns.cc
Modified: branches/vorner-recursor-timeouts/src/lib/asiolink/asiolink.cc
==============================================================================
--- branches/vorner-recursor-timeouts/src/lib/asiolink/asiolink.cc (original)
+++ branches/vorner-recursor-timeouts/src/lib/asiolink/asiolink.cc Thu Oct 28 19:21:37 2010
@@ -227,6 +227,18 @@
dns_service_(dns_service), ns_addr_(&forward), port_(port)
{}
+namespace {
+
+// This is just temporary so the interface change does not propagate too far
+struct ServerNotify : public UDPQuery::Callback {
+ DNSServer *server;
+ virtual void operator()(UDPQuery::Result result) {
+ server->resume(result == UDPQuery::SUCCESS);
+ }
+};
+
+}
+
void
RecursiveQuery::sendQuery(const Question& question, OutputBufferPtr buffer,
DNSServer* server)
@@ -237,7 +249,11 @@
// UDP and then fall back to TCP on failure, but for the moment
// we're only going to handle UDP.
asio::io_service& io = dns_service_.get_io_service();
- UDPQuery q(io, question, ns_addr_, port_, buffer, server);
+ boost::shared_ptr<ServerNotify> callback(new ServerNotify);
+ // FIXME This is said it does problems when it is shared pointer, as
+ // it is destroyed too soon. But who deletes it now?
+ callback->server = server->clone();
+ UDPQuery q(io, question, ns_addr_, port_, buffer, callback);
io.post(q);
}
Modified: branches/vorner-recursor-timeouts/src/lib/asiolink/internal/udpdns.h
==============================================================================
--- branches/vorner-recursor-timeouts/src/lib/asiolink/internal/udpdns.h (original)
+++ branches/vorner-recursor-timeouts/src/lib/asiolink/internal/udpdns.h Thu Oct 28 19:21:37 2010
@@ -180,11 +180,28 @@
//
class UDPQuery : public coroutine {
public:
+ // TODO Maybe this should be more generic than just for UDPQuery?
+ /**
+ * \short Result of the query
+ *
+ * This is related only to contacting the remote server. If the answer
+ * indicates error, it is still counted as SUCCESS here, if it comes back.
+ */
+ enum Result {
+ SUCCESS,
+ TIME_OUT
+ };
+ /// Abstract callback for the UDPQuery.
+ class Callback {
+ public:
+ /// This will be called when the UDPQuery is completed
+ virtual void operator()(Result result) = 0;
+ };
explicit UDPQuery(asio::io_service& io_service,
const isc::dns::Question& q,
const IOAddress& addr, uint16_t port,
isc::dns::OutputBufferPtr buffer,
- DNSServer* server);
+ boost::shared_ptr<Callback> callback, int timeout = -1);
void operator()(asio::error_code ec = asio::error_code(),
size_t length = 0);
private:
@@ -211,20 +228,15 @@
// The output buffer supplied by the caller. The resposne frmo
// the upstream server will be copied here.
- isc::dns::OutputBufferPtr buffer_;;
+ isc::dns::OutputBufferPtr buffer_;
// These are allocated for each new query and are stored as
// shared pointers to minimize copy overhead.
isc::dns::OutputBufferPtr msgbuf_;
boost::shared_array<char> data_;
- // The UDP or TCP Server object from which the query originated.
- // Note: Using a shared_ptr for this can cause problems when
- // control is being transferred from this coroutine to the server;
- // the reference count can drop to zero and cause the server to be
- // destroyed before it executes. Consequently in this case it's
- // safer to use a raw pointer.
- DNSServer* server_;
+ // This will be called when we are done.
+ boost::shared_ptr<Callback> callback_;
};
}
Modified: branches/vorner-recursor-timeouts/src/lib/asiolink/udpdns.cc
==============================================================================
--- branches/vorner-recursor-timeouts/src/lib/asiolink/udpdns.cc (original)
+++ branches/vorner-recursor-timeouts/src/lib/asiolink/udpdns.cc Thu Oct 28 19:21:37 2010
@@ -176,8 +176,9 @@
/// The constructor
UDPQuery::UDPQuery(io_service& io_service,
const Question& q, const IOAddress& addr, uint16_t port,
- OutputBufferPtr buffer, DNSServer* server) :
- question_(q), buffer_(buffer), server_(server->clone())
+ OutputBufferPtr buffer,
+ boost::shared_ptr<Callback> callback, int timeout) :
+ question_(q), buffer_(buffer), callback_(callback)
{
udp proto = (addr.getFamily() == AF_INET) ? udp::v4() : udp::v6();
socket_.reset(new udp::socket(io_service, proto));
@@ -232,8 +233,8 @@
/// be unnecessary.)
buffer_->writeData(data_.get(), length);
- /// Signal the DNSServer object to resume processing.
- server_->resume(true);
+ /// We are done
+ (*callback_)(SUCCESS);
}
}
More information about the bind10-changes
mailing list