|
28 | 28 | #include "server.h" |
29 | 29 | #include "channel.h" |
30 | 30 |
|
31 | | -CTcpConnection::CTcpConnection ( QTcpSocket* pTcpSocket, const CHostAddress& tcpAddress, CServer* pServer ) : |
| 31 | +CTcpConnection::CTcpConnection ( QTcpSocket* pTcpSocket, const CHostAddress& tcpAddress, CServer* pServer, CChannel* pChannel ) : |
32 | 32 | pTcpSocket ( pTcpSocket ), |
33 | 33 | tcpAddress ( tcpAddress ), |
34 | | - pServer ( pServer ) |
| 34 | + pServer ( pServer ), |
| 35 | + pChannel ( pChannel ) |
35 | 36 | { |
36 | 37 | vecbyRecBuf.Init ( MAX_SIZE_BYTES_NETW_BUF ); |
37 | 38 | iPos = 0; |
38 | 39 | iPayloadRemain = 0; |
39 | 40 |
|
40 | 41 | connect ( pTcpSocket, &QTcpSocket::disconnected, this, &CTcpConnection::OnDisconnected ); |
41 | 42 | connect ( pTcpSocket, &QTcpSocket::readyRead, this, &CTcpConnection::OnReadyRead ); |
| 43 | + |
42 | 44 | if ( pServer ) |
43 | 45 | { |
44 | 46 | connect ( this, &CTcpConnection::ProtocolCLMessageReceived, pServer, &CServer::OnProtocolCLMessageReceived ); |
45 | 47 | } |
| 48 | + |
| 49 | + if ( pChannel ) |
| 50 | + { |
| 51 | + connect ( this, &CTcpConnection::ProtocolCLMessageReceived, pChannel, &CChannel::OnProtocolCLMessageReceived ); |
| 52 | + } |
46 | 53 | } |
47 | 54 |
|
48 | 55 | void CTcpConnection::OnDisconnected() |
49 | 56 | { |
50 | | - qDebug() << "- Jamulus-TCP: disconnected from:" << tcpAddress.InetAddr.toString(); |
| 57 | + qDebug() << "- Jamulus-TCP: disconnected from:" << tcpAddress.toString(); |
51 | 58 | pTcpSocket->deleteLater(); |
52 | | - delete this; |
| 59 | + deleteLater(); // delete this object in the next event loop |
53 | 60 | } |
54 | 61 |
|
55 | 62 | void CTcpConnection::OnReadyRead() |
@@ -124,7 +131,7 @@ void CTcpConnection::OnReadyRead() |
124 | 131 | //### TODO: END ###// |
125 | 132 |
|
126 | 133 | // disconnect if we are a client |
127 | | - if ( !pServer ) |
| 134 | + if ( pChannel ) |
128 | 135 | { |
129 | 136 | pTcpSocket->disconnectFromHost(); |
130 | 137 | } |
|
0 commit comments