mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-22 14:38:14 +02:00
det id const and ini shm in constructor
This commit is contained in:
parent
7522a655df
commit
4943983d10
@ -29,8 +29,9 @@
|
|||||||
using sls::SharedMemory;
|
using sls::SharedMemory;
|
||||||
using sls::SharedMemoryError;
|
using sls::SharedMemoryError;
|
||||||
|
|
||||||
multiSlsDetector::multiSlsDetector(int id, bool verify, bool update)
|
multiSlsDetector::multiSlsDetector(int multi_id, bool verify, bool update)
|
||||||
: detId(id) {
|
: multiId(multi_id),
|
||||||
|
multi_shm(multi_id, -1) {
|
||||||
setupMultiDetector(verify, update);
|
setupMultiDetector(verify, update);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,20 +303,15 @@ std::string multiSlsDetector::getUserDetails() {
|
|||||||
return sstream.str();
|
return sstream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* pre: multi_shm=0, multi_shm() = 0, detectors.size() = 0
|
|
||||||
*/
|
|
||||||
void multiSlsDetector::initSharedMemory(bool verify) {
|
void multiSlsDetector::initSharedMemory(bool verify) {
|
||||||
multi_shm = SharedMemory<sharedMultiSlsDetector>(detId, -1);
|
|
||||||
if (!multi_shm.IsExisting()) {
|
if (!multi_shm.IsExisting()) {
|
||||||
multi_shm.CreateSharedMemory();
|
multi_shm.CreateSharedMemory();
|
||||||
initializeDetectorStructure();
|
initializeDetectorStructure();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
multi_shm.OpenSharedMemory();
|
multi_shm.OpenSharedMemory();
|
||||||
if (verify && multi_shm()->shmversion != MULTI_SHMVERSION) {
|
if (verify && multi_shm()->shmversion != MULTI_SHMVERSION) {
|
||||||
FILE_LOG(logERROR) << "Multi shared memory (" << detId << ") version mismatch "
|
FILE_LOG(logERROR) << "Multi shared memory (" << multiId << ") version mismatch "
|
||||||
"(expected 0x"
|
"(expected 0x"
|
||||||
<< std::hex << MULTI_SHMVERSION << " but got 0x" << multi_shm()->shmversion << std::dec;
|
<< std::hex << MULTI_SHMVERSION << " but got 0x" << multi_shm()->shmversion << std::dec;
|
||||||
throw SharedMemoryError("Shared memory version mismatch!");
|
throw SharedMemoryError("Shared memory version mismatch!");
|
||||||
}
|
}
|
||||||
@ -355,7 +351,7 @@ void multiSlsDetector::initializeMembers(bool verify) {
|
|||||||
for (int i = 0; i < multi_shm()->numberOfDetectors; i++) {
|
for (int i = 0; i < multi_shm()->numberOfDetectors; i++) {
|
||||||
try {
|
try {
|
||||||
detectors.push_back(
|
detectors.push_back(
|
||||||
sls::make_unique<slsDetector>(detId, i, verify));
|
sls::make_unique<slsDetector>(multiId, i, verify));
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
detectors.clear();
|
detectors.clear();
|
||||||
throw;
|
throw;
|
||||||
@ -463,7 +459,7 @@ void multiSlsDetector::addSlsDetector(const std::string &hostname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int pos = (int)detectors.size();
|
int pos = (int)detectors.size();
|
||||||
detectors.push_back(sls::make_unique<slsDetector>(type, detId, pos, false));
|
detectors.push_back(sls::make_unique<slsDetector>(type, multiId, pos, false));
|
||||||
multi_shm()->numberOfDetectors = detectors.size();
|
multi_shm()->numberOfDetectors = detectors.size();
|
||||||
multi_shm()->dataBytes += detectors[pos]->getDataBytes();
|
multi_shm()->dataBytes += detectors[pos]->getDataBytes();
|
||||||
multi_shm()->dataBytesInclGapPixels +=
|
multi_shm()->dataBytesInclGapPixels +=
|
||||||
|
@ -120,7 +120,7 @@ class multiSlsDetector : public virtual slsDetectorDefs,
|
|||||||
* one
|
* one
|
||||||
* @param update true to update last user pid, date etc
|
* @param update true to update last user pid, date etc
|
||||||
*/
|
*/
|
||||||
explicit multiSlsDetector(int id = 0, bool verify = true, bool update = true);
|
explicit multiSlsDetector(int multi_id = 0, bool verify = true, bool update = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor
|
* Destructor
|
||||||
@ -1956,7 +1956,7 @@ class multiSlsDetector : public virtual slsDetectorDefs,
|
|||||||
int kbhit();
|
int kbhit();
|
||||||
|
|
||||||
/** Multi detector Id */
|
/** Multi detector Id */
|
||||||
int detId;
|
const int multiId;
|
||||||
|
|
||||||
/** Shared Memory object */
|
/** Shared Memory object */
|
||||||
sls::SharedMemory<sharedMultiSlsDetector> multi_shm{0, -1};
|
sls::SharedMemory<sharedMultiSlsDetector> multi_shm{0, -1};
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@ -22,39 +23,39 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
|
using sls::RuntimeError;
|
||||||
using sls::SharedMemory;
|
using sls::SharedMemory;
|
||||||
using sls::SharedMemoryError;
|
using sls::SharedMemoryError;
|
||||||
using sls::RuntimeError;
|
|
||||||
|
|
||||||
#define DEFAULT_HOSTNAME "localhost"
|
#define DEFAULT_HOSTNAME "localhost"
|
||||||
|
|
||||||
slsDetector::slsDetector(detectorType type, int multiId, int id, bool verify)
|
slsDetector::slsDetector(detectorType type, int multi_id, int det_id, bool verify)
|
||||||
: detId(id) {
|
: detId(det_id),
|
||||||
|
detector_shm(multi_id, det_id) {
|
||||||
/* called from put hostname command,
|
/* called from put hostname command,
|
||||||
* so sls shared memory will be created */
|
* so sls shared memory will be created */
|
||||||
|
|
||||||
// ensure shared memory was not created before
|
// ensure shared memory was not created before
|
||||||
SharedMemory<sharedSlsDetector> shm(multiId, id);
|
if (detector_shm.IsExisting()) {
|
||||||
if (shm.IsExisting()) {
|
|
||||||
FILE_LOG(logWARNING) << "This shared memory should have been "
|
FILE_LOG(logWARNING) << "This shared memory should have been "
|
||||||
"deleted before! "
|
"deleted before! "
|
||||||
<< shm.GetName() << ". Freeing it again";
|
<< detector_shm.GetName() << ". Freeing it again";
|
||||||
freeSharedMemory(multiId, id);
|
freeSharedMemory(multi_id, det_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
initSharedMemory(type, multiId, verify);
|
initSharedMemory(type, multi_id, verify);
|
||||||
}
|
}
|
||||||
|
|
||||||
slsDetector::slsDetector(int multiId, int id, bool verify)
|
slsDetector::slsDetector(int multi_id, int det_id, bool verify)
|
||||||
: detId(id) {
|
: detId(det_id),
|
||||||
|
detector_shm(multi_id, det_id) {
|
||||||
/* called from multi constructor to populate structure,
|
/* called from multi constructor to populate structure,
|
||||||
* so sls shared memory will be opened, not created */
|
* so sls shared memory will be opened, not created */
|
||||||
|
|
||||||
// getDetectorType From shm will check if it was already existing
|
// getDetectorType From shm will check if it was already existing
|
||||||
detectorType type = getDetectorTypeFromShm(multiId, verify);
|
detectorType type = getDetectorTypeFromShm(multi_id, verify);
|
||||||
initSharedMemory(type, multiId, verify);
|
initSharedMemory(type, multi_id, verify);
|
||||||
}
|
}
|
||||||
|
|
||||||
slsDetector::~slsDetector() = default;
|
slsDetector::~slsDetector() = default;
|
||||||
@ -196,8 +197,8 @@ int64_t slsDetector::getId(idMode mode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void slsDetector::freeSharedMemory(int multiId, int slsId) {
|
void slsDetector::freeSharedMemory(int multi_id, int slsId) {
|
||||||
SharedMemory<sharedSlsDetector> shm(multiId, slsId);
|
SharedMemory<sharedSlsDetector> shm(multi_id, slsId);
|
||||||
if (shm.IsExisting()) {
|
if (shm.IsExisting()) {
|
||||||
shm.RemoveSharedMemory();
|
shm.RemoveSharedMemory();
|
||||||
}
|
}
|
||||||
@ -219,10 +220,10 @@ std::string slsDetector::getHostname() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void slsDetector::initSharedMemory(detectorType type,
|
void slsDetector::initSharedMemory(detectorType type,
|
||||||
int multiId,
|
int multi_id,
|
||||||
bool verify) {
|
bool verify) {
|
||||||
|
|
||||||
detector_shm = SharedMemory<sharedSlsDetector>(multiId, detId);
|
detector_shm = SharedMemory<sharedSlsDetector>(multi_id, detId);
|
||||||
if (!detector_shm.IsExisting()) {
|
if (!detector_shm.IsExisting()) {
|
||||||
detector_shm.CreateSharedMemory();
|
detector_shm.CreateSharedMemory();
|
||||||
initializeDetectorStructure(type);
|
initializeDetectorStructure(type);
|
||||||
@ -231,9 +232,9 @@ void slsDetector::initSharedMemory(detectorType type,
|
|||||||
if (verify && detector_shm()->shmversion != SLS_SHMVERSION) {
|
if (verify && detector_shm()->shmversion != SLS_SHMVERSION) {
|
||||||
FILE_LOG(logERROR) << "Single shared memory "
|
FILE_LOG(logERROR) << "Single shared memory "
|
||||||
"("
|
"("
|
||||||
<< multiId << "-" << detId << ":) "
|
<< multi_id << "-" << detId << ":) "
|
||||||
"version mismatch "
|
"version mismatch "
|
||||||
"(expected 0x"
|
"(expected 0x"
|
||||||
<< std::hex << SLS_SHMVERSION << " but got 0x" << detector_shm()->shmversion << ")" << std::dec;
|
<< std::hex << SLS_SHMVERSION << " but got 0x" << detector_shm()->shmversion << ")" << std::dec;
|
||||||
throw SharedMemoryError("Shared memory version mismatch (det)");
|
throw SharedMemoryError("Shared memory version mismatch (det)");
|
||||||
}
|
}
|
||||||
@ -423,7 +424,6 @@ void slsDetector::initializeDetectorStructure(detectorType type) {
|
|||||||
if (detector_shm()->myDetectorType == CHIPTESTBOARD || detector_shm()->myDetectorType == MOENCH) {
|
if (detector_shm()->myDetectorType == CHIPTESTBOARD || detector_shm()->myDetectorType == MOENCH) {
|
||||||
updateTotalNumberOfChannels();
|
updateTotalNumberOfChannels();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
slsDetectorDefs::sls_detector_module *slsDetector::createModule() {
|
slsDetectorDefs::sls_detector_module *slsDetector::createModule() {
|
||||||
@ -465,7 +465,7 @@ void slsDetector::connectDataError() {
|
|||||||
setErrorMask((getErrorMask()) | (CANNOT_CONNECT_TO_RECEIVER));
|
setErrorMask((getErrorMask()) | (CANNOT_CONNECT_TO_RECEIVER));
|
||||||
}
|
}
|
||||||
|
|
||||||
int slsDetector::sendModule(sls_detector_module *myMod, sls::ClientSocket& client) {
|
int slsDetector::sendModule(sls_detector_module *myMod, sls::ClientSocket &client) {
|
||||||
TLogLevel level = logDEBUG1;
|
TLogLevel level = logDEBUG1;
|
||||||
FILE_LOG(level) << "Sending Module";
|
FILE_LOG(level) << "Sending Module";
|
||||||
int ts = 0;
|
int ts = 0;
|
||||||
@ -514,7 +514,7 @@ int slsDetector::sendModule(sls_detector_module *myMod, sls::ClientSocket& clien
|
|||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
int slsDetector::receiveModule(sls_detector_module *myMod, sls::ClientSocket& client) {
|
int slsDetector::receiveModule(sls_detector_module *myMod, sls::ClientSocket &client) {
|
||||||
int ts = 0;
|
int ts = 0;
|
||||||
ts += client.receiveData(&(myMod->serialnumber), sizeof(myMod->serialnumber));
|
ts += client.receiveData(&(myMod->serialnumber), sizeof(myMod->serialnumber));
|
||||||
ts += client.receiveData(&(myMod->nchan), sizeof(myMod->nchan));
|
ts += client.receiveData(&(myMod->nchan), sizeof(myMod->nchan));
|
||||||
@ -537,28 +537,27 @@ int slsDetector::receiveModule(sls_detector_module *myMod, sls::ClientSocket& cl
|
|||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
slsDetectorDefs::detectorType slsDetector::getDetectorTypeFromShm(int multiId, bool verify) {
|
slsDetectorDefs::detectorType slsDetector::getDetectorTypeFromShm(int multi_id, bool verify) {
|
||||||
SharedMemory<sharedSlsDetector> shm(multiId, detId);
|
if (!detector_shm.IsExisting()) {
|
||||||
if (!shm.IsExisting()) {
|
FILE_LOG(logERROR) << "Shared memory " << detector_shm.GetName() << " does not exist.\n"
|
||||||
FILE_LOG(logERROR) << "Shared memory " << shm.GetName() << " does not exist.\n"
|
|
||||||
"Corrupted Multi Shared memory. Please free shared memory.";
|
"Corrupted Multi Shared memory. Please free shared memory.";
|
||||||
throw SharedMemoryError("Could not read detector type from shared memory");
|
throw SharedMemoryError("Could not read detector type from shared memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
// open, map, verify version
|
// open, map, verify version
|
||||||
shm.OpenSharedMemory();
|
detector_shm.OpenSharedMemory();
|
||||||
|
|
||||||
if (verify && shm()->shmversion != SLS_SHMVERSION) {
|
if (verify && detector_shm()->shmversion != SLS_SHMVERSION) {
|
||||||
FILE_LOG(logERROR) << "Single shared memory "
|
FILE_LOG(logERROR) << "Single shared memory "
|
||||||
"("
|
"("
|
||||||
<< multiId << "-" << detId << ":)version mismatch "
|
<< multi_id << "-" << detId << ":)version mismatch "
|
||||||
"(expected 0x"
|
"(expected 0x"
|
||||||
<< std::hex << SLS_SHMVERSION << " but got 0x" << shm()->shmversion << ")" << std::dec;
|
<< std::hex << SLS_SHMVERSION << " but got 0x" << detector_shm()->shmversion << ")" << std::dec;
|
||||||
// unmap and throw
|
// unmap and throw
|
||||||
detector_shm.UnmapSharedMemory();
|
detector_shm.UnmapSharedMemory();
|
||||||
throw SharedMemoryError("Shared memory version mismatch");
|
throw SharedMemoryError("Shared memory version mismatch");
|
||||||
}
|
}
|
||||||
auto type = shm()->myDetectorType;
|
auto type = detector_shm()->myDetectorType;
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3877,13 +3876,13 @@ int slsDetector::getChanRegs(double *retval) {
|
|||||||
sls_detector_module *myMod = getModule();
|
sls_detector_module *myMod = getModule();
|
||||||
|
|
||||||
if (myMod != nullptr) {
|
if (myMod != nullptr) {
|
||||||
//the original array has 0 initialized
|
//the original array has 0 initialized
|
||||||
if (myMod->chanregs) {
|
if (myMod->chanregs) {
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
retval[i] = (double)(myMod->chanregs[i] & TRIMBITMASK);
|
retval[i] = (double)(myMod->chanregs[i] & TRIMBITMASK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deleteModule(myMod);
|
deleteModule(myMod);
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
@ -4058,7 +4057,7 @@ std::string slsDetector::checkReceiverOnline() {
|
|||||||
auto receiver = sls::ClientSocket(true, detector_shm()->receiver_hostname, detector_shm()->receiverTCPPort);
|
auto receiver = sls::ClientSocket(true, detector_shm()->receiver_hostname, detector_shm()->receiverTCPPort);
|
||||||
detector_shm()->receiverOnlineFlag = ONLINE_FLAG;
|
detector_shm()->receiverOnlineFlag = ONLINE_FLAG;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
detector_shm()->receiverOnlineFlag = OFFLINE_FLAG;
|
detector_shm()->receiverOnlineFlag = OFFLINE_FLAG;
|
||||||
retval = detector_shm()->receiver_hostname;
|
retval = detector_shm()->receiver_hostname;
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -250,23 +250,23 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
|
|||||||
/**
|
/**
|
||||||
* Constructor called when creating new shared memory
|
* Constructor called when creating new shared memory
|
||||||
* @param type detector type
|
* @param type detector type
|
||||||
* @param multiId multi detector shared memory id
|
* @param multi_id multi detector shared memory id
|
||||||
* @param id sls detector id (position in detectors list)
|
* @param id sls detector id (position in detectors list)
|
||||||
* @param verify true to verify if shared memory version matches existing one
|
* @param verify true to verify if shared memory version matches existing one
|
||||||
*/
|
*/
|
||||||
explicit slsDetector(detectorType type,
|
explicit slsDetector(detectorType type,
|
||||||
int multiId = 0,
|
int multi_id = 0,
|
||||||
int id = 0,
|
int det_id = 0,
|
||||||
bool verify = true);
|
bool verify = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor called when opening existing shared memory
|
* Constructor called when opening existing shared memory
|
||||||
* @param multiId multi detector shared memory id
|
* @param multi_id multi detector shared memory id
|
||||||
* @param id sls detector id (position in detectors list)
|
* @param id sls detector id (position in detectors list)
|
||||||
* @param verify true to verify if shared memory version matches existing one
|
* @param verify true to verify if shared memory version matches existing one
|
||||||
*/
|
*/
|
||||||
explicit slsDetector(int multiId = 0,
|
explicit slsDetector(int multi_id = 0,
|
||||||
int id = 0,
|
int det_id = 0,
|
||||||
bool verify = true);
|
bool verify = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -300,10 +300,10 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
|
|||||||
* If this is called, must take care to update
|
* If this is called, must take care to update
|
||||||
* multiSlsDetectors thisMultiDetector->numberofDetectors
|
* multiSlsDetectors thisMultiDetector->numberofDetectors
|
||||||
* avoiding creating the constructor classes and mapping
|
* avoiding creating the constructor classes and mapping
|
||||||
* @param multiId multi detector Id
|
* @param multi_id multi detector Id
|
||||||
* @param slsId slsDetectorId or position of slsDetector in detectors list
|
* @param slsId slsDetectorId or position of slsDetector in detectors list
|
||||||
*/
|
*/
|
||||||
static void freeSharedMemory(int multiId, int slsId);
|
static void freeSharedMemory(int multi_id, int slsId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free shared memory and delete shared memory structure
|
* Free shared memory and delete shared memory structure
|
||||||
@ -1616,21 +1616,21 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
|
|||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Get Detector Type from Shared Memory (opening shm without verifying size)
|
* Get Detector Type from Shared Memory (opening shm without verifying size)
|
||||||
* @param multiId multi detector Id
|
* @param multi_id multi detector Id
|
||||||
* @param verify true to verify if shm size matches existing one
|
* @param verify true to verify if shm size matches existing one
|
||||||
* @returns detector type
|
* @returns detector type
|
||||||
*/
|
*/
|
||||||
detectorType getDetectorTypeFromShm(int multiId, bool verify = true);
|
detectorType getDetectorTypeFromShm(int multi_id, bool verify = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize shared memory
|
* Initialize shared memory
|
||||||
* @param created true if shared memory must be created, else false to open
|
* @param created true if shared memory must be created, else false to open
|
||||||
* @param type type of detector
|
* @param type type of detector
|
||||||
* @param multiId multi detector Id
|
* @param multi_id multi detector Id
|
||||||
* @param verify true to verify if shm size matches existing one
|
* @param verify true to verify if shm size matches existing one
|
||||||
* @returns true if the shared memory was created now
|
* @returns true if the shared memory was created now
|
||||||
*/
|
*/
|
||||||
void initSharedMemory(detectorType type, int multiId, bool verify = true);
|
void initSharedMemory(detectorType type, int multi_id, bool verify = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets detector parameters depending detector type
|
* Sets detector parameters depending detector type
|
||||||
@ -1733,7 +1733,7 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
|
|||||||
int writeSettingsFile(const std::string &fname, sls_detector_module& mod);
|
int writeSettingsFile(const std::string &fname, sls_detector_module& mod);
|
||||||
|
|
||||||
/** slsDetector Id or position in the detectors list */
|
/** slsDetector Id or position in the detectors list */
|
||||||
int detId;
|
const int detId;
|
||||||
|
|
||||||
/** Shared Memory object */
|
/** Shared Memory object */
|
||||||
sls::SharedMemory<sharedSlsDetector> detector_shm{0,0};
|
sls::SharedMemory<sharedSlsDetector> detector_shm{0,0};
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include "sls_detector_defs.h"
|
#include "sls_detector_defs.h"
|
||||||
|
#include "sls_detector_exceptions.h"
|
||||||
|
#include "logger.h"
|
||||||
namespace sls {
|
namespace sls {
|
||||||
|
|
||||||
ClientSocket::ClientSocket(const bool isRx, const std::string &host, uint16_t port) : DataSocket(socket(AF_INET, SOCK_STREAM, 0)), isReceiver(isRx) {
|
ClientSocket::ClientSocket(const bool isRx, const std::string &host, uint16_t port) : DataSocket(socket(AF_INET, SOCK_STREAM, 0)), isReceiver(isRx) {
|
||||||
@ -17,7 +19,8 @@ ClientSocket::ClientSocket(const bool isRx, const std::string &host, uint16_t po
|
|||||||
hints.ai_flags |= AI_CANONNAME;
|
hints.ai_flags |= AI_CANONNAME;
|
||||||
|
|
||||||
if (getaddrinfo(host.c_str(), NULL, &hints, &result) != 0) {
|
if (getaddrinfo(host.c_str(), NULL, &hints, &result) != 0) {
|
||||||
throw std::runtime_error("ClientSocket ERROR: cannot decode host\n");
|
std::string msg = "ClientSocket ERROR: decode host:" + host + " on port " + std::to_string(port)+ "\n";
|
||||||
|
throw std::runtime_error(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO! Erik, results could have multiple entries do we need to loop through them?
|
//TODO! Erik, results could have multiple entries do we need to loop through them?
|
||||||
@ -29,7 +32,9 @@ ClientSocket::ClientSocket(const bool isRx, const std::string &host, uint16_t po
|
|||||||
|
|
||||||
if (::connect(getSocketId(), (struct sockaddr *)&serverAddr, sizeof(serverAddr)) != 0) {
|
if (::connect(getSocketId(), (struct sockaddr *)&serverAddr, sizeof(serverAddr)) != 0) {
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
throw std::runtime_error("ClientSocket ERROR: cannot connect to host\n");
|
std::string msg = "ClientSocket ERROR: cannot connect to host:" + host + " on port " + std::to_string(port)+ "\n";
|
||||||
|
FILE_LOG(logERROR) << msg;
|
||||||
|
throw SocketError(msg);
|
||||||
}
|
}
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user