Changeset - 4c885cc94785
[Not reviewed]
0 4 0
HanzZ - 14 years ago 2011-09-09 11:51:25
hanzz.k@gmail.com
Proper SIGTERM/SIGINT handlers
4 files changed with 23 insertions and 3 deletions:
0 comments (0 inline, 0 general)
include/transport/usermanager.h
Show inline comments
 
@@ -80,6 +80,8 @@ class UserManager {
 
		/// \param user User class to remove
 
		void removeUser(User *user);
 

	
 
		void removeAllUsers();
 

	
 
		/// Called when new User class is created.
 
		/// \param user newly created User class
 
		boost::signal<void (User *user)> onUserCreated;
spectrum/src/main.cpp
Show inline comments
 
@@ -30,13 +30,21 @@ using namespace Transport;
 
static LoggerPtr logger = log4cxx::Logger::getLogger("Spectrum");
 
 
Swift::SimpleEventLoop *eventLoop_ = NULL;
 
Component *component_ = NULL;
 
UserManager *userManager_ = NULL;
 
 
static void spectrum_sigint_handler(int sig) {
 
static void stop_spectrum() {
 
	userManager_->removeAllUsers();
 
	component_->stop();
 
	eventLoop_->stop();
 
}
 
 
static void spectrum_sigint_handler(int sig) {
 
	eventLoop_->postEvent(&stop_spectrum);
 
}
 
 
static void spectrum_sigterm_handler(int sig) {
 
	eventLoop_->stop();
 
	eventLoop_->postEvent(&stop_spectrum);
 
}
 
 
#ifndef WIN32
 
@@ -236,6 +244,7 @@ int main(int argc, char **argv)
 
	UserRegistry userRegistry(&config, factories);
 
 
	Component transport(&eventLoop, factories, &config, NULL, &userRegistry);
 
	component_ = &transport;
 
// 	Logger logger(&transport);
 
 
	StorageBackend *storageBackend = NULL;
 
@@ -260,6 +269,7 @@ int main(int argc, char **argv)
 
#endif
 
 
	UserManager userManager(&transport, &userRegistry, storageBackend);
 
	userManager_ = &userManager;
 
	UserRegistration *userRegistration = NULL;
 
	if (storageBackend) {
 
		userRegistration = new UserRegistration(&transport, &userManager, storageBackend);
 
@@ -275,6 +285,7 @@ int main(int argc, char **argv)
 
	eventLoop_ = &eventLoop;
 
 
	eventLoop.run();
 
 
	if (userRegistration) {
 
		userRegistration->stop();
 
		delete userRegistration;
src/transport.cpp
Show inline comments
 
@@ -177,7 +177,8 @@ void Component::start() {
 
void Component::stop() {
 
	if (m_component) {
 
		m_reconnectCount = 0;
 
		m_component->disconnect();
 
		// TODO: Call this once swiften will fix assert(!session_);
 
// 		m_component->disconnect();
 
		m_reconnectTimer->stop();
 
	}
 
	else if (m_server) {
src/usermanager.cpp
Show inline comments
 
@@ -105,6 +105,12 @@ void UserManager::removeUser(User *user) {
 
// 	VALGRIND_DO_LEAK_CHECK;
 
}
 

	
 
void UserManager::removeAllUsers() {
 
	while(m_users.begin() != m_users.end()) {
 
		removeUser((*m_users.begin()).second);
 
	}
 
}
 

	
 
int UserManager::getUserCount() {
 
	return m_users.size();
 
}
0 comments (0 inline, 0 general)