mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 18:17:59 +02:00
specify detector or receiver in error
This commit is contained in:
@ -10,7 +10,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.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) {
|
||||||
|
|
||||||
struct addrinfo hints, *result;
|
struct addrinfo hints, *result;
|
||||||
memset(&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
@ -19,7 +20,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 cannot decode host:" + host + " on port " + std::to_string(port) + "\n";
|
std::string msg =
|
||||||
|
"ClientSocket cannot decode host:" + host + " on port " + std::to_string(port) + "\n";
|
||||||
throw SocketError(msg);
|
throw SocketError(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,19 +29,21 @@ ClientSocket::ClientSocket(const bool isRx, const std::string &host, uint16_t po
|
|||||||
// struct sockaddr_in serverAddr {};
|
// struct sockaddr_in serverAddr {};
|
||||||
serverAddr.sin_family = AF_INET;
|
serverAddr.sin_family = AF_INET;
|
||||||
serverAddr.sin_port = htons(port);
|
serverAddr.sin_port = htons(port);
|
||||||
memcpy((char *)&serverAddr.sin_addr.s_addr,
|
memcpy((char *)&serverAddr.sin_addr.s_addr, &((struct sockaddr_in *)result->ai_addr)->sin_addr,
|
||||||
&((struct sockaddr_in *)result->ai_addr)->sin_addr, sizeof(in_addr_t));
|
sizeof(in_addr_t));
|
||||||
|
|
||||||
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: cannot connect to host:" + host + " on port " + std::to_string(port) + "\n";
|
const std::string name{(isReceiver ? "Receiver" : "Detector")};
|
||||||
FILE_LOG(logERROR) << msg;
|
std::string msg = "ClientSocket: Cannot connect to " + name + ":" + host + " on port " +
|
||||||
|
std::to_string(port) + "\n";
|
||||||
throw SocketError(msg);
|
throw SocketError(msg);
|
||||||
}
|
}
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ClientSocket::sendCommandThenRead(int fnum, void *args, size_t args_size, void *retval, size_t retval_size) {
|
int ClientSocket::sendCommandThenRead(int fnum, void *args, size_t args_size, void *retval,
|
||||||
|
size_t retval_size) {
|
||||||
int ret = slsDetectorDefs::FAIL;
|
int ret = slsDetectorDefs::FAIL;
|
||||||
sendData(&fnum, sizeof(fnum));
|
sendData(&fnum, sizeof(fnum));
|
||||||
sendData(args, args_size);
|
sendData(args, args_size);
|
||||||
|
Reference in New Issue
Block a user