Changeset - 28ca4ba95e42
[Not reviewed]
0 4 0
HanzZ - 14 years ago 2011-06-19 10:37:01
hanzz.k@gmail.com
Do not start XMPP server before first backend is connected
4 files changed with 29 insertions and 11 deletions:
0 comments (0 inline, 0 general)
include/transport/transport.h
Show inline comments
 
@@ -107,8 +107,8 @@ namespace Transport {
 

	
 
			/// Connects the Jabber server.
 

	
 
			/// In server mode this function does nothing.
 
			void connect();
 
			void start();
 
			void stop();
 

	
 
			/// Sets disco#info features which are sent as answer to disco#info IQ-get.
 
			
spectrum/src/main.cpp
Show inline comments
 
@@ -74,6 +74,5 @@ int main(int argc, char **argv)
 
 
	NetworkPluginServer plugin(&transport, &config, &userManager);
 
 
	transport.connect();
 
	eventLoop.run();
 
}
src/networkpluginserver.cpp
Show inline comments
 
@@ -155,6 +155,11 @@ void NetworkPluginServer::handleNewClientConnection(boost::shared_ptr<Swift::Con
 
	client->pongReceived = true;
 
	client->connection = c;
 

	
 
	if (m_clients.size() == 0) {
 
		// first backend connected, start the server, we're ready.
 
		m_component->start();
 
	}
 

	
 
	m_clients.push_back(client);
 

	
 
	c->onDisconnected.connect(boost::bind(&NetworkPluginServer::handleSessionFinished, this, client));
src/transport.cpp
Show inline comments
 
@@ -67,7 +67,7 @@ Component::Component(Swift::EventLoop *loop, Config *config, Factory *factory) {
 
	m_factories = new BoostNetworkFactories(loop);
 

	
 
	m_reconnectTimer = m_factories->getTimerFactory()->createTimer(1000);
 
	m_reconnectTimer->onTick.connect(bind(&Component::connect, this)); 
 
	m_reconnectTimer->onTick.connect(bind(&Component::start, this)); 
 

	
 
	if (CONFIG_BOOL(m_config, "service.server_mode")) {
 
		m_userRegistry = new MyUserRegistry(this);
 
@@ -76,7 +76,7 @@ Component::Component(Swift::EventLoop *loop, Config *config, Factory *factory) {
 
			TLSServerContextFactory *f = new OpenSSLServerContextFactory();
 
			m_server->addTLSEncryption(f, PKCS12Certificate(CONFIG_STRING(m_config, "service.cert"), createSafeByteArray(CONFIG_STRING(m_config, "service.cert_password"))));
 
		}
 
		m_server->start();
 
// 		m_server->start();
 
		m_stanzaChannel = m_server->getStanzaChannel();
 
		m_iqRouter = m_server->getIQRouter();
 

	
 
@@ -152,12 +152,26 @@ void Component::setBuddyFeatures(std::list<std::string> &features) {
 
	m_discoInfoResponder->setBuddyFeatures(features);
 
}
 

	
 
void Component::connect() {
 
	if (!m_component)
 
		return;
 
	m_reconnectCount++;
 
	m_component->connect(CONFIG_STRING(m_config, "service.server"), CONFIG_INT(m_config, "service.port"));
 
	m_reconnectTimer->stop();
 
void Component::start() {
 
	if (m_component) {
 
		m_reconnectCount++;
 
		m_component->connect(CONFIG_STRING(m_config, "service.server"), CONFIG_INT(m_config, "service.port"));
 
		m_reconnectTimer->stop();
 
	}
 
	else if (m_server) {
 
		m_server->start();
 
	}
 
}
 

	
 
void Component::stop() {
 
	if (m_component) {
 
		m_reconnectCount = 0;
 
		m_component->disconnect();
 
		m_reconnectTimer->stop();
 
	}
 
	else if (m_server) {
 
		m_server->stop();
 
	}
 
}
 

	
 
void Component::handleConnected() {
0 comments (0 inline, 0 general)