mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 10:07:59 +02:00
zmqip now uint
This commit is contained in:
@ -3,10 +3,13 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <netdb.h>
|
||||
#include <string>
|
||||
#include <numeric>
|
||||
#include <string>
|
||||
namespace sls {
|
||||
|
||||
/* Base class for TCP socket, this is used to send data between detector, client
|
||||
and receiver. Specific protocols inherit from this class.*/
|
||||
|
||||
class DataSocket {
|
||||
public:
|
||||
DataSocket(int socketId);
|
||||
@ -14,27 +17,28 @@ class DataSocket {
|
||||
virtual ~DataSocket();
|
||||
DataSocket &operator=(DataSocket &&move) noexcept;
|
||||
void swap(DataSocket &other) noexcept;
|
||||
|
||||
//No copy since the class manage the underlying socket
|
||||
DataSocket(const DataSocket &) = delete;
|
||||
DataSocket &operator=(DataSocket const &) = delete;
|
||||
int getSocketId() const { return socketId_; }
|
||||
|
||||
|
||||
int Send(const void *buffer, size_t size);
|
||||
template <typename T> int Send(T &&data) {
|
||||
return Send(&data, sizeof(data));
|
||||
}
|
||||
|
||||
// Trick to send all
|
||||
// Variadic template to send all arguments
|
||||
template <class... Args> int SendAll(Args &&... args) {
|
||||
auto l = std::initializer_list<int>{Send(args)...};
|
||||
auto sum = std::accumulate(begin(l), end(l), 0);
|
||||
return sum;
|
||||
}
|
||||
|
||||
int Receive(void *buffer, size_t size);
|
||||
|
||||
template <typename T> int Receive(T &arg) {
|
||||
return Receive(&arg, sizeof(arg));
|
||||
}
|
||||
|
||||
template <typename T> T Receive() {
|
||||
T arg;
|
||||
Receive(&arg, sizeof(arg));
|
||||
@ -52,12 +56,4 @@ class DataSocket {
|
||||
int socketId_ = -1;
|
||||
};
|
||||
|
||||
int ConvertHostnameToInternetAddress(const char *const hostname,
|
||||
struct ::addrinfo **res);
|
||||
int ConvertInternetAddresstoIpString(struct ::addrinfo *res, char *ip,
|
||||
const int ipsize);
|
||||
|
||||
struct ::sockaddr_in
|
||||
ConvertHostnameToInternetAddress(const std::string &hostname);
|
||||
|
||||
}; // namespace sls
|
||||
|
@ -56,7 +56,7 @@ class MacAddr {
|
||||
constexpr uint64_t uint64() const noexcept { return addr_; }
|
||||
};
|
||||
|
||||
uint32_t HostnameToIp(const char *hostname);
|
||||
IpAddr HostnameToIp(const char *hostname);
|
||||
std::string IpToInterfaceName(const std::string& ip);
|
||||
MacAddr InterfaceNameToMac(std::string inf);
|
||||
|
||||
|
Reference in New Issue
Block a user