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

Debug some fault-codes

上级 45feefce
......@@ -53,3 +53,6 @@ FORMS += zpmainframe.ui \
RESOURCES += \
resource.qrc
OTHER_FILES += \
ZoomPipeline_FuncSvr_zh_CN.ts
#include "zp_net_threadpool.h"
#include <QCoreApplication>
#include <QStringList>
#include <QTcpSocket>
#include <QSslSocket>
namespace ZPNetwork{
/**
* @brief Construct a net thread pool object.
......@@ -82,33 +81,6 @@ namespace ZPNetwork{
return 0;
}
QString zp_net_ThreadPool::GenSockMsg(QObject * pSock)
{
QString msg;
msg += tr("Obj=%1").arg((unsigned int)pSock);
QTcpSocket * pSocket = qobject_cast<QTcpSocket *>(pSock);
QTcpSocket * pSocketSSL = qobject_cast<QSslSocket *>(pSock);
if (pSocketSSL)
{
msg += tr (",SSLSock,Local=(%1:%2),Peer=%3(%4:%5)")
.arg(pSocket->localAddress().toString())
.arg(pSocket->localPort())
.arg(pSocket->peerName())
.arg(pSocket->peerAddress().toString())
.arg(pSocket->peerPort());
}
else if (pSocket)
{
msg += tr (",TcpSock,Local=(%1:%2),Peer=%3(%4:%5)")
.arg(pSocket->localAddress().toString())
.arg(pSocket->localPort())
.arg(pSocket->peerName())
.arg(pSocket->peerAddress().toString())
.arg(pSocket->peerPort());
}
return msg;
}
/**
* @brief Begin a listening socket at special address and port. The socket will be activated as soon as possible
* The Wait-and-Accept approaches are all managed by Listening thread, instead of main-GUI thread.
......@@ -207,9 +179,10 @@ namespace ZPNetwork{
}
//qDebug()<<i<<" "<<nPat<<" "<<nMinIdx;
}
// for (int i=0;i<nsz;i++)
// if (m_vec_NetTransThreads[i]->isActive()==false )
// TransThreadDel(m_vec_NetTransThreads[i]);
//remove old threads
for (int i=0;i<nsz;i++)
if (m_vec_NetTransThreads[i]->isActive()==false )
TransThreadDel(m_vec_NetTransThreads[i]);
if (nMinIdx>=0 && nMinIdx<nsz)
emit evt_EstablishConnection(m_vec_NetTransThreads[nMinIdx],socketDescriptor);
......@@ -483,9 +456,10 @@ namespace ZPNetwork{
}
//qDebug()<<i<<" "<<nPat<<" "<<nMinIdx;
}
// for (int i=0;i<nsz;i++)
// if (m_vec_NetTransThreads[i]->isActive()==false )
// TransThreadDel(m_vec_NetTransThreads[i]);
//remove old threads
for (int i=0;i<nsz;i++)
if (m_vec_NetTransThreads[i]->isActive()==false )
TransThreadDel(m_vec_NetTransThreads[i]);
if (nMinIdx>=0 && nMinIdx<nsz)
{
......
......@@ -28,9 +28,6 @@ namespace ZPNetwork{
public:
explicit zp_net_ThreadPool(int nPayLoad = 4096,QObject *parent = 0);
// Dump errmessage
static QString GenSockMsg(QObject * pSock);
//Listening Ctrl
//Begin a listening socket at special address and port. The socket will be activated as soon as possible
void AddListeningAddress(const QString & id,const QHostAddress & address , quint16 nPort,bool bSSLConn = true);
......
......@@ -7,6 +7,9 @@
#include <QFileDialog>
#include <QSqlDatabase>
#include <QMap>
#include <QTcpSocket>
#include <QSslSocket>
#include "smartlink/st_clientnode_basetrans.h"
#include "dialogaddressinput.h"
using namespace ZPNetwork;
using namespace ZPTaskEngine;
......@@ -20,7 +23,7 @@ ZPMainFrame::ZPMainFrame(QWidget *parent) :
//Create net engine
m_netEngine = new zp_net_ThreadPool (8192);
connect (m_netEngine,&zp_net_ThreadPool::evt_Message,this,&ZPMainFrame::on_evt_Message);
connect (m_netEngine,&zp_net_ThreadPool::evt_Message,this,&ZPMainFrame::on_evt_MessageNetwork);
connect (m_netEngine,&zp_net_ThreadPool::evt_SocketError,this,&ZPMainFrame::on_evt_SocketError);
//Create TaskEngine
m_taskEngine = new zp_pipeline(this);
......@@ -64,12 +67,22 @@ ZPMainFrame::~ZPMainFrame()
m_pClusterTerm->netEng()->KickAllClients();
m_pClusterTerm->netEng()->DeactiveImmediately();
m_pClusterTerm->taskEng()->removeThreads(-1);
int maxWait = 0;
while (m_netEngine->CanExit()==false || m_taskEngine->canClose()==false
|| m_pDatabases->isRunning()==true || m_pClusterTerm->canExit()==false)
{
QCoreApplication::processEvents();
QThread::currentThread()->msleep(200);
maxWait ++;
if (maxWait>=150)
{
if (QMessageBox::information(0,tr("Confire Exit"),
tr("There are still some clients alive in the server. continue waiting?"),
QMessageBox::Yes|QMessageBox::No)==QMessageBox::Yes)
maxWait = 0;
else
break;
}
}
delete ui;
......@@ -90,12 +103,10 @@ void ZPMainFrame::changeEvent(QEvent *e)
void ZPMainFrame::initUI()
{
//Message Shown model
m_pMsgModel = new QStandardItemModel(this);
ui->listView_msg->setModel(m_pMsgModel);
m_pMsgModelNetwork = new QStandardItemModel(this);
ui->listView_msg->setModel(m_pMsgModelNetwork);
m_pMsgModelCluster = new QStandardItemModel(this);
ui->listView_msg_cluster->setModel(m_pMsgModelCluster);
m_pMsgModelDebug = new QStandardItemModel(this);
ui->listView_msg_debug->setModel(m_pMsgModelDebug);
m_pMsgModelDatabase = new QStandardItemModel(this);
ui->listView_msg_database->setModel(m_pMsgModelDatabase);
m_pMsgModelSmartlink = new QStandardItemModel(this);
......@@ -128,67 +139,39 @@ void ZPMainFrame::initUI()
ui->comboBox_db_type->setModel(pCombo);
}
void ZPMainFrame::on_evt_Message(QObject * psource,const QString & strMsg)
void ZPMainFrame::on_evt_MessageNetwork(QObject * psource,const QString & strMsg)
{
QDateTime dtm = QDateTime::currentDateTime();
QString msg = dtm.toString("yyyy-MM-dd HH:mm:ss.zzz") + " " + strMsg;
if (strMsg.left(5)==QString("Debug"))
{
int nrows = m_pMsgModelDebug->rowCount();
m_pMsgModelDebug->insertRow(0,new QStandardItem(msg));
while (nrows-- > 16384)
m_pMsgModelDebug->removeRow(m_pMsgModelDebug->rowCount()-1);
}
else
{
int nrows = m_pMsgModel->rowCount();
m_pMsgModel->insertRow(0,new QStandardItem(msg));
while (nrows-- > 16384)
m_pMsgModel->removeRow(m_pMsgModel->rowCount()-1);
}
msg += tr(",Source=%1").arg((unsigned int)psource);
int nrows = m_pMsgModelNetwork->rowCount();
m_pMsgModelNetwork->insertRow(0,new QStandardItem(msg));
while (nrows-- > 4096)
m_pMsgModelNetwork->removeRow(m_pMsgModelNetwork->rowCount()-1);
}
void ZPMainFrame::on_evt_Message_Database(QObject * psource,const QString &strMsg)
{
QDateTime dtm = QDateTime::currentDateTime();
QString msg = dtm.toString("yyyy-MM-dd HH:mm:ss.zzz") + " " + strMsg;
if (strMsg.left(5)==QString("Debug"))
{
int nrows = m_pMsgModelDebug->rowCount();
m_pMsgModelDebug->insertRow(0,new QStandardItem(msg));
while (nrows-- > 16384)
m_pMsgModelDebug->removeRow(m_pMsgModelDebug->rowCount()-1);
}
else
{
int nrows = m_pMsgModelDatabase->rowCount();
m_pMsgModelDatabase->insertRow(0,new QStandardItem(msg));
while (nrows-- > 16384)
m_pMsgModelDatabase->removeRow(m_pMsgModelDatabase->rowCount()-1);
}
msg += tr(",Source=%1").arg((unsigned int)psource);
int nrows = m_pMsgModelDatabase->rowCount();
m_pMsgModelDatabase->insertRow(0,new QStandardItem(msg));
while (nrows-- > 4096)
m_pMsgModelDatabase->removeRow(m_pMsgModelDatabase->rowCount()-1);
}
void ZPMainFrame::on_evt_Message_Smartlink(QObject * psource,const QString &strMsg)
{
QDateTime dtm = QDateTime::currentDateTime();
QString msg = dtm.toString("yyyy-MM-dd HH:mm:ss.zzz") + " " + strMsg;
if (strMsg.left(5)==QString("Debug"))
{
int nrows = m_pMsgModelDebug->rowCount();
m_pMsgModelDebug->insertRow(0,new QStandardItem(msg));
while (nrows-- > 16384)
m_pMsgModelDebug->removeRow(m_pMsgModelDebug->rowCount()-1);
}
else
{
int nrows = m_pMsgModelSmartlink->rowCount();
m_pMsgModelSmartlink->insertRow(0,new QStandardItem(msg));
while (nrows-- > 16384)
m_pMsgModelSmartlink->removeRow(m_pMsgModelSmartlink->rowCount()-1);
}
msg += tr(",Source=%1").arg((unsigned int)psource);
int nrows = m_pMsgModelSmartlink->rowCount();
m_pMsgModelSmartlink->insertRow(0,new QStandardItem(msg));
while (nrows-- > 4096)
m_pMsgModelSmartlink->removeRow(m_pMsgModelSmartlink->rowCount()-1);
}
//The socket error message
......@@ -197,10 +180,10 @@ void ZPMainFrame::on_evt_SocketError(QObject * senderSock ,QAbstractSocket::Soc
QDateTime dtm = QDateTime::currentDateTime();
QString msg = dtm.toString("yyyy-MM-dd HH:mm:ss.zzz") + " " + QString("SockError %1 with code %2")
.arg((quint64)senderSock).arg((quint32)socketError);
int nrows = m_pMsgModelDebug->rowCount();
m_pMsgModelDebug->insertRow(0,new QStandardItem(msg));
while (nrows-- > 16384)
m_pMsgModelDebug->removeRow(m_pMsgModelDebug->rowCount()-1);
int nrows = m_pMsgModelNetwork->rowCount();
m_pMsgModelNetwork->insertRow(0,new QStandardItem(msg));
while (nrows-- > 4096)
m_pMsgModelNetwork->removeRow(m_pMsgModelNetwork->rowCount()-1);
}
......@@ -208,33 +191,23 @@ void ZPMainFrame::on_evt_Message_Cluster(QObject * psource,const QString & strM
{
QDateTime dtm = QDateTime::currentDateTime();
QString msg = dtm.toString("yyyy-MM-dd HH:mm:ss.zzz") + " " + strMsg;
if (strMsg.left(5)==QString("Debug"))
{
int nrows = m_pMsgModelDebug->rowCount();
m_pMsgModelDebug->insertRow(0,new QStandardItem(msg));
while (nrows-- > 16384)
m_pMsgModelDebug->removeRow(m_pMsgModelDebug->rowCount()-1);
}
else
{
int nrows = m_pMsgModelCluster->rowCount();
m_pMsgModelCluster->insertRow(0,new QStandardItem(msg));
while (nrows-- > 16384)
m_pMsgModelCluster->removeRow(m_pMsgModelCluster->rowCount()-1);
}
msg += tr(",Source=%1").arg((unsigned int)psource);
int nrows = m_pMsgModelCluster->rowCount();
m_pMsgModelCluster->insertRow(0,new QStandardItem(msg));
while (nrows-- > 4096)
m_pMsgModelCluster->removeRow(m_pMsgModelCluster->rowCount()-1);
}
//The socket error message
void ZPMainFrame::on_evt_SocketError_Cluster(QObject * senderSock ,QAbstractSocket::SocketError socketError)
{
QDateTime dtm = QDateTime::currentDateTime();
QString msg = dtm.toString("yyyy-MM-dd HH:mm:ss.zzz") + " (Cluster)" + QString("SockError %1 with code %2")
QString msg = dtm.toString("yyyy-MM-dd HH:mm:ss.zzz") + " " + QString("SockError %1 with code %2")
.arg((quint64)senderSock).arg((quint32)socketError);
int nrows = m_pMsgModelDebug->rowCount();
m_pMsgModelDebug->insertRow(0,new QStandardItem(msg));
while (nrows-- > 16384)
m_pMsgModelDebug->removeRow(m_pMsgModelDebug->rowCount()-1);
int nrows = m_pMsgModelCluster->rowCount();
m_pMsgModelCluster->insertRow(0,new QStandardItem(msg));
while (nrows-- > 4096)
m_pMsgModelCluster->removeRow(m_pMsgModelCluster->rowCount()-1);
}
......@@ -449,8 +422,13 @@ void ZPMainFrame::forkServer(const QString & config_file)
int nClusterWorkingThreads = settings.value("Cluster/nClusterWorkingThreads","4").toInt();
this->m_pClusterTerm->netEng()->RemoveAllAddresses();
this->m_pClusterTerm->netEng()->RemoveClientTransThreads(-1,false);
this->m_pClusterTerm->netEng()->AddClientTransThreads(nClusterTransThreads,false);
this->m_pClusterTerm->taskEng()->removeThreads(-1);
while (m_pClusterTerm->netEng()->ListenerNames().size())
{
QThread::currentThread()->msleep(200);
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
}
this->m_pClusterTerm->netEng()->AddClientTransThreads(nClusterTransThreads,false);
this->m_pClusterTerm->taskEng()->addThreads(nClusterWorkingThreads);
this->m_pClusterTerm->setName(strClusterPubName);
this->m_pClusterTerm->setPublishAddr(QHostAddress(strClusterPubAddr));
......
......@@ -22,13 +22,13 @@ public:
explicit ZPMainFrame(QWidget *parent = 0);
~ZPMainFrame();
void timerEvent(QTimerEvent *);
protected:
void changeEvent(QEvent *e);
QStandardItemModel * m_pMsgModel;
QStandardItemModel * m_pMsgModelNetwork;
QStandardItemModel * m_pMsgModelCluster;
QStandardItemModel * m_pMsgModelDatabase;
QStandardItemModel * m_pMsgModelSmartlink;
QStandardItemModel * m_pMsgModelDebug;
//Config File Name
QString m_currentConffile;
//Listeners settings
......@@ -57,7 +57,7 @@ private:
void forkServer(const QString & config_file);
protected slots:
void on_evt_Message(QObject * psource,const QString &);
void on_evt_MessageNetwork(QObject * psource,const QString &);
//The socket error message
void on_evt_SocketError(QObject * senderSock ,QAbstractSocket::SocketError socketError);
void on_evt_Message_Cluster(QObject * psource,const QString &);
......
......@@ -938,20 +938,6 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_msg_debug">
<attribute name="icon">
<iconset resource="resource.qrc">
<normaloff>:/icons/Resources/BackUp-4.png</normaloff>:/icons/Resources/BackUp-4.png</iconset>
</attribute>
<attribute name="title">
<string>Debug</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_20">
<item>
<widget class="QListView" name="listView_msg_debug"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册