Do not start XMPP server before first backend is connected
This commit is contained in:
parent
96425ce8db
commit
28ca4ba95e
4 changed files with 29 additions and 11 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -74,6 +74,5 @@ int main(int argc, char **argv)
|
|||
|
||||
NetworkPluginServer plugin(&transport, &config, &userManager);
|
||||
|
||||
transport.connect();
|
||||
eventLoop.run();
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Add table
Reference in a new issue