#ifndef GDRIDD_LISTENER_H
|
#define GDRIDD_LISTENER_H
|
|
#include <set>
|
#include <mutex>
|
#include "dgrid.h"
|
#include "dgrid_thread.h"
|
#include <sys/socket.h>
|
|
namespace DGrid {
|
|
class DGriddChild;
|
|
class DGriddListener: public DGriddThread
|
{
|
public:
|
DGriddListener();
|
virtual ~DGriddListener();
|
|
// start on local UNIX socket
|
bool start(const std::string& path);
|
// start on TCP port
|
bool start(const std::string& addr, const uint16_t port);
|
void childFinished(DGriddThread*);
|
virtual void showStats();
|
uint16_t connectedClients();
|
|
protected:
|
virtual void run();
|
void acceptConnection(int listenfd);
|
virtual DGriddChild* createChild() = 0;
|
|
private:
|
void stopChilds();
|
void cleanupFinished();
|
void setListenAddress(const std::string& path);
|
void setListenAddress(const std::string& addr, const uint16_t port);
|
|
sa_family_t address_family;
|
std::string sock_path;
|
std::string inet_addr;
|
uint16_t inet_port;
|
std::mutex childs_mutex;
|
std::set<DGriddThread*> childs;
|
|
// std::mutex childs_finished_mutex;
|
// std::set<DGriddThread*> childs_finished;
|
};
|
|
class DGriddClientListener: public DGriddListener
|
{
|
public:
|
DGriddClientListener();
|
virtual ~DGriddClientListener();
|
virtual void showStats();
|
|
protected:
|
virtual DGriddChild* createChild();
|
};
|
|
class DGriddNodeListener: public DGriddListener
|
{
|
public:
|
DGriddNodeListener();
|
virtual ~DGriddNodeListener();
|
virtual void showStats();
|
|
protected:
|
virtual DGriddChild* createChild();
|
};
|
|
|
} // namespace DGrid
|
|
#endif // GDRIDD_LISTENER_H
|