提交 aca13f1d 编写于 作者: 丁劲犇's avatar 丁劲犇 😸

Add dead client kicked out method. clients who lost heart-beating will be kicked in minutes

上级 94722e9d
......@@ -13,45 +13,54 @@ st_client_table::st_client_table(ZPNetwork::zp_net_ThreadPool * pool, ZPTaskEngi
connect (m_pThreadPool,&ZPNetwork::zp_net_ThreadPool::evt_Data_recieved,this,&st_client_table::on_evt_Data_recieved,Qt::QueuedConnection);
connect (m_pThreadPool,&ZPNetwork::zp_net_ThreadPool::evt_Data_transferred,this,&st_client_table::on_evt_Data_transferred,Qt::QueuedConnection);
}
st_client_table::~st_client_table()
st_client_table::~st_client_table()
{
}
void st_client_table::KickDealClients()
{
m_hash_mutex.lock();
for (QMap<QObject *,st_clientNode *>::iterator p =m_hash_sock2node.begin();
p!=m_hash_sock2node.end();p++)
{
p.value()->CheckHeartBeating();
}
m_hash_mutex.unlock();
}
bool st_client_table::regisitClientUUID(st_clientNode * c)
{
if (c->uuidValid()==false)
return false;
m_hash_mutex.lock();
m_hash_uuid2node[c->uuid()] = c;
m_hash_mutex.unlock();
return true;
}
bool st_client_table::regisitClientUUID(st_clientNode * c)
{
if (c->uuidValid()==false)
return false;
m_hash_mutex.lock();
m_hash_uuid2node[c->uuid()] = c;
m_hash_mutex.unlock();
return true;
}
st_clientNode * st_client_table::clientNodeFromUUID(quint32 uuid)
{
m_hash_mutex.lock();
if (m_hash_uuid2node.contains(uuid))
{
m_hash_mutex.unlock();
return m_hash_uuid2node[uuid];
}
m_hash_mutex.unlock();
return NULL;
}
st_clientNode * st_client_table::clientNodeFromSocket(QObject * sock)
{
m_hash_mutex.lock();
if (m_hash_sock2node.contains(sock))
{
m_hash_mutex.unlock();
return m_hash_sock2node[sock];
}
m_hash_mutex.unlock();
return NULL;
}
st_clientNode * st_client_table::clientNodeFromUUID(quint32 uuid)
{
m_hash_mutex.lock();
if (m_hash_uuid2node.contains(uuid))
{
m_hash_mutex.unlock();
return m_hash_uuid2node[uuid];
}
m_hash_mutex.unlock();
return NULL;
}
st_clientNode * st_client_table::clientNodeFromSocket(QObject * sock)
{
m_hash_mutex.lock();
if (m_hash_sock2node.contains(sock))
{
m_hash_mutex.unlock();
return m_hash_sock2node[sock];
}
m_hash_mutex.unlock();
return NULL;
}
//this event indicates new client connected.
......@@ -94,7 +103,7 @@ void st_client_table::on_evt_ClientDisconnected(QObject * clientHandle)
toBedel.push_back(pdelobj);
else
{
//qDebug()<<QString("%1(ref %2) Waiting in del queue.\n").arg((unsigned int)pdelobj).arg(pdelobj->ref());
//qDebug()<<QString("%1(ref %2) Waiting in del queue.\n").arg((unsigned int)pdelobj).arg(pdelobj->ref());
}
}
foreach(st_clientNode * pdelobj,toBedel)
......
......@@ -20,7 +20,7 @@ public:
bool regisitClientUUID(st_clientNode *);
st_clientNode * clientNodeFromUUID(quint32);
st_clientNode * clientNodeFromSocket(QObject *);
void KickDealClients();
protected:
QList<st_clientNode *> m_nodeToBeDel;
QMutex m_hash_mutex;
......
......@@ -253,7 +253,7 @@ int st_clientNode::deal_current_message_block()
//need further dev, insert into db, or catched on disk.
//destin client is un-reachable, or in another function server.
//need server-to-server channels to re-post this message.
emit evt_Message(tr("Destin ID ") + QString("%1").arg(m_currentHeader.destin_id) + tr(" is not currently logged in.\n"));
emit evt_Message(tr("Destin ID ") + QString("%1").arg(m_currentHeader.destin_id) + tr(" is not currently logged in."));
//Do Nothing
}
......@@ -266,4 +266,15 @@ int st_clientNode::deal_current_message_block()
}
return 0;
}
void st_clientNode::CheckHeartBeating()
{
QDateTime dtm = QDateTime::currentDateTime();
qint64 usc = this->m_last_Report.secsTo(dtm);
if (usc >=60)
{
emit evt_Message(tr("Client ") + QString("%1").arg((unsigned int)(this)) + tr(" is dead, kick out."));
emit evt_close_client(this->sock());
}
}
}
......@@ -34,7 +34,7 @@ public:
{
return m_last_Report;
}
void CheckHeartBeating();
protected:
//!deal one message, affect m_currentRedOffset,m_currentMessageSize,m_currentHeader
//!return bytes Used.
......
......@@ -31,7 +31,7 @@ ZPMainFrame::ZPMainFrame(QWidget *parent) :
m_pDatabases->start();
m_nTimerId = startTimer(500);
m_nTimerCheck = startTimer(10000);
initUI();
LoadSettings(m_currentConffile);
}
......@@ -163,6 +163,11 @@ void ZPMainFrame::timerEvent(QTimerEvent * e)
ui->plainTextEdit_status_net->setPlainText(str_msg);
}
else if (e->timerId()==m_nTimerCheck)
{
m_clientTable->KickDealClients();
}
}
void ZPMainFrame::on_action_Start_Stop_triggered(bool setordel)
{
......
......@@ -20,10 +20,9 @@ class ZPMainFrame : public QMainWindow
public:
explicit ZPMainFrame(QWidget *parent = 0);
~ZPMainFrame();
void timerEvent(QTimerEvent *);
protected:
void changeEvent(QEvent *e);
void timerEvent(QTimerEvent *);
QStandardItemModel * m_pMsgModel;
//Config File Name
......@@ -35,6 +34,9 @@ protected:
QStandardItemModel * m_pDbResModel;
QMap<QString,QString> m_set_DbResNames;
//Dead check
int m_nTimerCheck;
private:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册