zmqip now uint

This commit is contained in:
Erik Frojdh
2019-06-06 18:17:04 +02:00
parent c86a1e7d48
commit 170aca0e1f
6 changed files with 90 additions and 176 deletions

View File

@ -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

View File

@ -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);