mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Moved Octave socket reading into riSocketTools
This commit is contained in:
parent
364ea1f937
commit
ed216f6de3
@ -4,7 +4,9 @@
|
|||||||
#include <octave/oct.h>
|
#include <octave/oct.h>
|
||||||
|
|
||||||
#include "riSettings.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)
|
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();
|
double* internalMatrixData = cellCornerValues.fortran_vec();
|
||||||
QStringList errorMessages;
|
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++)
|
for (int i = 0; i < errorMessages.size(); i++)
|
||||||
{
|
{
|
||||||
@ -82,6 +84,8 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16
|
|||||||
OCTAVE_QUIT;
|
OCTAVE_QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
octave_stdout << "Bytes count processed : " << byteCount << std::endl;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
while (socket.bytesAvailable() < (qint64)(byteCount))
|
while (socket.bytesAvailable() < (qint64)(byteCount))
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <octave/oct-map.h>
|
#include <octave/oct-map.h>
|
||||||
|
|
||||||
#include "riSettings.h"
|
#include "riSettings.h"
|
||||||
|
#include "riSocketTools.h"
|
||||||
|
|
||||||
void getCurrentCase(qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId, const QString &hostName, quint16 port)
|
void getCurrentCase(qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId, const QString &hostName, quint16 port)
|
||||||
{
|
{
|
||||||
|
46
OctavePlugin/riSocketTools.h
Normal file
46
OctavePlugin/riSocketTools.h
Normal 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user