specify detector or receiver in error

This commit is contained in:
Erik Frojdh
2019-03-20 17:41:46 +01:00
parent 83e43b1bcf
commit c16f9b8c30

View File

@ -10,7 +10,8 @@
#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) {
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;
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;
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);
}
@ -27,19 +29,21 @@ ClientSocket::ClientSocket(const bool isRx, const std::string &host, uint16_t po
// struct sockaddr_in serverAddr {};
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(port);
memcpy((char *)&serverAddr.sin_addr.s_addr,
&((struct sockaddr_in *)result->ai_addr)->sin_addr, sizeof(in_addr_t));
memcpy((char *)&serverAddr.sin_addr.s_addr, &((struct sockaddr_in *)result->ai_addr)->sin_addr,
sizeof(in_addr_t));
if (::connect(getSocketId(), (struct sockaddr *)&serverAddr, sizeof(serverAddr)) != 0) {
freeaddrinfo(result);
std::string msg = "ClientSocket: cannot connect to host:" + host + " on port " + std::to_string(port) + "\n";
FILE_LOG(logERROR) << msg;
const std::string name{(isReceiver ? "Receiver" : "Detector")};
std::string msg = "ClientSocket: Cannot connect to " + name + ":" + host + " on port " +
std::to_string(port) + "\n";
throw SocketError(msg);
}
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;
sendData(&fnum, sizeof(fnum));
sendData(args, args_size);