diff --git a/src/transport.cpp b/src/transport.cpp index d32bad70330c7ae8b26e5004718ef249e5772031..80e086a41febf7593c580b76afd9243783e219cf 100644 --- a/src/transport.cpp +++ b/src/transport.cpp @@ -203,6 +203,11 @@ void Component::start() { else if (m_server) { LOG4CXX_INFO(logger, "Starting component in server mode on port " << CONFIG_INT(m_config, "service.port")); m_server->start(); + + //Type casting to BoostConnectionServer since onStopped signal is not defined in ConnectionServer + //Ideally, onStopped must be defined in ConnectionServer + boost::dynamic_pointer_cast(m_server->getConnectionServer())->onStopped.connect(boost::bind(&Component::handleServerStopped, this, _1)); + // We're connected right here, because we're in server mode... handleConnected(); } @@ -226,6 +231,17 @@ void Component::handleConnected() { m_reconnectCount = 0; } +void Component::handleServerStopped(boost::optional e) { + if(e != NULL ) { + if(*e == Swift::BoostConnectionServer::Conflict) + LOG4CXX_INFO(logger, "Port "<< CONFIG_INT(m_config, "service.port") << " already in use! Stopping server.."); + if(*e == Swift::BoostConnectionServer::UnknownError) + LOG4CXX_INFO(logger, "Unknown error occured! Stopping server.."); + exit(1); + } +} + + void Component::handleConnectionError(const ComponentError &error) { onConnectionError(error); // if (m_reconnectCount == 2)