[SOLVED] Qt Example - QNetwork
-
wrote on 13 Mar 2014, 19:20 last edited by
Hello, I am playing around with "Qt example":http://qt-project.org/doc/qt-5.0/qtnetwork/torrent-peerwireclient-cpp.html and there is one thing I don't really understand...
How are readFromSocket and readData emited? I did not find it being called anywhere... I am trying to understand how to read incoming data from socket...
@qint64 PeerWireClient::readFromSocket(qint64 bytes)
{
char buffer[1024];
qint64 totalRead = 0;
do {
qint64 bytesRead = socket.read(buffer, qMin<qint64>(sizeof(buffer), bytes - totalRead));
if (bytesRead <= 0)
break;
qint64 oldSize = incomingBuffer.size();
incomingBuffer.resize(oldSize + bytesRead);
memcpy(incomingBuffer.data() + oldSize, buffer, bytesRead);totalRead += bytesRead; } while (totalRead < bytes); if (totalRead > 0) { downloadSpeedData[0] += totalRead; emit bytesReceived(totalRead); processIncomingData(); } return totalRead;
}@
@qint64 PeerWireClient::readData(char *data, qint64 size)
{
int n = qMin<int>(size, incomingBuffer.size());
memcpy(data, incomingBuffer.constData(), n);
incomingBuffer.remove(0, n);
return n;
}@ -
wrote on 13 Mar 2014, 20:26 last edited by
These are not signals and they are not emitted.
readFromSocket is called by RateController::transfer() which is called by a timer
readData, "according the the doc":http://qt-project.org/doc/qt-5/qiodevice.html#readData is called by QIODevice -
wrote on 13 Mar 2014, 21:39 last edited by
ohh... I did not see there are also other files... Thanks...
1/3