squid broadcasting
This commit is contained in:
parent
9baa9a73a4
commit
a4c150cc06
12 changed files with 87 additions and 40 deletions
9
server/src/ctx/master.hpp
Normal file
9
server/src/ctx/master.hpp
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef SOSC_CTX_MASTER_H
|
||||||
|
#define SOSC_CTX_MASTER_H
|
||||||
|
|
||||||
|
namespace sosc {
|
||||||
|
namespace ctx {
|
||||||
|
|
||||||
|
}}
|
||||||
|
|
||||||
|
#endif
|
2
server/src/ctx/master_client.cpp
Normal file
2
server/src/ctx/master_client.cpp
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#include "master.hpp"
|
||||||
|
|
2
server/src/ctx/master_intra.cpp
Normal file
2
server/src/ctx/master_intra.cpp
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#include "master.hpp"
|
||||||
|
|
2
server/src/ctx/slave.cpp
Normal file
2
server/src/ctx/slave.cpp
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#include "slave.hpp"
|
||||||
|
|
14
server/src/ctx/slave.hpp
Normal file
14
server/src/ctx/slave.hpp
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef SOSC_CTX_SLAVE_H
|
||||||
|
#define SOSC_CTX_SLAVE_H
|
||||||
|
|
||||||
|
namespace sosc {
|
||||||
|
namespace ctx {
|
||||||
|
class SlaveContext {
|
||||||
|
public:
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
}}
|
||||||
|
|
||||||
|
#endif
|
|
@ -17,7 +17,7 @@ private:
|
||||||
|
|
||||||
class MasterClientPool : public Pool<MasterClient> {
|
class MasterClientPool : public Pool<MasterClient> {
|
||||||
protected:
|
protected:
|
||||||
bool ProcessClient(MasterClient* client) override;
|
bool ProcessClient(MasterClient client) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** MASTER -> SLAVE **/
|
/** MASTER -> SLAVE **/
|
||||||
|
@ -31,7 +31,7 @@ private:
|
||||||
|
|
||||||
class MasterIntraPool : public Pool<MasterIntra> {
|
class MasterIntraPool : public Pool<MasterIntra> {
|
||||||
protected:
|
protected:
|
||||||
bool ProcessClient(MasterIntra* client) override;
|
bool ProcessClient(MasterIntra client) override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,9 @@
|
||||||
#include "master.hpp"
|
#include "master.hpp"
|
||||||
|
|
||||||
|
sosc::MasterIntra::MasterIntra(IntraClient client) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sosc::MasterIntraPool::ProcessClient(MasterIntra client) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ private:
|
||||||
ScapeConnection sock;
|
ScapeConnection sock;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SlavePool : public Pool<SlaveClient> {
|
class SlavePool : public Pool<SlaveClient*> {
|
||||||
protected:
|
protected:
|
||||||
bool ProcessClient(SlaveClient* client) override;
|
bool ProcessClient(SlaveClient* client) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,12 +19,6 @@
|
||||||
#include "hosts/master.hpp"
|
#include "hosts/master.hpp"
|
||||||
#include "hosts/slave.hpp"
|
#include "hosts/slave.hpp"
|
||||||
|
|
||||||
/*class User;
|
|
||||||
class Test : sosc::Pool<User> {
|
|
||||||
protected:
|
|
||||||
bool ProcessClient(User* client) override;
|
|
||||||
};*/
|
|
||||||
|
|
||||||
bool master_intra(uint16_t port);
|
bool master_intra(uint16_t port);
|
||||||
bool master_client(uint16_t port);
|
bool master_client(uint16_t port);
|
||||||
bool slave(uint16_t port);
|
bool slave(uint16_t port);
|
||||||
|
|
|
@ -17,6 +17,10 @@ public:
|
||||||
return this->client_open;
|
return this->client_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline net::IpAddress GetIpAddress() const {
|
||||||
|
return this->client.GetIpAddress();
|
||||||
|
}
|
||||||
|
|
||||||
inline void Close() {
|
inline void Close() {
|
||||||
this->client_open = false;
|
this->client_open = false;
|
||||||
this->client.Close();
|
this->client.Close();
|
||||||
|
|
|
@ -30,18 +30,19 @@ template<class T>
|
||||||
class Pool {
|
class Pool {
|
||||||
public:
|
public:
|
||||||
Pool();
|
Pool();
|
||||||
|
Pool(const Pool&) = delete;
|
||||||
void Configure(const poolinfo_t& info);
|
void Configure(const poolinfo_t& info);
|
||||||
|
|
||||||
void Start();
|
void Start();
|
||||||
bool AddClient(T* client);
|
bool AddClient(T client);
|
||||||
int ClientCount() const;
|
int ClientCount();
|
||||||
inline bool IsOpen() const {
|
inline bool IsOpen() const {
|
||||||
return this->is_open;
|
return this->is_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stop();
|
void Stop();
|
||||||
protected:
|
protected:
|
||||||
virtual bool ProcessClient(T* client) = 0;
|
virtual bool ProcessClient(T client) = 0;
|
||||||
private:
|
private:
|
||||||
bool IsStackFull(int stackCount) const;
|
bool IsStackFull(int stackCount) const;
|
||||||
bool CanAddStack() const;
|
bool CanAddStack() const;
|
||||||
|
@ -49,10 +50,12 @@ private:
|
||||||
class Stack {
|
class Stack {
|
||||||
public:
|
public:
|
||||||
Stack(Pool<T>* pool);
|
Stack(Pool<T>* pool);
|
||||||
|
Stack(const Stack&) = delete;
|
||||||
|
|
||||||
void Start();
|
void Start();
|
||||||
|
|
||||||
void AddClient(T* client);
|
void AddClient(T client);
|
||||||
int ClientCount() const;
|
int ClientCount();
|
||||||
inline bool IsOpen() const {
|
inline bool IsOpen() const {
|
||||||
return this->is_open;
|
return this->is_open;
|
||||||
}
|
}
|
||||||
|
@ -61,19 +64,19 @@ private:
|
||||||
private:
|
private:
|
||||||
void StackThread();
|
void StackThread();
|
||||||
|
|
||||||
std::thread thread;
|
std::thread* thread;
|
||||||
Pool<T> *pool;
|
Pool<T>* pool;
|
||||||
bool is_open;
|
bool is_open;
|
||||||
bool is_running;
|
bool is_running;
|
||||||
|
|
||||||
std::list<T*> clients;
|
std::list<T> clients;
|
||||||
std::mutex clients_mtx;
|
std::mutex clients_mtx;
|
||||||
};
|
};
|
||||||
|
|
||||||
poolinfo_t info;
|
poolinfo_t info;
|
||||||
bool is_open;
|
bool is_open;
|
||||||
|
|
||||||
std::vector<Stack> stacks;
|
std::vector<Stack*> stacks;
|
||||||
|
|
||||||
friend class Stack;
|
friend class Stack;
|
||||||
};
|
};
|
||||||
|
@ -86,25 +89,25 @@ Pool<T>::Pool() {
|
||||||
template<class T>
|
template<class T>
|
||||||
void Pool<T>::Configure(const poolinfo_t& info) {
|
void Pool<T>::Configure(const poolinfo_t& info) {
|
||||||
this->info = info;
|
this->info = info;
|
||||||
this->is_running = false;
|
this->is_open = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void Pool<T>::Start() {
|
void Pool<T>::Start() {
|
||||||
if(this->is_running)
|
if(this->is_open)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(int i = 0; i < this->info.initial_count; ++i) {
|
for(int i = 0; i < this->info.initial_count; ++i) {
|
||||||
this->stacks.push_back(Stack(this));
|
this->stacks.push_back(new Stack(this));
|
||||||
this->stacks.back().Start();
|
this->stacks.back()->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->is_running = true;
|
this->is_open = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
bool Pool<T>::IsStackFull(int stackCount) const {
|
bool Pool<T>::IsStackFull(int stackCount) const {
|
||||||
poolinfo_t *info = &this->info;
|
const poolinfo_t *info = &this->info;
|
||||||
return info->max_size != -1
|
return info->max_size != -1
|
||||||
&& stackCount <
|
&& stackCount <
|
||||||
info->initial_size
|
info->initial_size
|
||||||
|
@ -120,8 +123,8 @@ bool Pool<T>::CanAddStack() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
bool Pool<T>::AddClient(T* client) {
|
bool Pool<T>::AddClient(T client) {
|
||||||
if(!this->is_running)
|
if(!this->is_open)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(this->info.max_total != -1)
|
if(this->info.max_total != -1)
|
||||||
|
@ -132,17 +135,17 @@ bool Pool<T>::AddClient(T* client) {
|
||||||
Stack* lowestStack = nullptr;
|
Stack* lowestStack = nullptr;
|
||||||
for(auto i = this->stacks.begin(); i != this->stacks.end(); ++i) {
|
for(auto i = this->stacks.begin(); i != this->stacks.end(); ++i) {
|
||||||
int thisCount;
|
int thisCount;
|
||||||
if((thisCount = i->ClientCount()) > lowestCount) {
|
if((thisCount = (*i)->ClientCount()) > lowestCount) {
|
||||||
lowestCount = thisCount;
|
lowestCount = thisCount;
|
||||||
lowestStack = &(*i);
|
lowestStack = *i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lowestStack != nullptr && !this->IsStackFull(lowestCount))
|
if(lowestStack != nullptr && !this->IsStackFull(lowestCount))
|
||||||
lowestStack->AddClient(client);
|
lowestStack->AddClient(client);
|
||||||
else if(this->CanAddStack()) {
|
else if(this->CanAddStack()) {
|
||||||
this->stacks.push_back(Stack(this));
|
this->stacks.push_back(new Stack(this));
|
||||||
this->stacks.back().AddClient(client);
|
this->stacks.back()->AddClient(client);
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -150,26 +153,28 @@ bool Pool<T>::AddClient(T* client) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
int Pool<T>::ClientCount() const {
|
int Pool<T>::ClientCount() {
|
||||||
if(!this->is_running)
|
if(!this->is_open)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for(auto i = this->stacks.begin(); i != this->stacks.end(); ++i)
|
for(auto i = this->stacks.begin(); i != this->stacks.end(); ++i)
|
||||||
count += i->ClientCount();
|
count += (*i)->ClientCount();
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void Pool<T>::Stop() {
|
void Pool<T>::Stop() {
|
||||||
if(!this->is_running)
|
if(!this->is_open)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(auto i = this->stacks.begin(); i != this->stacks.end(); ++i)
|
for(auto i = this->stacks.begin(); i != this->stacks.end(); ++i) {
|
||||||
i->Stop();
|
(*i)->Stop();
|
||||||
|
delete *i;
|
||||||
|
}
|
||||||
|
|
||||||
stacks->clear();
|
stacks->clear();
|
||||||
this->is_running = false;
|
this->is_open = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
@ -186,11 +191,13 @@ void Pool<T>::Stack::Start() {
|
||||||
|
|
||||||
this->is_open = true;
|
this->is_open = true;
|
||||||
this->is_running = true;
|
this->is_running = true;
|
||||||
this->thread = std::thread(this->StackThread, this);
|
this->thread = new std::thread([&]() {
|
||||||
|
this->StackThread();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void Pool<T>::Stack::AddClient(T* client) {
|
void Pool<T>::Stack::AddClient(T client) {
|
||||||
if(!this->is_open || !this->is_running)
|
if(!this->is_open || !this->is_running)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -200,7 +207,7 @@ void Pool<T>::Stack::AddClient(T* client) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
int Pool<T>::Stack::ClientCount() const {
|
int Pool<T>::Stack::ClientCount() {
|
||||||
if(!this->is_open || !this->is_running)
|
if(!this->is_open || !this->is_running)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -233,6 +240,8 @@ void Pool<T>::Stack::Stop() {
|
||||||
|
|
||||||
this->is_running = false;
|
this->is_running = false;
|
||||||
this->thread.join();
|
this->thread.join();
|
||||||
|
|
||||||
|
delete this->thread;
|
||||||
this->is_open = false;
|
this->is_open = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,10 @@ public:
|
||||||
return this->handshaked;
|
return this->handshaked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline net::IpAddress GetIpAddress() const {
|
||||||
|
return this->client.GetIpAddress();
|
||||||
|
}
|
||||||
|
|
||||||
inline void Close() {
|
inline void Close() {
|
||||||
this->client_open = false;
|
this->client_open = false;
|
||||||
this->client.Close();
|
this->client.Close();
|
||||||
|
|
Loading…
Reference in a new issue