Added code to handle errors during Server creation
This commit is contained in:
parent
99941f0a4c
commit
2b834d16ab
2 changed files with 18 additions and 0 deletions
|
@ -37,6 +37,7 @@
|
|||
#include "transport/config.h"
|
||||
#include "transport/factory.h"
|
||||
#include "transport/presenceoracle.h"
|
||||
#include <Swiften/Network/BoostConnectionServer.h>
|
||||
|
||||
namespace Transport {
|
||||
// typedef enum { CLIENT_FEATURE_ROSTERX = 2,
|
||||
|
@ -165,6 +166,7 @@ namespace Transport {
|
|||
private:
|
||||
void handleConnected();
|
||||
void handleConnectionError(const Swift::ComponentError &error);
|
||||
void handleServerStopped(boost::optional<Swift::BoostConnectionServer::Error> e);
|
||||
void handlePresence(Swift::Presence::ref presence);
|
||||
void handleDataRead(const Swift::SafeByteArray &data);
|
||||
void handleDataWritten(const Swift::SafeByteArray &data);
|
||||
|
|
|
@ -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<Swift::BoostConnectionServer>(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<Swift::BoostConnectionServer::Error> 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)
|
||||
|
|
Loading…
Add table
Reference in a new issue