Added block read from socket

This commit is contained in:
Magne Sjaastad 2014-04-02 08:55:26 +02:00
parent c1419e53e8
commit 364ea1f937
3 changed files with 61 additions and 0 deletions

View File

@ -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;
}

View File

@ -28,4 +28,5 @@ public:
static void getCaseInfoFromCase(RimCase* rimCase, qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId);
static bool writeBlockData(RiaSocketServer* server, QTcpSocket* socket, const char* data, quint64 bytesToWrite);
static bool readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringList& errorMessages);
};

View File

@ -1,7 +1,10 @@
#include <QtNetwork>
#include <QStringList>
#include <octave/oct.h>
#include "riSettings.h"
#include "../ApplicationCode/SocketInterface/RiaSocketTools.h"
void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 port, const qint32& caseId, const quint32& gridIndex)
@ -67,7 +70,20 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16
dv(4) = 3;
cellCornerValues.resize(dv);
double* internalMatrixData = cellCornerValues.fortran_vec();
QStringList errorMessages;
if (!RiaSocketTools::readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages))
{
for (int i = 0; i < errorMessages.size(); i++)
{
error(errorMessages[i].toLatin1().data());
}
OCTAVE_QUIT;
}
/*
while (socket.bytesAvailable() < (qint64)(byteCount))
{
if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs))
@ -97,6 +113,7 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16
}
#endif
*/
return;
}