From b5e4d7d8fb01e13e7426b318a8e4e7d611354ffa Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 5 Jun 2019 15:40:28 +0200 Subject: [PATCH] fixed reading and double print in client --- slsSupportLib/src/ClientSocket.cpp | 7 ++----- slsSupportLib/src/DataSocket.cpp | 5 ++++- slsSupportLib/src/ServerInterface2.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/slsSupportLib/src/ClientSocket.cpp b/slsSupportLib/src/ClientSocket.cpp index 7e531c93c..57fbb5821 100755 --- a/slsSupportLib/src/ClientSocket.cpp +++ b/slsSupportLib/src/ClientSocket.cpp @@ -75,15 +75,12 @@ void ClientSocket::readReply(int &ret, void *retval, size_t retval_size) { char mess[MAX_STR_LENGTH]{}; // get error message read(mess, sizeof(mess)); - FILE_LOG(logERROR) << socketType << " returned error: " << mess; - std::cout << "\n"; // needed to reset the color. - // Do we need to know hostname here? // In that case save it??? if (socketType == "Receiver") { - throw ReceiverError(mess); + throw ReceiverError("Receiver returned: " + std::string(mess)); } else if (socketType == "Detector") { - throw DetectorError(mess); + throw DetectorError("Detector returned: " + std::string(mess)); } else { throw GuiError(mess); } diff --git a/slsSupportLib/src/DataSocket.cpp b/slsSupportLib/src/DataSocket.cpp index ce28d8b2c..1ffc31076 100755 --- a/slsSupportLib/src/DataSocket.cpp +++ b/slsSupportLib/src/DataSocket.cpp @@ -43,9 +43,12 @@ DataSocket &DataSocket::operator=(DataSocket &&move) noexcept { int DataSocket::receiveData(void *buffer, size_t size) { size_t dataRead = 0; while (dataRead < size) { - dataRead += + auto thisRead = ::read(getSocketId(), reinterpret_cast(buffer) + dataRead, size - dataRead); + if (thisRead <= 0) + break; + dataRead += thisRead; } return dataRead; } diff --git a/slsSupportLib/src/ServerInterface2.cpp b/slsSupportLib/src/ServerInterface2.cpp index 1d970ecf8..6dd5a377f 100644 --- a/slsSupportLib/src/ServerInterface2.cpp +++ b/slsSupportLib/src/ServerInterface2.cpp @@ -23,7 +23,7 @@ int ServerInterface2::sendResult(int ret, void *retval, int retvalSize, int ServerInterface2::receiveArg(void *arg, int sizeofArg) { assert(sizeofArg > 0); - int bytes_read = read(arg, sizeofArg); + int bytes_read = receiveData(arg, sizeofArg); if (bytes_read == sizeofArg) { return defs::OK; } else {