ADD: added clocalClientsClass and ping pong check
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
|
||||
|
||||
#include "WHISPER/whisper.hpp"
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <WHISPER/localClients.hpp>
|
||||
|
||||
#define ZMQ_BUILD_DRAFT_API 1
|
||||
#include <zmq.hpp>
|
||||
@@ -14,14 +16,14 @@
|
||||
namespace WHISPER {
|
||||
|
||||
|
||||
struct localClient{
|
||||
std::uint32_t port;
|
||||
std::string addr;
|
||||
std::uint32_t parentid;
|
||||
std::uint32_t id;
|
||||
zmq::socket_t clientSocket;
|
||||
std::time_t lastResponse;
|
||||
};
|
||||
// struct localClient{
|
||||
// std::uint32_t port;
|
||||
// std::string addr;
|
||||
// std::uint32_t parentid;
|
||||
// std::uint32_t id;
|
||||
// zmq::socket_t clientSocket;
|
||||
// std::time_t lastResponse;
|
||||
// };
|
||||
|
||||
|
||||
|
||||
@@ -50,9 +52,13 @@ namespace WHISPER {
|
||||
std::shared_ptr<zmq::socket_t> loopbackSocket = nullptr;
|
||||
/// vector of local udp clients
|
||||
std::list<std::shared_ptr<localClient>> localclients;
|
||||
|
||||
|
||||
|
||||
std::atomic<bool> stopClientChecker = false;
|
||||
std::atomic<bool> clientCheckerisRunning = false;
|
||||
|
||||
std::thread clientsCheckerThread;
|
||||
|
||||
|
||||
/**
|
||||
* @brief checks if the given port is already is use
|
||||
@@ -69,7 +75,11 @@ namespace WHISPER {
|
||||
void derivedUnsubscribe(std::string topic) override;
|
||||
|
||||
void sendToLocalClients(std::string msg,std::string topic);
|
||||
|
||||
|
||||
|
||||
void startChecker();
|
||||
void stopChecker();
|
||||
void checkClients();
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ message Message {
|
||||
uint32 sourceType = 3;
|
||||
uint32 sourceID = 4;
|
||||
uint32 parentID = 5;
|
||||
|
||||
|
||||
repeated google.protobuf.Any payload = 6;
|
||||
|
||||
|
||||
45
include/WHISPER/localClients.hpp
Normal file
45
include/WHISPER/localClients.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <zmq.hpp>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace WHISPER {
|
||||
|
||||
class localClient
|
||||
{
|
||||
public:
|
||||
localClient(std::uint32_t port,std::string addr,std::uint32_t parentid,std::uint32_t id, std::shared_ptr<zmq::socket_t> clientSocket);
|
||||
~localClient();
|
||||
|
||||
|
||||
|
||||
std::uint32_t getPort();
|
||||
std::string getAddr();
|
||||
std::uint32_t getParentid();
|
||||
std::uint32_t getID();
|
||||
|
||||
void addClientSocket(std::shared_ptr<zmq::socket_t> socket);
|
||||
std::shared_ptr<zmq::socket_t> getClientSocket();
|
||||
|
||||
std::time_t getLastResponse();
|
||||
void setLastResponse(std::time_t time);
|
||||
|
||||
private:
|
||||
|
||||
mutable std::mutex mx;
|
||||
|
||||
const std::uint32_t port_;
|
||||
const std::string addr_;
|
||||
const std::uint32_t parentid_;
|
||||
const std::uint32_t id_;
|
||||
std::shared_ptr<zmq::socket_t> clientSocket_;
|
||||
std::time_t lastResponse_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -46,7 +46,7 @@ namespace WHISPER
|
||||
std::atomic<bool> connected;
|
||||
|
||||
/// attribute identifying this service as a gateway and all packets should be forwarded
|
||||
bool gateway = false;
|
||||
std::atomic<bool> gateway = false;
|
||||
|
||||
/// variable for holding the receive thread identifier
|
||||
std::thread receiveThread;
|
||||
|
||||
Reference in New Issue
Block a user