Пример #1
0
bool TaskManager::start_server()
{
	//Init NetInterface
	init_net_interface();
	set_thread_ready();

	//// Add Your Codes Here
	////////////////////////
	SLOG_INFO("Start download server.");
	get_io_demuxer()->run_loop();

	return true;
}
Пример #2
0
/////////////////////////////////////// MasterServer ///////////////////////////////////////
bool MasterServer::start_server()
{
	//Init NetInterface
	init_net_interface();
	set_thread_ready();

	////Add your codes here
	///////////////////////
	m_saving_task_timeout_sec = g_config_reader->GetValueInt("SavingTaskTimeout", 120);

	//数据库
	m_db_connection = NULL;
	m_db_ip     = g_config_reader->GetValueString("DBIP");
	m_db_port   = g_config_reader->GetValueInt("DBPort", 0);
	m_db_user   = g_config_reader->GetValueString("DBUser");
	m_db_passwd = g_config_reader->GetValueString("DBPassword");
	m_db_name   = g_config_reader->GetValueString("DBName");
	if(m_db_ip!="" && m_db_user!="" && m_db_passwd!="" && m_db_name!="")
	{
		m_db_connection = new Connection(m_db_name.c_str(), m_db_ip.c_str(), m_db_user.c_str(), m_db_passwd.c_str(), m_db_port);
		if(!m_db_connection->connected())
		{
			SLOG_ERROR("connect DB error.db=%s, ip=%s, port=%d, user=%s, pwd=%s."
						,m_db_name.c_str()
						,m_db_ip.c_str()
						,m_db_port
						,m_db_user.c_str()
						,m_db_passwd.c_str());
			delete m_db_connection;
		}
	}
	else
	{
		SLOG_WARN("DB parameters is invalid. no using DB!!!");
	}

	//注册定时器
	IODemuxer *io_demuxer = get_io_demuxer();
	assert(io_demuxer != NULL);
	if(io_demuxer->register_event(-1, EVENT_PERSIST, 3000, this) == -1)
	{
		SLOG_ERROR("register timer handler failed.");
		return false;
	}
	io_demuxer->run_loop();
	return true;
}