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;
|
||||
};
|
||||
|
||||
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
|
||||
|
@ -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 "logger.h"
|
||||
#include "sls_detector_defs.h"
|
||||
#include "sls_detector_exceptions.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <stdexcept>
|
||||
#include "sls_detector_defs.h"
|
||||
#include "sls_detector_exceptions.h"
|
||||
#include "logger.h"
|
||||
#include <unistd.h>
|
||||
namespace sls {
|
||||
|
||||
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;
|
||||
|
||||
if (getaddrinfo(host.c_str(), NULL, &hints, &result) != 0) {
|
||||
std::string msg = "ClientSocket ERROR: decode host:" + host + " on port " + std::to_string(port)+ "\n";
|
||||
throw std::runtime_error(msg);
|
||||
std::string msg = "ClientSocket ERROR: decode host:" + host + " on port " + std::to_string(port) + "\n";
|
||||
throw SocketError(msg);
|
||||
}
|
||||
|
||||
//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) {
|
||||
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;
|
||||
throw SocketError(msg);
|
||||
}
|
||||
@ -61,6 +61,14 @@ void ClientSocket::readReply(int &ret, void *retval, size_t retval_size) {
|
||||
// unrecognized function, do not ask for retval
|
||||
if (strstr(mess, "Unrecognized Function") != nullptr)
|
||||
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
|
||||
if (!unrecognizedFunction)
|
||||
|
Loading…
x
Reference in New Issue
Block a user