mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-26 08:10:02 +02:00
new socket overload
This commit is contained in:
parent
6759b2eeb8
commit
4e56107015
File diff suppressed because it is too large
Load Diff
@ -18,4 +18,16 @@ class ClientSocket : public DataSocket {
|
|||||||
bool isReceiver;
|
bool isReceiver;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ReceiverSocket : public ClientSocket {
|
||||||
|
public:
|
||||||
|
ReceiverSocket(const std::string &hostname, uint16_t port_number)
|
||||||
|
: ClientSocket(true, hostname, port_number){};
|
||||||
|
};
|
||||||
|
|
||||||
|
class DetectorSocket : public ClientSocket {
|
||||||
|
public:
|
||||||
|
DetectorSocket(const std::string &hostname, uint16_t port_number)
|
||||||
|
: ClientSocket(false, hostname, port_number){};
|
||||||
|
};
|
||||||
|
|
||||||
}; //namespace sls
|
}; //namespace sls
|
||||||
|
@ -42,6 +42,18 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DetectorError : public RuntimeError {
|
||||||
|
public:
|
||||||
|
DetectorError(std::string msg):RuntimeError(msg) {}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ReceiverError : public RuntimeError {
|
||||||
|
public:
|
||||||
|
ReceiverError(std::string msg):RuntimeError(msg) {}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#include "ClientSocket.h"
|
#include "ClientSocket.h"
|
||||||
|
#include "logger.h"
|
||||||
|
#include "sls_detector_defs.h"
|
||||||
|
#include "sls_detector_exceptions.h"
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include "sls_detector_defs.h"
|
#include <unistd.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) {
|
||||||
@ -19,8 +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) {
|
||||||
std::string msg = "ClientSocket ERROR: decode host:" + host + " on port " + std::to_string(port)+ "\n";
|
std::string msg = "ClientSocket ERROR: decode host:" + host + " on port " + std::to_string(port) + "\n";
|
||||||
throw std::runtime_error(msg);
|
throw SocketError(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?
|
||||||
@ -32,7 +32,7 @@ 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);
|
||||||
std::string msg = "ClientSocket ERROR: cannot connect to host:" + host + " on port " + std::to_string(port)+ "\n";
|
std::string msg = "ClientSocket ERROR: cannot connect to host:" + host + " on port " + std::to_string(port) + "\n";
|
||||||
FILE_LOG(logERROR) << msg;
|
FILE_LOG(logERROR) << msg;
|
||||||
throw SocketError(msg);
|
throw SocketError(msg);
|
||||||
}
|
}
|
||||||
@ -61,10 +61,18 @@ void ClientSocket::readReply(int &ret, void *retval, size_t retval_size) {
|
|||||||
// unrecognized function, do not ask for retval
|
// unrecognized function, do not ask for retval
|
||||||
if (strstr(mess, "Unrecognized Function") != nullptr)
|
if (strstr(mess, "Unrecognized Function") != nullptr)
|
||||||
unrecognizedFunction = true;
|
unrecognizedFunction = true;
|
||||||
|
|
||||||
|
//Do we need to know hostname here?
|
||||||
|
//In that case save it???
|
||||||
|
if (isReceiver) {
|
||||||
|
throw ReceiverError(mess);
|
||||||
|
} else {
|
||||||
|
throw DetectorError(mess);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// get retval
|
// get retval
|
||||||
if (!unrecognizedFunction)
|
if (!unrecognizedFunction)
|
||||||
receiveData(retval, retval_size);
|
receiveData(retval, retval_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
}; //namespace sls
|
}; //namespace sls
|
||||||
|
Loading…
x
Reference in New Issue
Block a user