[svn] commit: r1274 - /trunk/src/bin/auth/main.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Mar 10 10:04:05 UTC 2010
Author: jelte
Date: Wed Mar 10 10:04:05 2010
New Revision: 1274
Log:
moved io_service to global scope so the command handler for "shutdown" can call io_service.stop()
renamed it to io_service to avoid naming collision with boost::io_service namespace
added a variable listening to TCPServer, that keeps track of the currently listening TCPClient pointer, and delete it on destruction (without this we have a fixed-size memory 'leak')
Modified:
trunk/src/bin/auth/main.cc
Modified: trunk/src/bin/auth/main.cc
==============================================================================
--- trunk/src/bin/auth/main.cc (original)
+++ trunk/src/bin/auth/main.cc Wed Mar 10 10:04:05 2010
@@ -72,7 +72,10 @@
* todo: turn this around, and put handlers in the authserver
* class itself? */
namespace {
-AuthSrv *auth_server;
+ AuthSrv *auth_server;
+ // TODO: this should be a property of AuthSrv, and AuthSrv needs
+ // a stop() method (so the shutdown command can be handled)
+ boost::asio::io_service io_service_;
}
static ElementPtr
@@ -84,12 +87,14 @@
my_command_handler(const string& command, const ElementPtr args) {
ElementPtr answer = createAnswer(0);
- if (command == "print_message")
- {
+ if (command == "print_message") {
cout << args << endl;
/* let's add that message to our answer as well */
answer->get("result")->add(args);
- }
+ } else if (command == "shutdown") {
+ io_service_.stop();
+ }
+
return answer;
}
@@ -190,6 +195,8 @@
class TCPServer
{
+private:
+ TCPClient* listening;
public:
TCPServer(io_service& io_service, int af, short port) :
io_service_(io_service),
@@ -201,7 +208,10 @@
acceptor_.async_accept(new_client->getSocket(),
boost::bind(&TCPServer::handleAccept, this,
new_client, placeholders::error));
- }
+ listening = new_client;
+ }
+
+ ~TCPServer() { delete listening; }
void handleAccept(TCPClient* new_client,
const boost::system::error_code& error)
@@ -213,6 +223,7 @@
boost::bind(&TCPServer::handleAccept,
this, new_client,
placeholders::error));
+ listening = new_client;
} else {
delete new_client;
}
@@ -310,23 +321,22 @@
const string& specfile)
{
ServerSet servers;
- boost::asio::io_service io_service;
short portnum = atoi(port);
- ModuleCCSession cs(specfile, io_service, my_config_handler,
+ ModuleCCSession cs(specfile, io_service_, my_config_handler,
my_command_handler);
if (use_ipv4) {
- servers.udp4_server = new UDPServer(io_service, AF_INET, portnum);
- servers.tcp4_server = new TCPServer(io_service, AF_INET, portnum);
+ servers.udp4_server = new UDPServer(io_service_, AF_INET, portnum);
+ servers.tcp4_server = new TCPServer(io_service_, AF_INET, portnum);
}
if (use_ipv6) {
- servers.udp6_server = new UDPServer(io_service, AF_INET6, portnum);
- servers.tcp6_server = new TCPServer(io_service, AF_INET6, portnum);
+ servers.udp6_server = new UDPServer(io_service_, AF_INET6, portnum);
+ servers.tcp6_server = new TCPServer(io_service_, AF_INET6, portnum);
}
cout << "Server started." << endl;
- io_service.run();
+ io_service_.run();
}
}
#else // !HAVE_BOOSTLIB
More information about the bind10-changes
mailing list