mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 13:27:14 +02:00
exceptions TCP (#31)
* WIP * first test * format * test frames * also 0: * WIP * WIP * first test * format * test frames * also 0: * test and less local * pass ret by value * level * WIP * WIP * cleaning up interface * removed ref * another * updated api version * cleanup * cleanup * WIP * fixes * fixed tests
This commit is contained in:

committed by
Dhanya Thattil

parent
a6144f658e
commit
1db7521cfa
@ -1,37 +1,37 @@
|
||||
#include "ServerInterface2.h"
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
namespace sls {
|
||||
|
||||
int ServerInterface2::sendResult(bool update, int ret, void *retval,
|
||||
int retvalSize, char *mess) {
|
||||
int ServerInterface2::sendResult(int ret, void *retval, int retvalSize,
|
||||
char *mess) {
|
||||
|
||||
// if (update && ret == defs::OK && server_->DifferentClients()) {
|
||||
// ret = defs::FORCE_UPDATE;
|
||||
// }
|
||||
sendData(&ret, sizeof(ret));
|
||||
write(&ret, sizeof(ret));
|
||||
if (ret == defs::FAIL) {
|
||||
// send error message
|
||||
if (mess)
|
||||
sendData(mess, MAX_STR_LENGTH);
|
||||
// debugging feature. should not happen.
|
||||
else
|
||||
if (mess != nullptr) {
|
||||
write(mess, MAX_STR_LENGTH);
|
||||
} else {
|
||||
FILE_LOG(logERROR) << "No error message provided for this "
|
||||
"failure. Will mess up TCP\n";
|
||||
}
|
||||
} else {
|
||||
write(retval, retvalSize);
|
||||
}
|
||||
sendData(retval, retvalSize);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ServerInterface2::receiveArg(int &ret, char *mess, void *arg,
|
||||
int sizeofArg) {
|
||||
int ServerInterface2::receiveArg(void *arg, int sizeofArg) {
|
||||
assert(sizeofArg > 0);
|
||||
int bytes_read = read(arg, sizeofArg);
|
||||
if (bytes_read == sizeofArg) {
|
||||
return defs::OK;
|
||||
} else {
|
||||
FILE_LOG(logERROR) << "Read: " << bytes_read << " instead of "
|
||||
<< sizeofArg;
|
||||
return defs::FAIL;
|
||||
std::ostringstream ss;
|
||||
ss << "TCP socket error read " << bytes_read << " bytes instead of "
|
||||
<< sizeofArg << " bytes";
|
||||
|
||||
throw sls::SocketError(ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user