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:
Erik Fröjdh
2019-06-05 15:25:18 +02:00
committed by Dhanya Thattil
parent a6144f658e
commit 1db7521cfa
14 changed files with 1048 additions and 1752 deletions

View File

@ -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());
}
}