diff --git a/FunctionalClientTest/FunctionalClientTest.pro b/FunctionalClientTest/FunctionalClientTest.pro index 527229a4a4407d6bd7f3d89f3a2aa460410b3756..bdc034471401ce827c5a68caf77e75ddab0db014 100644 --- a/FunctionalClientTest/FunctionalClientTest.pro +++ b/FunctionalClientTest/FunctionalClientTest.pro @@ -8,7 +8,7 @@ QT += core gui network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -TARGET = $$OUT_PWD/../bin/FunctionalClientTest +TARGET = FunctionalClientTest TEMPLATE = app diff --git a/QTcpClientTest/QTcpClientTest.pro b/QTcpClientTest/QTcpClientTest.pro index 395c516b828fc52c78056e71ee3c34254ea33134..26b16b3d5a707508d94d81a0f3306a03c00badc6 100644 --- a/QTcpClientTest/QTcpClientTest.pro +++ b/QTcpClientTest/QTcpClientTest.pro @@ -7,7 +7,7 @@ QT += core gui network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -TARGET = $$OUT_PWD/../bin/QTcpClientTest +TARGET = QTcpClientTest TEMPLATE = app # Input HEADERS += qghtcpclient.h qtcpclienttest.h \ diff --git a/ZoomPipeline_FuncSvr/ZoomPipeline_FuncSvr.pro b/ZoomPipeline_FuncSvr/ZoomPipeline_FuncSvr.pro index 5f2b7c2b6915ecce8fb1ed729936ed62156e4902..8c17a5384b35c40717f9501f8f4bc008dc5a6784 100644 --- a/ZoomPipeline_FuncSvr/ZoomPipeline_FuncSvr.pro +++ b/ZoomPipeline_FuncSvr/ZoomPipeline_FuncSvr.pro @@ -9,7 +9,7 @@ unix:QMAKE_CXXFLAGS += -std=c++11 win32-g++: QMAKE_CXXFLAGS += -std=c++11 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -TARGET = $$OUT_PWD/../bin/ZoomPipeline_FuncSvr +TARGET = ZoomPipeline_FuncSvr TEMPLATE = app diff --git a/ZoomPipeline_FuncSvr/cluster/zp_clusternode.cpp b/ZoomPipeline_FuncSvr/cluster/zp_clusternode.cpp index 7b94ef3b197ad6ea2d289403112119b6bf7d1b1e..217d8fb3bb920778faa9e20dde1534906fdffbd5 100644 --- a/ZoomPipeline_FuncSvr/cluster/zp_clusternode.cpp +++ b/ZoomPipeline_FuncSvr/cluster/zp_clusternode.cpp @@ -307,7 +307,7 @@ namespace ZP_Cluster{ //because cross-connection is not good, we just want the low Addr:port connect to max Addr:Port. //Connect to New Servers if (strName > m_pTerm->name()) - emit evt_connect_to(addrToConnectTo,PortToConnectTo,false); + emit evt_connect_to(addrToConnectTo,PortToConnectTo,false,0); else emit evt_Message(this,tr("Name %1 <= %2, omitted.").arg(strName).arg(m_pTerm->name())); } diff --git a/ZoomPipeline_FuncSvr/cluster/zp_clusternode.h b/ZoomPipeline_FuncSvr/cluster/zp_clusternode.h index cb825c9b584b1740848fdf66dd512f22ba0fc047..03feabe7c34ec1a8aa62192280c1f4c23f0cc79b 100644 --- a/ZoomPipeline_FuncSvr/cluster/zp_clusternode.h +++ b/ZoomPipeline_FuncSvr/cluster/zp_clusternode.h @@ -80,7 +80,7 @@ namespace ZP_Cluster{ signals: void evt_SendDataToClient(QObject * objClient,QByteArray dtarray); void evt_close_client(QObject * objClient); - void evt_connect_to(const QHostAddress & address , quint16 nPort,bool bSSLConn); + void evt_connect_to(const QHostAddress & address , quint16 nPort,bool bSSLConn, quint64); void evt_Message (QObject * psource,QString ); //Notify Messages diff --git a/ZoomPipeline_FuncSvr/cluster/zp_clusterterm.cpp b/ZoomPipeline_FuncSvr/cluster/zp_clusterterm.cpp index adf4df9412af460b424495a8d7cb393978029cb0..781e07dfe1840a77b956b62346e815cf1855670e 100644 --- a/ZoomPipeline_FuncSvr/cluster/zp_clusterterm.cpp +++ b/ZoomPipeline_FuncSvr/cluster/zp_clusterterm.cpp @@ -129,7 +129,7 @@ namespace ZP_Cluster{ } bool zp_ClusterTerm::JoinCluster(const QHostAddress &addr, int nPort,bool bSSL) { - return m_pClusterNet->connectTo(addr,nPort,bSSL); + return m_pClusterNet->connectTo(addr,nPort,bSSL,0); } bool zp_ClusterTerm::canExit() { diff --git a/ZoomPipeline_FuncSvr/network/zp_net_threadpool.cpp b/ZoomPipeline_FuncSvr/network/zp_net_threadpool.cpp index 24eee2f6c08ed6e66d2cb02b9561f5ada76d5382..f6623e0ce6293de48b43382490f55cbfd5ae9e1f 100644 --- a/ZoomPipeline_FuncSvr/network/zp_net_threadpool.cpp +++ b/ZoomPipeline_FuncSvr/network/zp_net_threadpool.cpp @@ -420,9 +420,11 @@ namespace ZPNetwork{ * @param address the address to connect to * @param nPort port to connect to * @param bSSLConn if true, SSL connections will be used + * @param extraData Extra data for users to remember extra imformation for this connection.this message will be + * given back when on_connect is called. * @return bool */ - bool zp_net_Engine::connectTo (const QHostAddress & address , quint16 nPort,bool bSSLConn) + bool zp_net_Engine::connectTo (const QHostAddress & address , quint16 nPort,bool bSSLConn, quint64 extraData) { bool res= false; //m_mutex_trans.lock(); @@ -453,7 +455,7 @@ namespace ZPNetwork{ if (nMinIdx>=0 && nMinIdx=RUBBISH_CAN_SIZE) { + if (m_extraData.contains(m_rabish_can.first())) m_extraData.remove(m_rabish_can.first()); m_rabish_can.first()->deleteLater(); m_set_rabish.remove(m_rabish_can.first()); m_rabish_can.pop_front(); @@ -161,6 +162,10 @@ namespace ZPNetwork{ #endif if (sock_client) { + quint64 extraData = 0; + if (m_extraData.contains(sock_client)) + extraData = m_extraData[sock_client]; + //Initial content if (true ==sock_client->setSocketDescriptor(socketDescriptor)) { @@ -186,7 +191,7 @@ namespace ZPNetwork{ #endif qDebug()<peerAddress().toString()<< sock_client->peerPort() <" + QString(tr("Client Accepted."))); } else @@ -202,7 +207,7 @@ namespace ZPNetwork{ * @param addr address to which the socket should be connected. * @param port port to which the socket should be connected. */ - void zp_netTransThread::startConnection(QObject * threadid,const QHostAddress & addr, quint16 port) + void zp_netTransThread::startConnection(QObject * threadid,const QHostAddress & addr, quint16 port, quint64 extraData) { if (threadid!=this) return; @@ -217,6 +222,7 @@ namespace ZPNetwork{ #endif if (sock_client) { + m_extraData[sock_client] = extraData; #if (ZP_WANTSSL!=0) if (m_bSSLConnection==true) { @@ -270,7 +276,9 @@ namespace ZPNetwork{ void zp_netTransThread::on_connected() { QTcpSocket * pSock = qobject_cast(sender()); - emit evt_NewClientConnected(pSock); + quint64 extraData = 0; + if (m_extraData.contains(pSock)) extraData = m_extraData[pSock]; + emit evt_NewClientConnected(pSock,extraData); emit evt_Message(pSock,"Info>" + QString(tr("Client connected."))); qDebug()<peerAddress().toString()<< pSock->peerPort() <(sender()); - emit evt_ClientEncrypted(pSock); + quint64 extraData = 0; + if (m_extraData.contains(pSock)) extraData = m_extraData[pSock]; + emit evt_ClientEncrypted(pSock,extraData); //emit evt_Message(pSock,"Info>" + QString(tr("Client Encrypted."))); qDebug()<peerAddress().toString()<< pSock->peerPort() <(sender()); if (pSock) { + quint64 extraData = 0; + if (m_extraData.contains(pSock)) extraData = m_extraData[pSock]; + #if (ZP_WANTSSL!=0) if (m_bSSLConnection) { @@ -310,7 +323,7 @@ namespace ZPNetwork{ m_clientList.remove(pSock); m_mutex_protect.unlock(); //pSock->abort(); - emit evt_ClientDisconnected(pSock); + emit evt_ClientDisconnected(pSock,extraData); emit evt_Message(pSock,"Info>" + QString(tr("Client Closed."))); qDebug()<(sender()); if (pSock) { + quint64 extraData = 0; + if (m_extraData.contains(pSock)) extraData = m_extraData[pSock]; + QByteArray array = pSock->readAll(); int sz = array.size(); g_mutex_sta.lock(); g_bytesRecieved +=sz; g_secRecieved += sz; g_mutex_sta.unlock(); - emit evt_Data_recieved(pSock,array); + emit evt_Data_recieved(pSock,array,extraData); } } /** @@ -346,7 +362,10 @@ namespace ZPNetwork{ QTcpSocket * pSock = qobject_cast(sender()); if (pSock) { - emit evt_Data_transferred(pSock,wsended); + quint64 extraData = 0; + if (m_extraData.contains(pSock)) extraData = m_extraData[pSock]; + + emit evt_Data_transferred(pSock,wsended,extraData); QList & list_sock_data = m_buffer_sending[pSock]; QList & list_offset = m_buffer_sending_offset[pSock]; while (list_sock_data.empty()==false) @@ -372,9 +391,12 @@ namespace ZPNetwork{ QTcpSocket * pSock = qobject_cast(sender()); if (pSock) { + quint64 extraData = 0; + if (m_extraData.contains(pSock)) extraData = m_extraData[pSock]; + qDebug()<peerAddress().toString()<< pSock->peerPort() <errorString()); - emit evt_SocketError(pSock,socketError); + emit evt_SocketError(pSock,socketError,extraData); #if (ZP_WANTSSL!=0) if (m_bSSLConnection) { @@ -394,7 +416,7 @@ namespace ZPNetwork{ m_clientList.remove(pSock); m_mutex_protect.unlock(); pSock->abort(); - emit evt_ClientDisconnected(pSock); + emit evt_ClientDisconnected(pSock,extraData); emit evt_Message(pSock,"Info>" + QString(tr("Client Error, Closed."))); //pSock->disconnectFromHost(); push_to_rabish_can(pSock); diff --git a/ZoomPipeline_FuncSvr/network/zp_nettransthread.h b/ZoomPipeline_FuncSvr/network/zp_nettransthread.h index cd9adf3920efec93dc59979e8669beed33aff2e3..bf8b837cc726829c2066ea4cd51d108e77987748 100644 --- a/ZoomPipeline_FuncSvr/network/zp_nettransthread.h +++ b/ZoomPipeline_FuncSvr/network/zp_nettransthread.h @@ -53,12 +53,14 @@ namespace ZPNetwork{ QList m_rabish_can; QSet m_set_rabish; QMutex m_mutex_rabish_can; + //Extra Data + QHash m_extraData; void push_to_rabish_can(QObject * deletedobj); public slots: //This slot dealing with multi-thread client socket accept. void incomingConnection(QObject * threadid,qintptr socketDescriptor); //This slot dealing with possive connecting-to method. - void startConnection(QObject * threadid,const QHostAddress & addr, quint16 port); + void startConnection(QObject * threadid,const QHostAddress & addr, quint16 port, quint64 extraData); //sending dtarray to objClient. dtarray will be pushed into m_buffer_sending void SendDataToClient(QObject * objClient,QByteArray dtarray); //Set terminate mark, the thread will quit after last client quit. @@ -82,12 +84,12 @@ namespace ZPNetwork{ void on_encrypted(); signals: void evt_Message(QObject * psource,QString ); - void evt_SocketError(QObject * senderSock ,QAbstractSocket::SocketError socketError); - void evt_NewClientConnected(QObject * client); - void evt_ClientEncrypted(QObject * client); - void evt_ClientDisconnected(QObject * client); - void evt_Data_recieved(QObject * ,QByteArray ); - void evt_Data_transferred(QObject * client,qint64); + void evt_SocketError(QObject * senderSock ,QAbstractSocket::SocketError socketError, quint64 extraData); + void evt_NewClientConnected(QObject * client, quint64 extraData); + void evt_ClientEncrypted(QObject * client, quint64 extraData); + void evt_ClientDisconnected(QObject * client, quint64 extraData); + void evt_Data_recieved(QObject * ,QByteArray , quint64 extraData); + void evt_Data_transferred(QObject * client,qint64, quint64 extraData); }; } #endif // ZP_NETTRANSTHREAD_H diff --git a/zoomPipeline.pro b/zoomPipeline.pro index 8792969f10d0b1f058c9b0134efc742c2a7bdb34..582dc714506f2d0d6bce792e6a79770136f1dee4 100644 --- a/zoomPipeline.pro +++ b/zoomPipeline.pro @@ -2,4 +2,3 @@ TEMPLATE = subdirs SUBDIRS += QTcpClientTest SUBDIRS += FunctionalClientTest SUBDIRS += ZoomPipeline_FuncSvr -OTHER_FILES += .gitignore