Merge branch 'developer' of github.com:slsdetectorgroup/slsDetectorPackage into developer

This commit is contained in:
Gemma Tinti 2019-06-06 17:53:52 +02:00
commit 0c6304bdf8
11 changed files with 253 additions and 250 deletions

View File

@ -422,49 +422,49 @@ int slsDetector::sendModule(sls_detector_module *myMod,
FILE_LOG(level) << "Sending Module";
int ts = 0;
int n = 0;
n = client.sendData(&(myMod->serialnumber), sizeof(myMod->serialnumber));
n = client.Send(&(myMod->serialnumber), sizeof(myMod->serialnumber));
ts += n;
FILE_LOG(level) << "Serial number sent. " << n
<< " bytes. serialno: " << myMod->serialnumber;
n = client.sendData(&(myMod->nchan), sizeof(myMod->nchan));
n = client.Send(&(myMod->nchan), sizeof(myMod->nchan));
ts += n;
FILE_LOG(level) << "nchan sent. " << n
<< " bytes. serialno: " << myMod->nchan;
n = client.sendData(&(myMod->nchip), sizeof(myMod->nchip));
n = client.Send(&(myMod->nchip), sizeof(myMod->nchip));
ts += n;
FILE_LOG(level) << "nchip sent. " << n
<< " bytes. serialno: " << myMod->nchip;
n = client.sendData(&(myMod->ndac), sizeof(myMod->ndac));
n = client.Send(&(myMod->ndac), sizeof(myMod->ndac));
ts += n;
FILE_LOG(level) << "ndac sent. " << n
<< " bytes. serialno: " << myMod->ndac;
n = client.sendData(&(myMod->reg), sizeof(myMod->reg));
n = client.Send(&(myMod->reg), sizeof(myMod->reg));
ts += n;
FILE_LOG(level) << "reg sent. " << n << " bytes. serialno: " << myMod->reg;
n = client.sendData(&(myMod->iodelay), sizeof(myMod->iodelay));
n = client.Send(&(myMod->iodelay), sizeof(myMod->iodelay));
ts += n;
FILE_LOG(level) << "iodelay sent. " << n
<< " bytes. serialno: " << myMod->iodelay;
n = client.sendData(&(myMod->tau), sizeof(myMod->tau));
n = client.Send(&(myMod->tau), sizeof(myMod->tau));
ts += n;
FILE_LOG(level) << "tau sent. " << n << " bytes. serialno: " << myMod->tau;
n = client.sendData(&(myMod->eV), sizeof(myMod->eV));
n = client.Send(&(myMod->eV), sizeof(myMod->eV));
ts += n;
FILE_LOG(level) << "ev sent. " << n << " bytes. serialno: " << myMod->eV;
n = client.sendData(myMod->dacs, sizeof(int) * (myMod->ndac));
n = client.Send(myMod->dacs, sizeof(int) * (myMod->ndac));
ts += n;
FILE_LOG(level) << "dacs sent. " << n << " bytes";
if (shm()->myDetectorType == EIGER) {
n = client.sendData(myMod->chanregs, sizeof(int) * (myMod->nchan));
n = client.Send(myMod->chanregs, sizeof(int) * (myMod->nchan));
ts += n;
FILE_LOG(level) << "channels sent. " << n << " bytes";
}
@ -475,19 +475,19 @@ int slsDetector::receiveModule(sls_detector_module *myMod,
sls::ClientSocket &client) {
int ts = 0;
ts +=
client.receiveData(&(myMod->serialnumber), sizeof(myMod->serialnumber));
ts += client.receiveData(&(myMod->nchan), sizeof(myMod->nchan));
ts += client.receiveData(&(myMod->nchip), sizeof(myMod->nchip));
ts += client.receiveData(&(myMod->ndac), sizeof(myMod->ndac));
ts += client.receiveData(&(myMod->reg), sizeof(myMod->reg));
ts += client.receiveData(&(myMod->iodelay), sizeof(myMod->iodelay));
ts += client.receiveData(&(myMod->tau), sizeof(myMod->tau));
ts += client.receiveData(&(myMod->eV), sizeof(myMod->eV));
client.Receive(&(myMod->serialnumber), sizeof(myMod->serialnumber));
ts += client.Receive(&(myMod->nchan), sizeof(myMod->nchan));
ts += client.Receive(&(myMod->nchip), sizeof(myMod->nchip));
ts += client.Receive(&(myMod->ndac), sizeof(myMod->ndac));
ts += client.Receive(&(myMod->reg), sizeof(myMod->reg));
ts += client.Receive(&(myMod->iodelay), sizeof(myMod->iodelay));
ts += client.Receive(&(myMod->tau), sizeof(myMod->tau));
ts += client.Receive(&(myMod->eV), sizeof(myMod->eV));
ts += client.receiveData(myMod->dacs, sizeof(int) * (myMod->ndac));
ts += client.Receive(myMod->dacs, sizeof(int) * (myMod->ndac));
FILE_LOG(logDEBUG1) << "received dacs of size " << ts;
if (shm()->myDetectorType == EIGER) {
ts += client.receiveData(myMod->chanregs, sizeof(int) * (myMod->nchan));
ts += client.Receive(myMod->chanregs, sizeof(int) * (myMod->nchan));
FILE_LOG(logDEBUG1)
<< "nchans= " << shm()->nChans << " nchips= " << shm()->nChips
<< "mod - nchans= " << myMod->nchan << " nchips= " << myMod->nchip
@ -528,9 +528,9 @@ slsDetector::getTypeFromDetector(const std::string &hostname, int cport) {
detectorType retval = GENERIC;
FILE_LOG(logDEBUG1) << "Getting detector type ";
sls::ClientSocket cs("Detector", hostname, cport);
cs.sendData(reinterpret_cast<char *>(&fnum), sizeof(fnum));
cs.receiveData(reinterpret_cast<char *>(&ret), sizeof(ret));
cs.receiveData(reinterpret_cast<char *>(&retval), sizeof(retval));
cs.Send(reinterpret_cast<char *>(&fnum), sizeof(fnum));
cs.Receive(reinterpret_cast<char *>(&ret), sizeof(ret));
cs.Receive(reinterpret_cast<char *>(&retval), sizeof(retval));
FILE_LOG(logDEBUG1) << "Detector type is " << retval;
return retval;
}
@ -788,91 +788,91 @@ int slsDetector::updateDetectorNoWait(sls::ClientSocket &client) {
int n = 0, i32 = 0;
int64_t i64 = 0;
char lastClientIP[INET_ADDRSTRLEN] = {0};
n += client.receiveData(lastClientIP, sizeof(lastClientIP));
n += client.Receive(lastClientIP, sizeof(lastClientIP));
FILE_LOG(logDEBUG1) << "Updating detector last modified by "
<< lastClientIP;
// dr
n += client.receiveData(&i32, sizeof(i32));
n += client.Receive(&i32, sizeof(i32));
shm()->dynamicRange = i32;
// databytes
n += client.receiveData(&i32, sizeof(i32));
n += client.Receive(&i32, sizeof(i32));
shm()->dataBytes = i32;
// settings
if ((shm()->myDetectorType != CHIPTESTBOARD) &&
(shm()->myDetectorType != MOENCH)) {
n += client.receiveData(&i32, sizeof(i32));
n += client.Receive(&i32, sizeof(i32));
shm()->currentSettings = static_cast<detectorSettings>(i32);
}
// threshold
if (shm()->myDetectorType == EIGER) {
n += client.receiveData(&i32, sizeof(i32));
n += client.Receive(&i32, sizeof(i32));
shm()->currentThresholdEV = i32;
}
// frame number
n += client.receiveData(&i64, sizeof(i64));
n += client.Receive(&i64, sizeof(i64));
shm()->timerValue[FRAME_NUMBER] = i64;
// exptime
n += client.receiveData(&i64, sizeof(i64));
n += client.Receive(&i64, sizeof(i64));
shm()->timerValue[ACQUISITION_TIME] = i64;
// subexptime, subdeadtime
if (shm()->myDetectorType == EIGER) {
n += client.receiveData(&i64, sizeof(i64));
n += client.Receive(&i64, sizeof(i64));
shm()->timerValue[SUBFRAME_ACQUISITION_TIME] = i64;
n += client.receiveData(&i64, sizeof(i64));
n += client.Receive(&i64, sizeof(i64));
shm()->timerValue[SUBFRAME_DEADTIME] = i64;
}
// period
n += client.receiveData(&i64, sizeof(i64));
n += client.Receive(&i64, sizeof(i64));
shm()->timerValue[FRAME_PERIOD] = i64;
// delay
if (shm()->myDetectorType != EIGER) {
n += client.receiveData(&i64, sizeof(i64));
n += client.Receive(&i64, sizeof(i64));
shm()->timerValue[DELAY_AFTER_TRIGGER] = i64;
}
if (shm()->myDetectorType == JUNGFRAU) {
// storage cell
n += client.receiveData(&i64, sizeof(i64));
n += client.Receive(&i64, sizeof(i64));
shm()->timerValue[STORAGE_CELL_NUMBER] = i64;
// storage cell delay
n += client.receiveData(&i64, sizeof(i64));
n += client.Receive(&i64, sizeof(i64));
shm()->timerValue[STORAGE_CELL_DELAY] = i64;
}
// cycles
n += client.receiveData(&i64, sizeof(i64));
n += client.Receive(&i64, sizeof(i64));
shm()->timerValue[CYCLES_NUMBER] = i64;
// readout flags
if (shm()->myDetectorType == EIGER ||
shm()->myDetectorType == CHIPTESTBOARD) {
n += client.receiveData(&i32, sizeof(i32));
n += client.Receive(&i32, sizeof(i32));
shm()->roFlags = static_cast<readOutFlags>(i32);
}
// roi
if (shm()->myDetectorType == GOTTHARD) {
n += client.receiveData(&i32, sizeof(i32));
n += client.Receive(&i32, sizeof(i32));
shm()->nROI = i32;
for (int i = 0; i < shm()->nROI; ++i) {
n += client.receiveData(&i32, sizeof(i32));
n += client.Receive(&i32, sizeof(i32));
shm()->roiLimits[i].xmin = i32;
n += client.receiveData(&i32, sizeof(i32));
n += client.Receive(&i32, sizeof(i32));
shm()->roiLimits[i].xmax = i32;
n += client.receiveData(&i32, sizeof(i32));
n += client.Receive(&i32, sizeof(i32));
shm()->roiLimits[i].ymin = i32;
n += client.receiveData(&i32, sizeof(i32));
n += client.Receive(&i32, sizeof(i32));
shm()->roiLimits[i].xmax = i32;
}
}
@ -880,20 +880,20 @@ int slsDetector::updateDetectorNoWait(sls::ClientSocket &client) {
if (shm()->myDetectorType == CHIPTESTBOARD ||
shm()->myDetectorType == MOENCH) {
// analog samples
n += client.receiveData(&i64, sizeof(i64));
n += client.Receive(&i64, sizeof(i64));
if (i64 >= 0) {
shm()->timerValue[ANALOG_SAMPLES] = i64;
}
// digital samples
n += client.receiveData(&i64, sizeof(i64));
n += client.Receive(&i64, sizeof(i64));
if (i64 >= 0) {
shm()->timerValue[DIGITAL_SAMPLES] = i64;
}
// adcmask
uint32_t u32 = 0;
n += client.receiveData(&u32, sizeof(u32));
n += client.Receive(&u32, sizeof(u32));
shm()->adcEnableMask = u32;
if (shm()->myDetectorType == MOENCH)
setAdditionalJsonParameter("adcmask", std::to_string(u32));
@ -2459,13 +2459,13 @@ int slsDetector::sendImageToDetector(imageType index, int16_t imageVals[]) {
if (shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.sendData(&fnum, sizeof(fnum));
client.sendData(args, sizeof(args));
client.sendData(imageVals, nChan * sizeof(int16_t));
client.receiveData(&ret, sizeof(ret));
client.Send(&fnum, sizeof(fnum));
client.Send(args, sizeof(args));
client.Send(imageVals, nChan * sizeof(int16_t));
client.Receive(&ret, sizeof(ret));
if (ret == FAIL) {
char mess[MAX_STR_LENGTH]{};
client.receiveData(mess, MAX_STR_LENGTH);
client.Receive(mess, MAX_STR_LENGTH);
throw DetectorError("Detector " + std::to_string(detId) +
" returned error: " + std::string(mess));
}
@ -2554,32 +2554,32 @@ int slsDetector::sendROI(int n, ROI roiLimits[]) {
if (shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.sendData(&fnum, sizeof(fnum));
client.sendData(&narg, sizeof(narg));
client.Send(&fnum, sizeof(fnum));
client.Send(&narg, sizeof(narg));
if (narg != -1) {
for (int i = 0; i < narg; ++i) {
client.sendData(&arg[i].xmin, sizeof(int));
client.sendData(&arg[i].xmax, sizeof(int));
client.sendData(&arg[i].ymin, sizeof(int));
client.sendData(&arg[i].ymax, sizeof(int));
client.Send(&arg[i].xmin, sizeof(int));
client.Send(&arg[i].xmax, sizeof(int));
client.Send(&arg[i].ymin, sizeof(int));
client.Send(&arg[i].ymax, sizeof(int));
}
}
client.receiveData(&ret, sizeof(ret));
client.Receive(&ret, sizeof(ret));
// handle ret
if (ret == FAIL) {
char mess[MAX_STR_LENGTH]{};
client.receiveData(mess, MAX_STR_LENGTH);
client.Receive(mess, MAX_STR_LENGTH);
throw RuntimeError("Detector " + std::to_string(detId) +
" returned error: " + std::string(mess));
} else {
client.receiveData(&nretval, sizeof(nretval));
client.Receive(&nretval, sizeof(nretval));
int nrec = 0;
for (int i = 0; i < nretval; ++i) {
nrec += client.receiveData(&retval[i].xmin, sizeof(int));
nrec += client.receiveData(&retval[i].xmax, sizeof(int));
nrec += client.receiveData(&retval[i].ymin, sizeof(int));
nrec += client.receiveData(&retval[i].ymax, sizeof(int));
nrec += client.Receive(&retval[i].xmin, sizeof(int));
nrec += client.Receive(&retval[i].xmax, sizeof(int));
nrec += client.Receive(&retval[i].ymin, sizeof(int));
nrec += client.Receive(&retval[i].ymax, sizeof(int));
}
shm()->nROI = nretval;
FILE_LOG(logDEBUG1) << "nRoi: " << nretval;
@ -2618,21 +2618,21 @@ int slsDetector::sendROI(int n, ROI roiLimits[]) {
FILE_LOG(logDEBUG1) << "Sending ROI to receiver: " << shm()->nROI;
auto receiver = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
receiver.sendData(&fnum, sizeof(fnum));
receiver.sendData(&narg, sizeof(narg));
receiver.Send(&fnum, sizeof(fnum));
receiver.Send(&narg, sizeof(narg));
if (narg != -1) {
for (int i = 0; i < narg; ++i) {
receiver.sendData(&arg[i].xmin, sizeof(int));
receiver.sendData(&arg[i].xmax, sizeof(int));
receiver.sendData(&arg[i].ymin, sizeof(int));
receiver.sendData(&arg[i].ymax, sizeof(int));
receiver.Send(&arg[i].xmin, sizeof(int));
receiver.Send(&arg[i].xmax, sizeof(int));
receiver.Send(&arg[i].ymin, sizeof(int));
receiver.Send(&arg[i].ymax, sizeof(int));
}
}
receiver.receiveData(&ret, sizeof(ret));
receiver.Receive(&ret, sizeof(ret));
if (ret == FAIL) {
char mess[MAX_STR_LENGTH]{};
receiver.receiveData(mess, MAX_STR_LENGTH);
receiver.Receive(mess, MAX_STR_LENGTH);
throw ReceiverError("Receiver " + std::to_string(detId) +
" returned error: " + std::string(mess));
}
@ -2979,12 +2979,12 @@ int slsDetector::programFPGA(std::vector<char> buffer) {
if (shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.sendData(&fnum, sizeof(fnum));
client.sendData(&filesize, sizeof(filesize));
client.receiveData(&ret, sizeof(ret));
client.Send(&fnum, sizeof(fnum));
client.Send(&filesize, sizeof(filesize));
client.Receive(&ret, sizeof(ret));
// error in detector at opening file pointer to flash
if (ret == FAIL) {
client.receiveData(mess, sizeof(mess));
client.Receive(mess, sizeof(mess));
std::ostringstream os;
os << "Detector " << detId << " (" << shm()->hostname << ")"
<< " returned error: " << mess;
@ -3029,8 +3029,8 @@ int slsDetector::programFPGA(std::vector<char> buffer) {
FILE_LOG(logDEBUG1) << "unitprogramsize:" << unitprogramsize
<< "\t filesize:" << filesize;
client.sendData(&buffer[currentPointer], unitprogramsize);
client.receiveData(&ret, sizeof(ret));
client.Send(&buffer[currentPointer], unitprogramsize);
client.Receive(&ret, sizeof(ret));
if (ret != FAIL) {
filesize -= unitprogramsize;
currentPointer += unitprogramsize;
@ -3043,7 +3043,7 @@ int slsDetector::programFPGA(std::vector<char> buffer) {
std::cout << std::flush;
} else {
printf("\n");
client.receiveData(mess, sizeof(mess));
client.Receive(mess, sizeof(mess));
std::ostringstream os;
os << "Detector " << detId << " (" << shm()->hostname << ")"
<< " returned error: " << mess;
@ -3090,7 +3090,7 @@ int slsDetector::rebootController() {
<< " (" << shm()->hostname << ")";
if (shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.sendData(&fnum, sizeof(fnum));
client.Send(&fnum, sizeof(fnum));
ret = OK;
}
return ret;
@ -3128,16 +3128,16 @@ int slsDetector::setModule(sls_detector_module &module, int tb) {
}
if (shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.sendData(&fnum, sizeof(fnum));
client.Send(&fnum, sizeof(fnum));
sendModule(&module, client);
client.receiveData(&ret, sizeof(ret));
client.Receive(&ret, sizeof(ret));
if (ret == FAIL) {
char mess[MAX_STR_LENGTH] = {0};
client.receiveData(mess, sizeof(mess));
client.Receive(mess, sizeof(mess));
throw RuntimeError("Detector " + std::to_string(detId) +
" returned error: " + mess);
}
client.receiveData(&retval, sizeof(retval));
client.Receive(&retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Set Module returned: " << retval;
}
if (ret == FORCE_UPDATE) {
@ -3317,95 +3317,95 @@ int slsDetector::updateCachedReceiverVariables() const {
char cstring[MAX_STR_LENGTH]{};
char lastClientIP[INET_ADDRSTRLEN]{};
n += receiver.receiveData(lastClientIP, sizeof(lastClientIP));
n += receiver.Receive(lastClientIP, sizeof(lastClientIP));
FILE_LOG(logDEBUG1)
<< "Updating receiver last modified by " << lastClientIP;
// filepath
n += receiver.receiveData(cstring, sizeof(cstring));
n += receiver.Receive(cstring, sizeof(cstring));
sls::strcpy_safe(shm()->rxFilePath, cstring);
// filename
n += receiver.receiveData(cstring, sizeof(cstring));
n += receiver.Receive(cstring, sizeof(cstring));
sls::strcpy_safe(shm()->rxFileName, cstring);
// index
n += receiver.receiveData(&i32, sizeof(i32));
n += receiver.Receive(&i32, sizeof(i32));
shm()->rxFileIndex = i32;
// file format
n += receiver.receiveData(&i32, sizeof(i32));
n += receiver.Receive(&i32, sizeof(i32));
shm()->rxFileFormat = static_cast<fileFormat>(i32);
// frames per file
n += receiver.receiveData(&i32, sizeof(i32));
n += receiver.Receive(&i32, sizeof(i32));
shm()->rxFramesPerFile = i32;
// frame discard policy
n += receiver.receiveData(&i32, sizeof(i32));
n += receiver.Receive(&i32, sizeof(i32));
shm()->rxFrameDiscardMode = static_cast<frameDiscardPolicy>(i32);
// frame padding
n += receiver.receiveData(&i32, sizeof(i32));
n += receiver.Receive(&i32, sizeof(i32));
shm()->rxFramePadding = static_cast<bool>(i32);
// file write enable
n += receiver.receiveData(&i32, sizeof(i32));
n += receiver.Receive(&i32, sizeof(i32));
shm()->rxFileWrite = static_cast<bool>(i32);
// master file write enable
n += receiver.receiveData(&i32, sizeof(i32));
n += receiver.Receive(&i32, sizeof(i32));
shm()->rxMasterFileWrite = static_cast<bool>(i32);
// file overwrite enable
n += receiver.receiveData(&i32, sizeof(i32));
n += receiver.Receive(&i32, sizeof(i32));
shm()->rxFileOverWrite = static_cast<bool>(i32);
// gap pixels
n += receiver.receiveData(&i32, sizeof(i32));
n += receiver.Receive(&i32, sizeof(i32));
shm()->gappixels = i32;
// receiver read frequency
n += receiver.receiveData(&i32, sizeof(i32));
n += receiver.Receive(&i32, sizeof(i32));
shm()->rxReadFreq = i32;
// receiver streaming port
n += receiver.receiveData(&i32, sizeof(i32));
n += receiver.Receive(&i32, sizeof(i32));
shm()->rxZmqport = i32;
// streaming source ip
n += receiver.receiveData(cstring, sizeof(cstring));
n += receiver.Receive(cstring, sizeof(cstring));
sls::strcpy_safe(shm()->rxZmqip, cstring);
// additional json header
n += receiver.receiveData(cstring, sizeof(cstring));
n += receiver.Receive(cstring, sizeof(cstring));
sls::strcpy_safe(shm()->rxAdditionalJsonHeader, cstring);
// receiver streaming enable
n += receiver.receiveData(&i32, sizeof(i32));
n += receiver.Receive(&i32, sizeof(i32));
shm()->rxUpstream = static_cast<bool>(i32);
// activate
n += receiver.receiveData(&i32, sizeof(i32));
n += receiver.Receive(&i32, sizeof(i32));
shm()->activated = static_cast<bool>(i32);
// deactivated padding enable
n += receiver.receiveData(&i32, sizeof(i32));
n += receiver.Receive(&i32, sizeof(i32));
shm()->rxPadDeactivatedModules = static_cast<bool>(i32);
// silent mode
n += receiver.receiveData(&i32, sizeof(i32));
n += receiver.Receive(&i32, sizeof(i32));
shm()->rxSilentMode = static_cast<bool>(i32);
// dbit list
{
sls::FixedCapacityContainer<int, MAX_RX_DBIT> temp;
n += receiver.receiveData(&temp, sizeof(temp));
n += receiver.Receive(&temp, sizeof(temp));
shm()->rxDbitList = temp;
}
// dbit offset
n += receiver.receiveData(&i32, sizeof(i32));
n += receiver.Receive(&i32, sizeof(i32));
shm()->rxDbitOffset = i32;
if (n == 0) {

View File

@ -212,7 +212,7 @@ int slsReceiverTCPIPInterface::function_table(){
// clang-format on
int slsReceiverTCPIPInterface::decode_function(Interface &socket) {
ret = FAIL;
socket.receiveArg(fnum);
socket.Receive(fnum);
if (fnum <= NUM_DET_FUNCTIONS || fnum >= NUM_REC_FUNCTIONS) {
throw RuntimeError("Unrecognized Function enum " +
std::to_string(fnum) + "\n");
@ -274,7 +274,7 @@ void slsReceiverTCPIPInterface::VerifyIdle(Interface &socket) {
int slsReceiverTCPIPInterface::exec_command(Interface &socket) {
char cmd[MAX_STR_LENGTH]{};
char retval[MAX_STR_LENGTH]{};
socket.receiveArg(cmd);
socket.Receive(cmd);
FILE_LOG(logINFO) << "Executing command (" << cmd << ")";
const size_t tempsize = 256;
std::array<char, tempsize> temp;
@ -295,12 +295,12 @@ int slsReceiverTCPIPInterface::exec_command(Interface &socket) {
int slsReceiverTCPIPInterface::exit_server(Interface &socket) {
FILE_LOG(logINFO) << "Closing server";
socket.sendData(OK);
socket.Send(OK);
return GOODBYE;
}
int slsReceiverTCPIPInterface::lock_receiver(Interface &socket) {
auto lock = socket.receive<int>();
auto lock = socket.Receive<int>();
FILE_LOG(logDEBUG1) << "Locking Server to " << lock;
if (lock >= 0) {
if (!lockStatus || (server->getLockedBy() == server->getThisClient())) {
@ -323,7 +323,7 @@ int slsReceiverTCPIPInterface::get_last_client_ip(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_port(Interface &socket) {
auto p_number = socket.receive<int>();
auto p_number = socket.Receive<int>();
if (p_number < 1024)
throw RuntimeError("Port Number: " + std::to_string(p_number) +
" is too low (<1024)");
@ -341,7 +341,7 @@ int slsReceiverTCPIPInterface::update_client(Interface &socket) {
if (receiver == nullptr)
throw sls::SocketError(
"Receiver not set up. Please use rx_hostname first.\n");
socket.sendData(OK);
socket.Send(OK);
return send_update(socket);
}
@ -352,83 +352,83 @@ int slsReceiverTCPIPInterface::send_update(Interface &socket) {
char ip[INET_ADDRSTRLEN]{};
sls::strcpy_safe(ip, server->getLastClient().str().c_str());
n += socket.sendData(ip, sizeof(ip));
n += socket.Send(ip, sizeof(ip));
// filepath
strcpy(cstring, receiver->getFilePath().c_str());
n += socket.sendData(cstring, sizeof(cstring));
n += socket.Send(cstring, sizeof(cstring));
// filename
strcpy(cstring, receiver->getFileName().c_str());
n += socket.sendData(cstring, sizeof(cstring));
n += socket.Send(cstring, sizeof(cstring));
// index
i32 = receiver->getFileIndex();
n += socket.sendData(&i32, sizeof(i32));
n += socket.Send(&i32, sizeof(i32));
// file format
i32 = (int)receiver->getFileFormat();
n += socket.sendData(&i32, sizeof(i32));
n += socket.Send(&i32, sizeof(i32));
// frames per file
i32 = (int)receiver->getFramesPerFile();
n += socket.sendData(&i32, sizeof(i32));
n += socket.Send(&i32, sizeof(i32));
// frame discard policy
i32 = (int)receiver->getFrameDiscardPolicy();
n += socket.sendData(&i32, sizeof(i32));
n += socket.Send(&i32, sizeof(i32));
// frame padding
i32 = (int)receiver->getFramePaddingEnable();
n += socket.sendData(&i32, sizeof(i32));
n += socket.Send(&i32, sizeof(i32));
// file write enable
i32 = (int)receiver->getFileWriteEnable();
n += socket.sendData(&i32, sizeof(i32));
n += socket.Send(&i32, sizeof(i32));
// master file write enable
i32 = (int)receiver->getMasterFileWriteEnable();
n += socket.sendData(&i32, sizeof(i32));
n += socket.Send(&i32, sizeof(i32));
// file overwrite enable
i32 = (int)receiver->getOverwriteEnable();
n += socket.sendData(&i32, sizeof(i32));
n += socket.Send(&i32, sizeof(i32));
// gap pixels
i32 = (int)receiver->getGapPixelsEnable();
n += socket.sendData(&i32, sizeof(i32));
n += socket.Send(&i32, sizeof(i32));
// streaming frequency
i32 = (int)receiver->getStreamingFrequency();
n += socket.sendData(&i32, sizeof(i32));
n += socket.Send(&i32, sizeof(i32));
// streaming port
i32 = (int)receiver->getStreamingPort();
n += socket.sendData(&i32, sizeof(i32));
n += socket.Send(&i32, sizeof(i32));
// streaming source ip
strcpy(cstring, receiver->getStreamingSourceIP().c_str());
n += socket.sendData(cstring, sizeof(cstring));
n += socket.Send(cstring, sizeof(cstring));
// additional json header
strcpy(cstring, receiver->getAdditionalJsonHeader().c_str());
n += socket.sendData(cstring, sizeof(cstring));
n += socket.Send(cstring, sizeof(cstring));
// data streaming enable
i32 = (int)receiver->getDataStreamEnable();
n += socket.sendData(&i32, sizeof(i32));
n += socket.Send(&i32, sizeof(i32));
// activate
i32 = (int)receiver->getActivate();
n += socket.sendData(&i32, sizeof(i32));
n += socket.Send(&i32, sizeof(i32));
// deactivated padding enable
i32 = (int)receiver->getDeactivatedPadding();
n += socket.sendData(&i32, sizeof(i32));
n += socket.Send(&i32, sizeof(i32));
// silent mode
i32 = (int)receiver->getSilentMode();
n += socket.sendData(&i32, sizeof(i32));
n += socket.Send(&i32, sizeof(i32));
// dbit list
{
@ -436,13 +436,13 @@ int slsReceiverTCPIPInterface::send_update(Interface &socket) {
int retvalsize = list.size();
int retval[retvalsize];
std::copy(std::begin(list), std::end(list), retval);
socket.sendData(&retvalsize, sizeof(retvalsize));
socket.sendData(retval, sizeof(retval));
socket.Send(&retvalsize, sizeof(retvalsize));
socket.Send(retval, sizeof(retval));
}
// dbit offset
i32 = receiver->getDbitOffset();
n += socket.sendData(&i32, sizeof(i32));
n += socket.Send(&i32, sizeof(i32));
return OK;
}
@ -452,7 +452,7 @@ int slsReceiverTCPIPInterface::get_id(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_detector_type(Interface &socket) {
auto arg = socket.receive<detectorType>();
auto arg = socket.Receive<detectorType>();
// set
if (arg >= 0) {
// if object exists, verify unlocked and idle, else only verify lock
@ -500,7 +500,7 @@ int slsReceiverTCPIPInterface::set_detector_type(Interface &socket) {
int slsReceiverTCPIPInterface::set_detector_hostname(Interface &socket) {
char hostname[MAX_STR_LENGTH]{};
char retval[MAX_STR_LENGTH]{};
socket.receiveArg(hostname);
socket.Receive(hostname);
if (strlen(hostname)) {
VerifyIdle(socket);
@ -516,11 +516,11 @@ int slsReceiverTCPIPInterface::set_detector_hostname(Interface &socket) {
int slsReceiverTCPIPInterface::set_roi(Interface &socket) {
static_assert(sizeof(ROI) == 4 * sizeof(int), "ROI not packed");
auto narg = socket.receive<int>();
auto narg = socket.Receive<int>();
std::vector<ROI> arg;
for (int iloop = 0; iloop < narg; ++iloop) {
ROI temp{};
socket.receiveArg(temp);
socket.Receive(temp);
arg.push_back(temp);
}
FILE_LOG(logDEBUG1) << "Set ROI narg: " << narg;
@ -536,14 +536,14 @@ int slsReceiverTCPIPInterface::set_roi(Interface &socket) {
VerifyIdle(socket);
if (impl()->setROI(arg) == FAIL)
throw RuntimeError("Could not set ROI");
return socket.sendData(OK);
return socket.Send(OK);
}
int slsReceiverTCPIPInterface::setup_udp(Interface &socket) {
ret = OK;
char args[5][MAX_STR_LENGTH]{};
char retvals[2][MAX_STR_LENGTH]{};
socket.receiveArg(args);
socket.Receive(args);
VerifyIdle(socket);
// setup interfaces count
@ -641,7 +641,7 @@ int slsReceiverTCPIPInterface::set_timer(Interface &socket) {
memset(mess, 0, sizeof(mess));
int64_t index[2] = {-1, -1};
int64_t retval = -1;
socket.receiveArg(index);
socket.Receive(index);
if (index[1] >= 0) {
FILE_LOG(logDEBUG1)
<< "Setting timer index " << index[0] << " to " << index[1];
@ -734,7 +734,7 @@ int slsReceiverTCPIPInterface::set_timer(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_dynamic_range(Interface &socket) {
auto dr = socket.receive<int>();
auto dr = socket.Receive<int>();
if (dr >= 0) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting dynamic range: " << dr;
@ -769,7 +769,7 @@ int slsReceiverTCPIPInterface::set_dynamic_range(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_streaming_frequency(Interface &socket) {
auto index = socket.receive<int>();
auto index = socket.Receive<int>();
if (index >= 0) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting streaming frequency: " << index;
@ -801,7 +801,7 @@ int slsReceiverTCPIPInterface::start_receiver(Interface &socket) {
throw RuntimeError(mess);
}
}
return socket.sendData(OK);
return socket.Send(OK);
}
int slsReceiverTCPIPInterface::stop_receiver(Interface &socket) {
@ -814,13 +814,13 @@ int slsReceiverTCPIPInterface::stop_receiver(Interface &socket) {
throw RuntimeError("Could not stop receiver. It as it is: " +
runStatusType(s));
return socket.sendData(OK);
return socket.Send(OK);
}
int slsReceiverTCPIPInterface::set_file_dir(Interface &socket) {
char fPath[MAX_STR_LENGTH]{};
char retval[MAX_STR_LENGTH]{};
socket.receiveArg(fPath);
socket.Receive(fPath);
if (strlen(fPath)) {
FILE_LOG(logDEBUG1) << "Setting file path: " << fPath;
@ -839,7 +839,7 @@ int slsReceiverTCPIPInterface::set_file_dir(Interface &socket) {
int slsReceiverTCPIPInterface::set_file_name(Interface &socket) {
char fName[MAX_STR_LENGTH]{};
char retval[MAX_STR_LENGTH]{};
socket.receiveArg(fName);
socket.Receive(fName);
if (strlen(fName)) {
FILE_LOG(logDEBUG1) << "Setting file name: " << fName;
impl()->setFileName(fName);
@ -854,7 +854,7 @@ int slsReceiverTCPIPInterface::set_file_name(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_file_index(Interface &socket) {
auto index = socket.receive<int>();
auto index = socket.Receive<int>();
if (index >= 0) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting file index: " << index;
@ -881,11 +881,11 @@ int slsReceiverTCPIPInterface::get_frames_caught(Interface &socket) {
int slsReceiverTCPIPInterface::reset_frames_caught(Interface &socket) {
FILE_LOG(logDEBUG1) << "Reset frames caught";
impl()->resetAcquisitionCount();
return socket.sendData(OK);
return socket.Send(OK);
}
int slsReceiverTCPIPInterface::enable_file_write(Interface &socket) {
auto enable = socket.receive<int>();
auto enable = socket.Receive<int>();
if (enable >= 0) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting File write enable:" << enable;
@ -898,7 +898,7 @@ int slsReceiverTCPIPInterface::enable_file_write(Interface &socket) {
}
int slsReceiverTCPIPInterface::enable_master_file_write(Interface &socket) {
auto enable = socket.receive<int>();
auto enable = socket.Receive<int>();
if (enable >= 0) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting Master File write enable:" << enable;
@ -911,7 +911,7 @@ int slsReceiverTCPIPInterface::enable_master_file_write(Interface &socket) {
}
int slsReceiverTCPIPInterface::enable_overwrite(Interface &socket) {
auto index = socket.receive<int>();
auto index = socket.Receive<int>();
if (index >= 0) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting File overwrite enable:" << index;
@ -924,7 +924,7 @@ int slsReceiverTCPIPInterface::enable_overwrite(Interface &socket) {
}
int slsReceiverTCPIPInterface::enable_tengiga(Interface &socket) {
auto val = socket.receive<int>();
auto val = socket.Receive<int>();
if (myDetectorType != EIGER && myDetectorType != CHIPTESTBOARD &&
myDetectorType != MOENCH)
functionNotImplemented();
@ -941,7 +941,7 @@ int slsReceiverTCPIPInterface::enable_tengiga(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_fifo_depth(Interface &socket) {
auto value = socket.receive<int>();
auto value = socket.Receive<int>();
if (value >= 0) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting fifo depth:" << value;
@ -954,7 +954,7 @@ int slsReceiverTCPIPInterface::set_fifo_depth(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_activate(Interface &socket) {
auto enable = socket.receive<int>();
auto enable = socket.Receive<int>();
if (myDetectorType != EIGER)
functionNotImplemented();
@ -970,7 +970,7 @@ int slsReceiverTCPIPInterface::set_activate(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_data_stream_enable(Interface &socket) {
auto index = socket.receive<int>();
auto index = socket.Receive<int>();
if (index >= 0) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting data stream enable:" << index;
@ -983,7 +983,7 @@ int slsReceiverTCPIPInterface::set_data_stream_enable(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_streaming_timer(Interface &socket) {
auto index = socket.receive<int>();
auto index = socket.Receive<int>();
if (index >= 0) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting streaming timer:" << index;
@ -999,7 +999,7 @@ int slsReceiverTCPIPInterface::set_flipped_data(Interface &socket) {
// TODO! Why 2 args?
memset(mess, 0, sizeof(mess));
int args[2]{0, -1};
socket.receiveArg(args);
socket.Receive(args);
if (myDetectorType != EIGER)
functionNotImplemented();
@ -1017,7 +1017,7 @@ int slsReceiverTCPIPInterface::set_flipped_data(Interface &socket) {
int slsReceiverTCPIPInterface::set_file_format(Interface &socket) {
fileFormat f = GET_FILE_FORMAT;
socket.receiveArg(f);
socket.Receive(f);
if (f >= 0) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting file format:" << f;
@ -1030,7 +1030,7 @@ int slsReceiverTCPIPInterface::set_file_format(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_detector_posid(Interface &socket) {
auto arg = socket.receive<int>();
auto arg = socket.Receive<int>();
if (arg >= 0) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting detector position id:" << arg;
@ -1044,7 +1044,7 @@ int slsReceiverTCPIPInterface::set_detector_posid(Interface &socket) {
int slsReceiverTCPIPInterface::set_multi_detector_size(Interface &socket) {
int arg[]{-1, -1};
socket.receiveArg(arg);
socket.Receive(arg);
if ((arg[0] > 0) && (arg[1] > 0)) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1)
@ -1058,7 +1058,7 @@ int slsReceiverTCPIPInterface::set_multi_detector_size(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_streaming_port(Interface &socket) {
auto port = socket.receive<int>();
auto port = socket.Receive<int>();
if (port >= 0) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting streaming port:" << port;
@ -1073,7 +1073,7 @@ int slsReceiverTCPIPInterface::set_streaming_port(Interface &socket) {
int slsReceiverTCPIPInterface::set_streaming_source_ip(Interface &socket) {
char arg[MAX_STR_LENGTH]{};
char retval[MAX_STR_LENGTH]{};
socket.receiveArg(arg);
socket.Receive(arg);
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting streaming source ip:" << arg;
impl()->setStreamingSourceIP(arg);
@ -1083,7 +1083,7 @@ int slsReceiverTCPIPInterface::set_streaming_source_ip(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_silent_mode(Interface &socket) {
auto value = socket.receive<int>();
auto value = socket.Receive<int>();
if (value >= 0) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting silent mode:" << value;
@ -1096,7 +1096,7 @@ int slsReceiverTCPIPInterface::set_silent_mode(Interface &socket) {
}
int slsReceiverTCPIPInterface::enable_gap_pixels(Interface &socket) {
auto enable = socket.receive<int>();
auto enable = socket.Receive<int>();
if (myDetectorType != EIGER)
functionNotImplemented();
@ -1122,14 +1122,14 @@ int slsReceiverTCPIPInterface::restream_stop(Interface &socket) {
if (ret == FAIL)
throw RuntimeError("Could not restream stop packet");
}
return socket.sendData(OK);
return socket.Send(OK);
}
int slsReceiverTCPIPInterface::set_additional_json_header(Interface &socket) {
memset(mess, 0, sizeof(mess));
char arg[MAX_STR_LENGTH]{};
char retval[MAX_STR_LENGTH]{};
socket.receiveArg(arg);
socket.Receive(arg);
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting additional json header: " << arg;
impl()->setAdditionalJsonHeader(arg);
@ -1146,7 +1146,7 @@ int slsReceiverTCPIPInterface::get_additional_json_header(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_udp_socket_buffer_size(Interface &socket) {
auto index = socket.receive<int64_t>();
auto index = socket.Receive<int64_t>();
if (index >= 0) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting UDP Socket Buffer size: " << index;
@ -1174,7 +1174,7 @@ int slsReceiverTCPIPInterface::get_real_udp_socket_buffer_size(
}
int slsReceiverTCPIPInterface::set_frames_per_file(Interface &socket) {
auto index = socket.receive<int>();
auto index = socket.Receive<int>();
if (index >= 0) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting frames per file: " << index;
@ -1187,7 +1187,7 @@ int slsReceiverTCPIPInterface::set_frames_per_file(Interface &socket) {
}
int slsReceiverTCPIPInterface::check_version_compatibility(Interface &socket) {
auto arg = socket.receive<int64_t>();
auto arg = socket.Receive<int64_t>();
FILE_LOG(logDEBUG1) << "Checking versioning compatibility with value "
<< arg;
int64_t client_requiredVersion = arg;
@ -1219,11 +1219,11 @@ int slsReceiverTCPIPInterface::check_version_compatibility(Interface &socket) {
} else {
FILE_LOG(logINFO) << "Compatibility with Client: Successful";
}
return socket.sendData(OK);
return socket.Send(OK);
}
int slsReceiverTCPIPInterface::set_discard_policy(Interface &socket) {
auto index = socket.receive<int>();
auto index = socket.Receive<int>();
if (index >= 0) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting frames discard policy: " << index;
@ -1236,7 +1236,7 @@ int slsReceiverTCPIPInterface::set_discard_policy(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_padding_enable(Interface &socket) {
auto index = socket.receive<int>();
auto index = socket.Receive<int>();
if (index >= 0) {
VerifyIdle(socket);
index = (index == 0) ? 0 : 1;
@ -1251,7 +1251,7 @@ int slsReceiverTCPIPInterface::set_padding_enable(Interface &socket) {
int slsReceiverTCPIPInterface::set_deactivated_padding_enable(
Interface &socket) {
auto enable = socket.receive<int>();
auto enable = socket.Receive<int>();
if (myDetectorType != EIGER)
functionNotImplemented();
@ -1268,7 +1268,7 @@ int slsReceiverTCPIPInterface::set_deactivated_padding_enable(
}
int slsReceiverTCPIPInterface::set_readout_flags(Interface &socket) {
auto arg = socket.receive<readOutFlags>();
auto arg = socket.Receive<readOutFlags>();
if (myDetectorType == JUNGFRAU || myDetectorType == GOTTHARD ||
myDetectorType == MOENCH)
@ -1287,7 +1287,7 @@ int slsReceiverTCPIPInterface::set_readout_flags(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_adc_mask(Interface &socket) {
auto arg = socket.receive<uint32_t>();
auto arg = socket.Receive<uint32_t>();
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting ADC enable mask: " << arg;
impl()->setADCEnableMask(arg);
@ -1303,7 +1303,7 @@ int slsReceiverTCPIPInterface::set_adc_mask(Interface &socket) {
int slsReceiverTCPIPInterface::set_dbit_list(Interface &socket) {
sls::FixedCapacityContainer<int, MAX_RX_DBIT> args;
socket.receiveArg(args);
socket.Receive(args);
FILE_LOG(logDEBUG1) << "Setting DBIT list";
for (auto &it : args) {
FILE_LOG(logDEBUG1) << it << " ";
@ -1311,7 +1311,7 @@ int slsReceiverTCPIPInterface::set_dbit_list(Interface &socket) {
FILE_LOG(logDEBUG1) << "\n";
VerifyIdle(socket);
impl()->setDbitList(args);
return socket.sendData(OK);
return socket.Send(OK);
}
int slsReceiverTCPIPInterface::get_dbit_list(Interface &socket) {
@ -1322,7 +1322,7 @@ int slsReceiverTCPIPInterface::get_dbit_list(Interface &socket) {
}
int slsReceiverTCPIPInterface::set_dbit_offset(Interface &socket) {
auto arg = socket.receive<int>();
auto arg = socket.Receive<int>();
if (arg >= 0) {
VerifyIdle(socket);
FILE_LOG(logDEBUG1) << "Setting Dbit offset: " << arg;

View File

@ -4,6 +4,7 @@
#include <cstdint>
#include <netdb.h>
#include <string>
#include <numeric>
namespace sls {
class DataSocket {
@ -16,13 +17,30 @@ class DataSocket {
DataSocket(const DataSocket &) = delete;
DataSocket &operator=(DataSocket const &) = delete;
int getSocketId() const { return socketId_; }
int sendData(const void *buffer, size_t size);
template <typename T> int sendData(T &&data) {
return sendData(&data, sizeof(data));
int Send(const void *buffer, size_t size);
template <typename T> int Send(T &&data) {
return Send(&data, sizeof(data));
}
// Trick to send all
template <class... Args> int SendAll(Args &&... args) {
auto l = std::initializer_list<int>{Send(args)...};
auto sum = std::accumulate(begin(l), end(l), 0);
return sum;
}
int Receive(void *buffer, size_t size);
template <typename T> int Receive(T &arg) {
return Receive(&arg, sizeof(arg));
}
template <typename T> T Receive() {
T arg;
Receive(&arg, sizeof(arg));
return arg;
}
int receiveData(void *buffer, size_t size);
int read(void *buffer, size_t size);
int write(void *buffer, size_t size);
int setTimeOut(int t_seconds);

View File

@ -22,23 +22,10 @@ class ServerInterface2 : public DataSocket {
}
template <typename T> int sendResult(T &&retval) {
sendData(defs::OK);
sendData(retval);
Send(defs::OK);
Send(retval);
return defs::OK;
}
int receiveArg(void *arg, int sizeofArg);
template <typename T> int receiveArg(T &arg) {
return receiveArg(&arg, sizeof(arg));
}
template <typename T> T receive() {
T arg;
receiveArg(&arg, sizeof(arg));
return arg;
}
private:
};
} // namespace sls

View File

@ -62,19 +62,19 @@ int ClientSocket::sendCommandThenRead(int fnum, const void *args,
size_t args_size, void *retval,
size_t retval_size) {
int ret = slsDetectorDefs::FAIL;
sendData(&fnum, sizeof(fnum));
sendData(args, args_size);
Send(&fnum, sizeof(fnum));
Send(args, args_size);
readReply(ret, retval, retval_size);
return ret;
}
void ClientSocket::readReply(int &ret, void *retval, size_t retval_size) {
read(&ret, sizeof(ret));
Receive(&ret, sizeof(ret));
if (ret == slsDetectorDefs::FAIL) {
char mess[MAX_STR_LENGTH]{};
// get error message
read(mess, sizeof(mess));
Receive(mess, sizeof(mess));
// Do we need to know hostname here?
// In that case save it???
if (socketType == "Receiver") {
@ -86,7 +86,7 @@ void ClientSocket::readReply(int &ret, void *retval, size_t retval_size) {
}
}
// get retval
read(retval, retval_size);
Receive(retval, retval_size);
}
}; // namespace sls

View File

@ -42,9 +42,8 @@ DataSocket &DataSocket::operator=(DataSocket &&move) noexcept {
return *this;
}
int DataSocket::receiveData(void *buffer, size_t size) {
int DataSocket::Receive(void *buffer, size_t size) {
// TODO!(Erik) Add sleep? how many reties?
assert(size > 0);
int bytes_expected = static_cast<int>(size); // signed size
int bytes_read = 0;
while (bytes_read < bytes_expected) {
@ -65,7 +64,7 @@ int DataSocket::receiveData(void *buffer, size_t size) {
}
}
int DataSocket::sendData(const void *buffer, size_t size) {
int DataSocket::Send(const void *buffer, size_t size) {
int bytes_sent = 0;
int data_size = static_cast<int>(size); // signed size
while (bytes_sent < (data_size)) {

View File

@ -21,18 +21,4 @@ int ServerInterface2::sendResult(int ret, void *retval, int retvalSize,
return ret;
}
int ServerInterface2::receiveArg(void *arg, int sizeofArg) {
assert(sizeofArg > 0);
int bytes_read = receiveData(arg, sizeofArg);
if (bytes_read == sizeofArg) {
return defs::OK;
} else {
std::ostringstream ss;
ss << "TCP socket error read " << bytes_read << " bytes instead of "
<< sizeofArg << " bytes";
throw sls::SocketError(ss.str());
}
}
} // namespace sls

View File

@ -10,14 +10,14 @@ std::vector<char> server() {
auto server = sls::ServerSocket(1950);
auto s = server.accept();
std::vector<char> buffer(100, '\0');
s.receiveData(buffer.data(), buffer.size());
s.Receive(buffer.data(), buffer.size());
std::cout << "ServerReceived: " << std::string(buffer.begin(), buffer.end())
<< '\n';
std::vector<char> to_send(100, '\0');
to_send[0] = 'O';
to_send[1] = 'K';
s.sendData(to_send.data(), to_send.size());
s.Send(to_send.data(), to_send.size());
s.close();
return buffer;
}
@ -31,8 +31,8 @@ TEST_CASE("The server recive the same message as we send", "[support]") {
auto s = std::async(std::launch::async, server);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
auto client = sls::DetectorSocket("localhost", 1950);
client.sendData(sent_message.data(), sent_message.size());
client.receiveData(received_message.data(), received_message.size());
client.Send(sent_message.data(), sent_message.size());
client.Receive(received_message.data(), received_message.size());
client.close();
auto server_message = s.get();

View File

@ -1,5 +1,5 @@
#pragma once
#include <cstdint>
enum class func_id{read_data, read_int, read_half_data};
enum class func_id{read_data, read_int, read_half_data, combined};
constexpr size_t MB = 1048576;
constexpr size_t DATA_SIZE = 50*MB;

View File

@ -1,6 +1,6 @@
#include "ClientSocket.h"
#include "sls_detector_exceptions.h"
#include "clara.hpp"
#include "sls_detector_exceptions.h"
#include "tests/testenum.h"
#include "container_utils.h"
@ -36,45 +36,50 @@ int main(int argc, char **argv) {
for (int i = 0; i != 100; ++i) {
std::cout << "Sending: " << i << "\n";
auto socket = sls::ClientSocket("test", hostname, port);
std::cout << "Sent: " << socket.sendData(func_id::read_int)
<< " bytes\n";
std::cout << "Sent: " << socket.sendData(i) << " bytes\n";
std::cout << "Sent: " << socket.Send(func_id::read_int) << " bytes\n";
std::cout << "Sent: " << socket.Send(i) << " bytes\n";
}
// Sending larger blocks
for (int i = 0; i != 5; ++i) {
std::cout << "Sending data\n";
auto socket = sls::ClientSocket("test", hostname, port);
std::cout << "Sent: " << socket.sendData(func_id::read_data)
<< " bytes\n";
std::cout << "Sent: " << socket.sendData(data.get(), DATA_SIZE)
std::cout << "Sent: " << socket.Send(func_id::read_data) << " bytes\n";
std::cout << "Sent: " << socket.Send(data.get(), DATA_SIZE)
<< " bytes\n";
}
// Send too little data
{
auto socket = sls::ClientSocket("test", hostname, port);
std::cout << "Sent: " << socket.sendData(func_id::read_data)
<< " bytes\n";
std::cout << "Sent: " << socket.sendData(data.get(), DATA_SIZE / 2)
std::cout << "Sent: " << socket.Send(func_id::read_data) << " bytes\n";
std::cout << "Sent: " << socket.Send(data.get(), DATA_SIZE / 2)
<< " bytes\n";
}
// Send too much data
try{
try {
auto socket = sls::ClientSocket("test", hostname, port);
std::cout << "Sent: " << socket.sendData(func_id::read_half_data)
std::cout << "Sent: " << socket.Send(func_id::read_half_data)
<< " bytes\n";
std::cout << "Sent: " << socket.sendData(data.get(), DATA_SIZE)
std::cout << "Sent: " << socket.Send(data.get(), DATA_SIZE)
<< " bytes\n";
}catch(const sls::SocketError& e){
} catch (const sls::SocketError &e) {
}
// Some ints again
for (int i = 0; i != 10; ++i) {
std::cout << "Sending: " << i << "\n";
auto socket = sls::ClientSocket("test", hostname, port);
std::cout << "Sent: " << socket.sendData(func_id::read_int)
<< " bytes\n";
std::cout << "Sent: " << socket.sendData(i) << " bytes\n";
std::cout << "Sent: " << socket.Send(func_id::read_int) << " bytes\n";
std::cout << "Sent: " << socket.Send(i) << " bytes\n";
}
// some combined sends
{
int a = 9;
double b = 18.3;
float c = -1.2;
auto socket = sls::ClientSocket("test", hostname, port);
int s = socket.SendAll(func_id::combined, a, b, c);
std::cout << "send all: " << s << "\n";
}
}

View File

@ -24,26 +24,34 @@ using func_ptr = void (*)(Interface &);
void read_data(Interface &socket) {
auto data = sls::make_unique<char[]>(DATA_SIZE);
std::cout << "Read: " << socket.receiveData(data.get(), DATA_SIZE)
std::cout << "Read: " << socket.Receive(data.get(), DATA_SIZE)
<< " bytes into buffer\n";
}
void read_half_data(Interface &socket) {
auto data = sls::make_unique<char[]>(DATA_SIZE);
std::cout << "Read: " << socket.receiveData(data.get(), DATA_SIZE / 2)
std::cout << "Read: " << socket.Receive(data.get(), DATA_SIZE / 2)
<< " bytes into buffer\n";
}
void read_int(Interface &socket) {
auto i = socket.receive<int>();
auto i = socket.Receive<int>();
std::cout << "Read <int>: " << i << "\n";
}
void read_combined(Interface &socket){
auto i = socket.Receive<int>();
auto d = socket.Receive<double>();
auto f = socket.Receive<float>();
std::cout << "read i: " << i << " d: " << d << " f: " << f << "\n";
}
// Map from int to function pointer, in this case probably a map would be faster
std::unordered_map<func_id, func_ptr, EnumClassHash> fmap{
{func_id::read_data, &read_data},
{func_id::read_int, &read_int},
{func_id::read_half_data, &read_half_data}};
{func_id::read_half_data, &read_half_data},
{func_id::combined, &read_combined}};
int main(int argc, char **argv) {
std::cout << "Starting test server...\n";
@ -63,7 +71,7 @@ int main(int argc, char **argv) {
while (true) {
try {
auto socket = server.accept();
auto fnum = socket.receive<func_id>();
auto fnum = socket.Receive<func_id>();
std::cout << "Calling func: " << (int)fnum << "\n";
(*fmap[fnum])(socket); // call mapped function