MCPcopy Create free account
hub / github.com/dannagle/PacketSender / persistentConnectionLoop

Method persistentConnectionLoop

src/tcpthread.cpp:219–386  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217
218
219void TCPThread::persistentConnectionLoop()
220{
221 QDEBUG() << "Entering the forever loop";
222 int ipMode = 4;
223 QHostAddress theAddress(sendPacket.toIP);
224 if (QAbstractSocket::IPv6Protocol == theAddress.protocol()) {
225 ipMode = 6;
226 }
227
228 int count = 0;
229 while (clientConnection->state() == QAbstractSocket::ConnectedState && !closeRequest) {
230 insidePersistent = true;
231
232
233 if (sendPacket.hexString.isEmpty() && sendPacket.persistent && (clientConnection->bytesAvailable() == 0)) {
234 count++;
235 if (count % 10 == 0) {
236 //QDEBUG() << "Loop and wait." << count++ << clientConnection->state();
237 emit connectStatus("Connected and idle.");
238 }
239 clientConnection->waitForReadyRead(200);
240 continue;
241 }
242
243 if (clientConnection->state() != QAbstractSocket::ConnectedState && sendPacket.persistent) {
244 QDEBUG() << "Connection broken.";
245 emit connectStatus("Connection broken");
246
247 break;
248 }
249
250 if (sendPacket.receiveBeforeSend) {
251 QDEBUG() << "Wait for data before sending...";
252 emit connectStatus("Waiting for data");
253 clientConnection->waitForReadyRead(500);
254
255 Packet tcpRCVPacket;
256 tcpRCVPacket.hexString = Packet::byteArrayToHex(clientConnection->readAll());
257 if (!tcpRCVPacket.hexString.trimmed().isEmpty()) {
258 QDEBUG() << "Received: " << tcpRCVPacket.hexString;
259 emit connectStatus("Received " + QString::number((tcpRCVPacket.hexString.size() / 3) + 1));
260
261 tcpRCVPacket.timestamp = QDateTime::currentDateTime();
262 tcpRCVPacket.name = QDateTime::currentDateTime().toString(DATETIMEFORMAT);
263 tcpRCVPacket.tcpOrUdp = "TCP";
264 if (clientConnection->isEncrypted()) {
265 tcpRCVPacket.tcpOrUdp = "SSL";
266 }
267
268 if (ipMode < 6) {
269 tcpRCVPacket.fromIP = Packet::removeIPv6Mapping(clientConnection->peerAddress());
270 } else {
271 tcpRCVPacket.fromIP = (clientConnection->peerAddress()).toString();
272 }
273
274
275 QDEBUGVAR(tcpRCVPacket.fromIP);
276 tcpRCVPacket.toIP = "You";

Callers

nothing calls this directly

Calls 8

sizeMethod · 0.80
toStringMethod · 0.80
isEncryptedMethod · 0.80
getByteArrayMethod · 0.80
asciiStringMethod · 0.80
appendMethod · 0.80
closeMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected