2424
2525#include " protocol.h"
2626#include " server.h"
27- #include " client.h"
27+ #ifndef SERVER_ONLY
28+ # include " client.h"
29+ #endif
2830#include " channel.h"
2931
30- CTcpConnection::CTcpConnection ( QTcpSocket* pTcpSocket,
31- const CHostAddress& tcpAddress,
32- CServer* pServer,
33- CClient* pClient,
34- CChannel* pChannel,
35- bool bIsSession ) :
32+ #ifndef SERVER_ONLY
33+ // TCP connection used by client
34+ CTcpConnection::CTcpConnection ( QTcpSocket* pTcpSocket, const CHostAddress& tcpAddress, CClient* pClient, CChannel* pChannel, bool bIsSession ) :
3635 pTcpSocket ( pTcpSocket ),
3736 tcpAddress ( tcpAddress ),
38- pServer ( pServer ),
39- pClient ( pClient ),
37+ pServer ( nullptr ),
4038 pChannel ( pChannel ),
4139 bIsSession ( bIsSession )
4240{
@@ -47,24 +45,35 @@ CTcpConnection::CTcpConnection ( QTcpSocket* pTcpSocket,
4745 connect ( pTcpSocket, &QTcpSocket::disconnected, this , &CTcpConnection::OnDisconnected );
4846 connect ( pTcpSocket, &QTcpSocket::readyRead, this , &CTcpConnection::OnReadyRead );
4947
50- if ( pServer )
51- {
52- connect ( this , &CTcpConnection::ProtocolCLMessageReceived, pServer, &CServer::OnProtocolCLMessageReceived );
53- }
54-
55- if ( pChannel )
56- {
57- connect ( this , &CTcpConnection::ProtocolCLMessageReceived, pChannel, &CChannel::OnProtocolCLMessageReceived );
58- }
48+ connect ( this , &CTcpConnection::ProtocolCLMessageReceived, pChannel, &CChannel::OnProtocolCLMessageReceived );
5949
60- if ( pClient && bIsSession )
50+ if ( bIsSession )
6151 {
6252 // set up keepalive CLM_EMPTY_MESSAGE over TCP session connection
6353 connect ( this , &CTcpConnection::CLSendEmptyMes, pClient, &CClient::OnCLSendEmptyMes );
6454 connect ( &TimerKeepalive, &QTimer::timeout, this , &CTcpConnection::OnTimerKeepalive );
6555 TimerKeepalive.start ( TCP_KEEPALIVE_INTERVAL_MS );
6656 }
6757}
58+ #endif
59+
60+ // TCP connection used by server
61+ CTcpConnection::CTcpConnection ( QTcpSocket* pTcpSocket, const CHostAddress& tcpAddress, CServer* pServer ) :
62+ pTcpSocket ( pTcpSocket ),
63+ tcpAddress ( tcpAddress ),
64+ pServer ( pServer ),
65+ pChannel ( nullptr ),
66+ bIsSession ( false )
67+ {
68+ vecbyRecBuf.Init ( MAX_SIZE_BYTES_NETW_BUF );
69+ iPos = 0 ;
70+ iPayloadRemain = 0 ;
71+
72+ connect ( pTcpSocket, &QTcpSocket::disconnected, this , &CTcpConnection::OnDisconnected );
73+ connect ( pTcpSocket, &QTcpSocket::readyRead, this , &CTcpConnection::OnReadyRead );
74+
75+ connect ( this , &CTcpConnection::ProtocolCLMessageReceived, pServer, &CServer::OnProtocolCLMessageReceived );
76+ }
6877
6978void CTcpConnection::OnDisconnected ()
7079{
0 commit comments