Commit 6cfc6a48 authored by Michal Vaner's avatar Michal Vaner
Browse files

Merge 394 into 327

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac327@3494 e5f2f494-b856-4b98-b285-d166d9295462
parents 49fdde93 4c3ee31b
......@@ -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;
......
......@@ -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 {
......
......@@ -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; }
......
......@@ -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_;
};
}
......
......@@ -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_;
};
}
......
......@@ -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
......
......@@ -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).
......
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