From 0fc0b62f7d8d6e8609f59d40a51188f24dd3be21 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 3 Apr 2014 11:09:42 +0200 Subject: [PATCH] Updated use of buffer read --- OctavePlugin/riGetActiveCellInfo.cpp | 48 +++++++--------------------- 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/OctavePlugin/riGetActiveCellInfo.cpp b/OctavePlugin/riGetActiveCellInfo.cpp index 824134e0f7..a7213a3697 100644 --- a/OctavePlugin/riGetActiveCellInfo.cpp +++ b/OctavePlugin/riGetActiveCellInfo.cpp @@ -1,7 +1,10 @@ #include +#include + #include #include "riSettings.h" +#include "riSocketTools.h" void getActiveCellInfo(int32NDArray& activeCellInfo, const QString &hostName, quint16 port, const qint64& caseId, const QString& porosityModel) @@ -43,59 +46,32 @@ void getActiveCellInfo(int32NDArray& activeCellInfo, const QString &hostName, qu // Read timestep count and blocksize quint64 columnCount; - quint64 byteCount; + quint64 byteCountForOneTimestep; size_t activeCellCount; socketStream >> columnCount; - socketStream >> byteCount; + socketStream >> byteCountForOneTimestep; - activeCellCount = byteCount / sizeof(qint32); + activeCellCount = byteCountForOneTimestep / sizeof(qint32); dim_vector dv (2, 1); dv(0) = activeCellCount; dv(1) = columnCount; activeCellInfo.resize(dv); - if (!(byteCount && columnCount)) + if (!(byteCountForOneTimestep && columnCount)) { error ("Could not find the requested data in ResInsight"); return; } - // Wait for available data for each column, then read data for each column - for (size_t tIdx = 0; tIdx < columnCount; ++tIdx) + qint32* internalMatrixData = (qint32*)activeCellInfo.fortran_vec()->mex_get_data(); + QStringList errorMessages; + if (!readBlockData(socket, (char*)(internalMatrixData), columnCount * byteCountForOneTimestep, errorMessages)) { - while (socket.bytesAvailable() < (int)byteCount) + for (int i = 0; i < errorMessages.size(); i++) { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) - { - QString errorMsg = QString("Waiting for column number: %1 of %2: %3").arg(tIdx).arg(columnCount).arg(socket.errorString()); - - error(errorMsg.toLatin1().data()); - octave_stdout << "Active cells: " << activeCellCount << ", Columns: " << columnCount << std::endl; - return ; - } - OCTAVE_QUIT; - } - - qint64 bytesRead = 0; - qint32* internalMatrixData = (qint32*)activeCellInfo.fortran_vec()->mex_get_data(); - -#if 1 // Use raw data transfer. Faster. - bytesRead = socket.read((char*)(internalMatrixData + tIdx * activeCellCount), byteCount); -#else - for (size_t cIdx = 0; cIdx < activeCellCount; ++cIdx) - { - socketStream >> internalMatrixData[tIdx * activeCellCount + cIdx]; - - if (socketStream.status() == QDataStream::Ok) bytesRead += sizeof(int); - } -#endif - - if ((int)byteCount != bytesRead) - { - error("Could not read binary double data properly from socket"); - octave_stdout << "Active cells: " << activeCellCount << ", Columns: " << columnCount << std::endl; + error(errorMessages[i].toLatin1().data()); } OCTAVE_QUIT;