Commit 06792038 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

simplified cod logic for TCPServer::listening :

  - avoid using an unnecessary temporary variable when possible
  - make sure it's allocated in constructor's memeber initialization list
  - some cleanups: conslidate definitions of private member variables,
    variable name consistency


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1292 e5f2f494-b856-4b98-b285-d166d9295462
parent 47a44f74
......@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <errno.h>
#include <cassert>
#include <iostream>
#include <boost/foreach.hpp>
......@@ -206,34 +207,33 @@ private:
class TCPServer
{
private:
TCPClient* listening;
public:
TCPServer(io_service& io_service, int af, short port) :
io_service_(io_service),
acceptor_(io_service,
tcp::endpoint(af == AF_INET6 ? tcp::v6() : tcp::v4(), port))
tcp::endpoint(af == AF_INET6 ? tcp::v6() : tcp::v4(), port)),
listening_(new TCPClient(io_service_))
{
TCPClient* new_client = new TCPClient(io_service_);
// XXX: isn't the following exception free? Need to check it.
acceptor_.async_accept(new_client->getSocket(),
acceptor_.async_accept(listening_->getSocket(),
boost::bind(&TCPServer::handleAccept, this,
new_client, placeholders::error));
listening = new_client;
listening_, placeholders::error));
}
~TCPServer() { delete listening; }
~TCPServer() { delete listening_; }
void handleAccept(TCPClient* new_client,
const boost::system::error_code& error)
{
if (!error) {
assert(new_client == listening_);
new_client->start();
new_client = new TCPClient(io_service_);
listening_ = new TCPClient(io_service_);
acceptor_.async_accept(new_client->getSocket(),
boost::bind(&TCPServer::handleAccept,
this, new_client,
this, listening_,
placeholders::error));
listening = new_client;
listening_ = new_client;
} else {
delete new_client;
}
......@@ -242,6 +242,7 @@ public:
private:
io_service& io_service_;
tcp::acceptor acceptor_;
TCPClient* listening_;
};
class UDPServer {
......
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