From daf6897fe24e62ae8cf8e42b151ed565563332fe Mon Sep 17 00:00:00 2001 From: Nicolas Noble Date: Fri, 8 Aug 2014 13:34:23 -0700 Subject: Finalizing cares integration. --- src/HttpServer.cc | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/HttpServer.cc') diff --git a/src/HttpServer.cc b/src/HttpServer.cc index d6bc53d..fe95edb 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -633,20 +633,20 @@ typedef Balau::Listener HttpListener; void Balau::HttpServer::start() { AAssert(!m_started, "Don't start an HttpServer twice"); - m_listenerPtr = TaskMan::registerTask(new HttpListener(m_port, m_local.to_charp(), this)); m_started = true; + m_listenerPtr = TaskMan::registerTask(new HttpListener(m_port, m_local.to_charp(), this), &m_listenerEvent); } void Balau::HttpServer::stop() { AAssert(m_started, "Don't stop an HttpServer that hasn't been started"); + m_started = false; + IAssert(!m_listenerEvent.gotSignal(), "Our listener has stopped already!"); HttpListener * listener = reinterpret_cast(m_listenerPtr); - Events::TaskEvent event(listener); - Task::prepare(&event); + Task::prepare(&m_listenerEvent); listener->stop(); - m_started = false; - Task::operationYield(&event); - IAssert(event.gotSignal(), "HttpServer::stop didn't actually get the listener to stop"); - event.ack(); + Task::operationYield(&m_listenerEvent); + IAssert(m_listenerEvent.gotSignal(), "HttpServer::stop didn't actually get the listener to stop"); + m_listenerEvent.ack(); } void Balau::HttpServer::registerAction(Action * action) { @@ -665,6 +665,15 @@ void Balau::HttpServer::flushAllActions() { } } +bool Balau::HttpServer::started() { + if (m_listenerEvent.gotSignal()) + return false; + HttpListener * listener = reinterpret_cast(m_listenerPtr); + if (!listener) + return false; + return listener->started(); +} + Balau::HttpServer::Action::ActionMatch Balau::HttpServer::Action::matches(const char * uri, const char * host) { ActionMatch r; -- cgit v1.2.3