Moved Octave socket reading into riSocketTools

This commit is contained in:
Magne Sjaastad 2014-04-02 09:52:02 +02:00
parent 492d86c39f
commit 1fd4c56a46
3 changed files with 53 additions and 2 deletions

View File

@ -4,7 +4,9 @@
#include <octave/oct.h>
#include "riSettings.h"
#include "../ApplicationCode/SocketInterface/RiaSocketTools.h"
#include "riSocketTools.h"
void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 port, const qint32& caseId, const quint32& gridIndex)
@ -72,7 +74,7 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16
double* internalMatrixData = cellCornerValues.fortran_vec();
QStringList errorMessages;
if (!RiaSocketTools::readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages))
if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages))
{
for (int i = 0; i < errorMessages.size(); i++)
{
@ -82,6 +84,8 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16
OCTAVE_QUIT;
}
octave_stdout << "Bytes count processed : " << byteCount << std::endl;
/*
while (socket.bytesAvailable() < (qint64)(byteCount))

View File

@ -3,6 +3,7 @@
#include <octave/oct-map.h>
#include "riSettings.h"
#include "riSocketTools.h"
void getCurrentCase(qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId, const QString &hostName, quint16 port)
{

View File

@ -0,0 +1,46 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringList& errorMessages)
{
quint64 bytesRead = 0;
int blockCount = 0;
quint64 maxBlockSize = 100000;
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;
octave_stdout << "Bytes read " << bytesRead << " of total " << bytesToRead << std::endl;
blockCount++;
}
else
{
if (!socket.waitForReadyRead())
{
errorMessages.push_back("Waited for data for %1 milli seconds.");
errorMessages.push_back(socket.errorString());
return false;
}
}
}
return true;
}