mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Added block read from socket
This commit is contained in:
@@ -147,3 +147,46 @@ bool RiaSocketTools::writeBlockData(RiaSocketServer* server, QTcpSocket* socket,
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaSocketTools::readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringList& errorMessages)
|
||||
{
|
||||
quint64 bytesRead = 0;
|
||||
int blockCount = 0;
|
||||
|
||||
quint64 maxBlockSize = RiaApplication::instance()->preferences()->blockSize();
|
||||
|
||||
while (bytesRead < bytesToRead)
|
||||
{
|
||||
if (socket.bytesAvailable())
|
||||
{
|
||||
quint64 byteCountToRead = qMin(bytesToRead - bytesRead, maxBlockSize);
|
||||
|
||||
qint64 actuallyBytesRead = socket.read(data + bytesRead, byteCountToRead);
|
||||
if (actuallyBytesRead < 0)
|
||||
{
|
||||
errorMessages.push_back("Error detected when writing data, error string from socket");
|
||||
errorMessages.push_back(socket.errorString());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bytesRead += actuallyBytesRead;
|
||||
blockCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!socket.waitForReadyRead())
|
||||
{
|
||||
errorMessages.push_back("Waited for data for %1 milli seconds.");
|
||||
errorMessages.push_back(socket.errorString());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user