return server;
}
-prefix_ boost::scoped_ptr<senf::console::Server> & senf::console::Server::instancePtr()
-{
- // We cannot make 'instance' a global or class-static variable, since it will then be destructed
- // at an unknown time which may fail if the scheduler or the file-handle pool allocators have
- // already been destructed.
- static boost::scoped_ptr<senf::console::Server> instance;
- return instance;
-}
-
prefix_ senf::console::Server & senf::console::Server::start(ServerHandle handle)
{
// Uah .... ensure the scheduler is created before the instance pointer so it get's destructed
// AFTER it.
(void) senf::Scheduler::instance();
- SENF_ASSERT( ! instancePtr() );
- instancePtr().reset(new Server(handle));
- return * instancePtr();
+ boost::intrusive_ptr<Server> p (new Server(handle));
+ detail::ServerManager::add(boost::intrusive_ptr<Server>(p));
+ return *p;
}
prefix_ senf::console::Server::Server(ServerHandle handle)
- : handle_ (handle), mode_ (Automatic)
-{
- Scheduler::instance().add( handle_, senf::membind(&Server::newClient, this) );
-}
-
-prefix_ senf::console::Server::~Server()
-{
- Scheduler::instance().remove(handle_);
-}
+ : handle_ (handle),
+ event_ ("console::Server", senf::membind(&Server::newClient, this),
+ handle_, scheduler::FdEvent::EV_READ),
+ root_ (senf::console::root().thisptr()), mode_ (Automatic)
+{}
-prefix_ void senf::console::Server::newClient(Scheduler::EventId event)
+prefix_ void senf::console::Server::newClient(int event)
{
ServerHandle::ClientSocketHandle client (handle_.accept());
boost::intrusive_ptr<Client> p (new Client(*this, client));
prefix_
senf::console::detail::NoninteractiveClientReader::NoninteractiveClientReader(Client & client)
- : ClientReader (client), binding_ (handle(),
- senf::membind(&NoninteractiveClientReader::newData, this),
- senf::Scheduler::EV_READ)
+ : ClientReader (client),
+ readevent_ ("NoninteractiveClientReader",
+ senf::membind(&NoninteractiveClientReader::newData, this),
+ handle(), senf::Scheduler::EV_READ)
{}
prefix_ void senf::console::detail::NoninteractiveClientReader::v_disablePrompt()
{}
prefix_ void
-senf::console::detail::NoninteractiveClientReader::newData(senf::Scheduler::EventId event)
+senf::console::detail::NoninteractiveClientReader::newData(int event)
{
if (event != senf::Scheduler::EV_READ || handle().eof()) {
if (! buffer_.empty())
prefix_ senf::console::Client::Client(Server & server, ClientHandle handle)
: out_t(boost::ref(*this)), senf::log::IOStreamTarget(out_t::member), server_ (server),
handle_ (handle),
- binding_ (handle, boost::bind(&Client::setNoninteractive,this), Scheduler::EV_READ, false),
- timer_ (Scheduler::instance().eventTime() + ClockService::milliseconds(INTERACTIVE_TIMEOUT),
- boost::bind(&Client::setInteractive, this), false),
+ readevent_ ("senf::console::Client", boost::bind(&Client::setNoninteractive,this),
+ handle, Scheduler::EV_READ, false),
+ timer_ ("senf::console::Client interactive timeout",
+ boost::bind(&Client::setInteractive, this),
+ Scheduler::instance().eventTime() + ClockService::milliseconds(INTERACTIVE_TIMEOUT),
+ false),
name_ (server.name()), reader_ (), mode_ (server.mode())
{
handle_.facet<senf::TCPSocketProtocol>().nodelay();
+ executor_.chroot(root());
switch (mode_) {
case Server::Interactive :
setInteractive();
setNoninteractive();
break;
case Server::Automatic :
- binding_.enable();
+ readevent_.enable();
timer_.enable();
break;
}
prefix_ void senf::console::Client::setInteractive()
{
- SENF_LOG(("Set client interactive"));
- binding_.disable();
+ readevent_.disable();
timer_.disable();
mode_ = Server::Interactive;
reader_.reset(new detail::SafeReadlineClientReader (*this));
prefix_ void senf::console::Client::setNoninteractive()
{
- SENF_LOG(("Set client non-interactive"));
- binding_.disable();
+ readevent_.disable();
timer_.disable();
mode_ = Server::Noninteractive;
reader_.reset(new detail::NoninteractiveClientReader(*this));
prefix_ std::string::size_type senf::console::Client::handleInput(std::string data,
bool incremental)
{
- SENF_LOG(("Data: " << data));
-
if (data.empty() && ! incremental)
data = lastCommand_;
else