Browse Source

Merge 394 into 327

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac327@3494 e5f2f494-b856-4b98-b285-d166d9295462
Michal Vaner 14 years ago
parent
commit
6cfc6a4854

+ 2 - 0
src/bin/auth/main.cc

@@ -240,6 +240,8 @@ main(int argc, char* argv[]) {
 
         cout << "[b10-auth] Server started." << endl;
         io_service.run();
+
+        delete dns_service;
     } catch (const std::exception& ex) {
         cerr << "[b10-auth] Server failed: " << ex.what() << endl;
         ret = 1;

+ 0 - 1
src/bin/recurse/main.cc

@@ -119,7 +119,6 @@ main(int argc, char* argv[]) {
 
     int ret = 0;
 
-    // XXX: we should eventually pass io_service here.
     Session* cc_session = NULL;
     ModuleCCSession* config_session = NULL;
     try {

+ 1 - 0
src/lib/asiolink/internal/coroutine.h

@@ -67,6 +67,7 @@ class coroutine
 {
 public:
   coroutine() : value_(0) {}
+  virtual ~coroutine() {}
   bool is_child() const { return value_ < 0; }
   bool is_parent() const { return !is_child(); }
   bool is_complete() const { return value_ == -1; }

+ 5 - 1
src/lib/asiolink/internal/tcpdns.h

@@ -21,6 +21,7 @@
 
 
 #include <asio.hpp>
+#include <boost/shared_array.hpp>
 #include <boost/shared_ptr.hpp>
 
 #include <dns/buffer.h>
@@ -167,7 +168,7 @@ private:
     isc::dns::MessagePtr message_;
 
     // The buffer into which the query packet is written
-    boost::shared_ptr<char> data_;
+    boost::shared_array<char>data_;
 
     // State information that is entirely internal to a given instance
     // of the coroutine can be declared here.
@@ -178,6 +179,9 @@ private:
     const SimpleCallback* checkin_callback_;
     const DNSLookup* lookup_callback_;
     const DNSAnswer* answer_callback_;
+
+    boost::shared_ptr<IOEndpoint> peer_;
+    boost::shared_ptr<IOSocket> iosock_;
 };
 
 }

+ 5 - 7
src/lib/asiolink/internal/udpdns.h

@@ -162,7 +162,7 @@ private:
     isc::dns::OutputBufferPtr respbuf_;
     
     // The buffer into which the query packet is written
-    boost::shared_ptr<char> data_;
+    boost::shared_array<char> data_;
 
     // State information that is entirely internal to a given instance
     // of the coroutine can be declared here.
@@ -173,6 +173,9 @@ private:
     const SimpleCallback* checkin_callback_;
     const DNSLookup* lookup_callback_;
     const DNSAnswer* answer_callback_;
+
+    boost::shared_ptr<IOEndpoint> peer_;
+    boost::shared_ptr<IOSocket> iosock_;
 };
 
 //
@@ -219,12 +222,7 @@ private:
     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_;
+    boost::shared_ptr<DNSServer> server_;
 };
 }
 

+ 7 - 10
src/lib/asiolink/tcpdns.cc

@@ -72,9 +72,7 @@ TCPServer::operator()(error_code ec, size_t length) {
     /// a switch statement, inline variable declarations are not
     /// permitted.  Certain variables used below can be declared here.
     boost::array<const_buffer,2> bufs;
-    OutputBuffer* lenbuf;
-    IOEndpoint* peer;
-    IOSocket* iosock;
+    OutputBuffer lenbuf(TCP_MESSAGE_LENGTHSIZE);
 
     CORO_REENTER (this) {
         do {
@@ -96,7 +94,7 @@ TCPServer::operator()(error_code ec, size_t length) {
 
         /// Instantiate the data buffer that will be used by the
         /// asynchronous read call.
-        data_ = boost::shared_ptr<char>(new char[MAX_LENGTH]);
+        data_.reset(new char[MAX_LENGTH]);
 
         /// Read the message, in two parts.  First, the message length:
         CORO_YIELD async_read(*socket_, asio::buffer(data_.get(),
@@ -122,9 +120,9 @@ TCPServer::operator()(error_code ec, size_t length) {
         // (XXX: It would be good to write a factory function
         // that would quickly generate an IOMessage object without
         // all these calls to "new".)
-        peer = new TCPEndpoint(socket_->remote_endpoint());
-        iosock = new TCPSocket(*socket_);
-        io_message_.reset(new IOMessage(data_.get(), length, *iosock, *peer));
+        peer_.reset(new TCPEndpoint(socket_->remote_endpoint()));
+        iosock_.reset(new TCPSocket(*socket_));
+        io_message_.reset(new IOMessage(data_.get(), length, *iosock_, *peer_));
         bytes_ = length;
 
         // Perform any necessary operations prior to processing the incoming
@@ -164,9 +162,8 @@ TCPServer::operator()(error_code ec, size_t length) {
         (*answer_callback_)(*io_message_, message_, respbuf_);
 
         // Set up the response, beginning with two length bytes.
-        lenbuf = new OutputBuffer(TCP_MESSAGE_LENGTHSIZE);
-        lenbuf->writeUint16(respbuf_->getLength());
-        bufs[0] = buffer(lenbuf->getData(), lenbuf->getLength());
+        lenbuf.writeUint16(respbuf_->getLength());
+        bufs[0] = buffer(lenbuf.getData(), lenbuf.getLength());
         bufs[1] = buffer(respbuf_->getData(), respbuf_->getLength());
 
         // Begin an asynchronous send, and then yield.  When the

+ 3 - 5
src/lib/asiolink/udpdns.cc

@@ -73,8 +73,6 @@ UDPServer::operator()(error_code ec, size_t length) {
     /// Because the coroutine reeentry block is implemented as
     /// a switch statement, inline variable declarations are not
     /// permitted.  Certain variables used below can be declared here.
-    IOEndpoint* peer;
-    IOSocket* iosock;
 
     CORO_REENTER (this) {
         do {
@@ -106,9 +104,9 @@ UDPServer::operator()(error_code ec, size_t length) {
         // (XXX: It would be good to write a factory function
         // that would quickly generate an IOMessage object without
         // all these calls to "new".)
-        peer = new UDPEndpoint(*sender_);
-        iosock = new UDPSocket(*socket_);
-        io_message_.reset(new IOMessage(data_.get(), bytes_, *iosock, *peer));
+        peer_.reset(new UDPEndpoint(*sender_));
+        iosock_.reset(new UDPSocket(*socket_));
+        io_message_.reset(new IOMessage(data_.get(), bytes_, *iosock_, *peer_));
 
         // Perform any necessary operations prior to processing an incoming
         // query (e.g., checking for queued configuration messages).