Esempio n. 1
0
bool TCPServer::handleError(PSocketContext pSocketContext)
{
	FastMutex::ScopedLock lock(_mtClients);

	auto* pClient = findClients(pSocketContext);
	if(nullptr == pClient) {
		return true;// 数据包过多可能造成该会话已经被清理掉
	}

	auto errID = WSAGetLastError();
	if(WAIT_TIMEOUT == errID) {
		if(!pClient->isAlive()) {
			LOG("网络超时!客户端离线");
			removeClients(pClient);
		} else {
			LOG("网络超时!客户端在线");
		}

	} else if(ERROR_NETNAME_DELETED == errID) {
		LOG("检测到客户端非正常离线");
		removeClients(pClient);

	} else {
		SYSLOG("完成端口操作出现错误,线程退出", errID);
		return false;
	}

	return true;
}
Esempio n. 2
0
void TCPServer::handleClose(PSocketContext pSocketContext)
{
	auto pClient = findClients(pSocketContext);
	LOG("客户端[%s-%d]正常离线", pClient->getPeerIP(),
		pClient->getPeerPort());

	removeClients(pClient);
}
Esempio n. 3
0
MainPresenter::MainPresenter(IViewForm *view, QObject *perent)
    :QObject(perent), m_view(view)
{
    QObject* view_obj = dynamic_cast<QObject*>(m_view);
    QObject::connect(view_obj, SIGNAL(actionFindClient()),
            this, SLOT(findClients()));
    QObject::connect(view_obj, SIGNAL(actionAddClient()),
            this, SLOT(addClient()));
    QObject::connect(view_obj, SIGNAL(actionReturnIndex(const int)),
            this, SLOT(createClientWindow(const int)));
    QObject::connect(view_obj, SIGNAL(actionRemoveClient(const int)),
            this, SLOT(removeClient(const int)));

    dbManager = DataBaseManager::getInstance();

    findClients();

}
Esempio n. 4
0
void TCPServer::handleRead(
	PSocketContext pSocketContext, 
	PIOContext pIOContext)
{
	auto pClient = dynamic_cast<TCPServerSession*>(
		findClients(pSocketContext));

	if(pClient->unPacket(pIOContext)) {
		pClient->postRecv(pIOContext);
	}
}
Esempio n. 5
0
void MainPresenter::addClient()
{
    Client client;
    client.setID(dbManager->getMaxID() + 1);
    client.setSurname(m_view->getLastName());
    client.setName(m_view->getName());
    client.setPatronymic(m_view->getPatronymic());
    client.setYear(m_view->getYear());
    client.setAddr(m_view->getAddress());
    client.setDisability(m_view->getDisability());
    client.setGroup(m_view->getGroup());

    if (!dbManager->insertClientInDB(client)) {
        QMessageBox msgBox;
        msgBox.setWindowTitle("Ошибка!");
        msgBox.setText("Не могу добавить в базу клиента.");
        msgBox.setStandardButtons(QMessageBox::Ok);
        msgBox.setIcon(QMessageBox::Critical);
        msgBox.exec();
    }
    refreshView();
    findClients();
}
Esempio n. 6
0
void BackupServer::operator()(void)
{
	IDatabase *db=Server->getDatabase(Server->getThreadID(),URBACKUPDB_SERVER);
	ISettingsReader *settings=Server->createDBSettingsReader(Server->getDatabase(Server->getThreadID(),URBACKUPDB_SERVER), "settings_db.settings");

#ifdef _WIN32
	std::wstring tmpdir;
	if(settings->getValue(L"tmpdir", &tmpdir) && !tmpdir.empty())
	{
		os_remove_nonempty_dir(tmpdir+os_file_sep()+L"urbackup_tmp");
		if(!os_create_dir(tmpdir+os_file_sep()+L"urbackup_tmp"))
		{
			Server->wait(5000);
			os_create_dir(tmpdir+os_file_sep()+L"urbackup_tmp");
		}
		Server->setTemporaryDirectory(tmpdir+os_file_sep()+L"urbackup_tmp");
	}
	else
	{
		wchar_t tmpp[MAX_PATH];
		DWORD l;
		if((l=GetTempPathW(MAX_PATH, tmpp))==0 || l>MAX_PATH )
		{
			wcscpy_s(tmpp,L"C:\\");
		}

		std::wstring w_tmp=tmpp;

		if(!w_tmp.empty() && w_tmp[w_tmp.size()-1]=='\\')
		{
			w_tmp.erase(w_tmp.size()-1, 1);		}


		os_remove_nonempty_dir(w_tmp+os_file_sep()+L"urbackup_tmp");
		if(!os_create_dir(w_tmp+os_file_sep()+L"urbackup_tmp"))
		{
			Server->wait(5000);
			os_create_dir(tmpdir+os_file_sep()+L"urbackup_tmp");
		}
		Server->setTemporaryDirectory(w_tmp+os_file_sep()+L"urbackup_tmp");
	}
#endif
	if( settings->getValue("use_tmpfiles", "")!="true" )
	{
		std::wstring backupfolder;
		if( settings->getValue(L"backupfolder", &backupfolder) )
		{
			std::wstring tmpfile_path=backupfolder+os_file_sep()+L"urbackup_tmp_files";

			Server->Log("Removing temporary files...");
			os_remove_nonempty_dir(tmpfile_path);
			Server->Log("Recreating temporary folder...");
			if(!os_create_dir(tmpfile_path))
			{
				Server->wait(5000);
				os_create_dir(tmpfile_path);
			}
		}
	}

	testSnapshotAvailability(db);

	q_get_extra_hostnames=db->Prepare("SELECT id,hostname FROM settings_db.extra_clients");
	q_update_extra_ip=db->Prepare("UPDATE settings_db.extra_clients SET lastip=? WHERE id=?");

	FileClient fc;

	Server->wait(1000);

	while(true)
	{
		findClients(fc);
		startClients(fc);

		if(!ServerStatus::isActive() && settings->getValue("autoshutdown", "false")=="true")
		{
			writestring("true", "urbackup/shutdown_now");
#ifdef _WIN32
			ExitWindowsEx(EWX_POWEROFF|EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_APPLICATION|SHTDN_REASON_MINOR_OTHER );
#endif
		}

		std::string r;
		exitpipe->Read(&r, 20000);
		if(r=="exit")
		{
			removeAllClients();
			exitpipe->Write("ok");
			Server->destroy(settings);
			db->destroyAllQueries();
			delete this;
			return;
		}
	}
}
Esempio n. 7
0
void MainPresenter::removeClient(const int index)
{
    dbManager->removeClient(clients.at(index)->getID());
    refreshView();
    findClients();
}