fixing illegal squids

This commit is contained in:
malloc 2018-08-10 10:30:03 -05:00
parent c5c1441287
commit 88ade7b66b
5 changed files with 73 additions and 41 deletions

View file

@ -3,7 +3,19 @@
namespace sosc { namespace sosc {
namespace ctx { namespace ctx {
class MasterClientContext {
public:
private:
};
class MasterIntraContext {
public:
private:
};
}} }}
#endif #endif

View file

@ -10,6 +10,8 @@
#include "../db/database.hpp" #include "../db/database.hpp"
#include "../ctx/master.hpp"
#include <vector> #include <vector>
namespace sosc { namespace sosc {
@ -24,10 +26,14 @@ private:
cgc::Cipher cipher; cgc::Cipher cipher;
}; };
class MasterClientPool : public Pool<MasterClient> { class MasterClientPool : public Pool<MasterClient, ctx::MasterClientContext> {
protected: protected:
void SetupQueries(Queries* queries) override; void SetupQueries(Queries* queries) override;
bool ProcessClient(MasterClient& client, const Queries* queries) override { bool ProcessClient(
MasterClient& client,
ctx::MasterClientContext* context,
const Queries* queries) override
{
// TODO implement // TODO implement
return true; return true;
} }
@ -79,10 +85,14 @@ private:
const Pool::Queries* queries; const Pool::Queries* queries;
}; };
class MasterIntraPool : public Pool<MasterIntra> { class MasterIntraPool : public Pool<MasterIntra, ctx::MasterIntraContext> {
protected: protected:
void SetupQueries(Queries* queries) override; void SetupQueries(Queries* queries) override;
bool ProcessClient(MasterIntra& client, const Queries* queries) override { bool ProcessClient
(MasterIntra& client,
ctx::MasterIntraContext* context,
const Queries* queries) override
{
return client.Process(queries); return client.Process(queries);
} }
}; };

View file

@ -3,6 +3,7 @@
#include "../sock/scapesock.hpp" #include "../sock/scapesock.hpp"
#include "../sock/pool.hpp" #include "../sock/pool.hpp"
#include "../ctx/slave.hpp"
namespace sosc { namespace sosc {
/** SLAVE -> CLIENT **/ /** SLAVE -> CLIENT **/
@ -14,9 +15,13 @@ private:
ScapeConnection sock; ScapeConnection sock;
}; };
class SlaveClientPool : public Pool<SlaveClient> { class SlaveClientPool : public Pool<SlaveClient, ctx::SlaveContext> {
protected: protected:
bool ProcessClient(SlaveClient& client, const Queries* queries) override { bool ProcessClient
(SlaveClient& client,
ctx::SlaveContext* context,
const Queries* queries) override
{
// TODO implement // TODO implement
return true; return true;
} }

View file

@ -27,7 +27,7 @@ typedef struct {
int tolerance = -1; int tolerance = -1;
} poolinfo_t; } poolinfo_t;
template<class T> template<class T, class U>
class Pool { class Pool {
public: public:
Pool(); Pool();
@ -46,14 +46,15 @@ public:
typedef std::vector<db::Query*> Queries; typedef std::vector<db::Query*> Queries;
protected: protected:
virtual void SetupQueries(Queries* queries) {}; virtual void SetupQueries(Queries* queries) {};
virtual bool ProcessClient(T& client, const Queries* queries) = 0; virtual bool ProcessClient
(T& client, U* context, const Queries* queries) = 0;
private: private:
bool IsStackFull(int stackCount) const; bool IsStackFull(int stackCount) const;
bool CanAddStack() const; bool CanAddStack() const;
class Stack { class Stack {
public: public:
explicit Stack(Pool<T>* pool); explicit Stack(Pool<T,U>* pool);
Stack(const Stack&) = delete; Stack(const Stack&) = delete;
void Start(); void Start();
@ -70,7 +71,7 @@ private:
Queries queries; Queries queries;
std::thread* thread; std::thread* thread;
Pool<T>* pool; Pool<T,U>* pool;
bool is_open; bool is_open;
bool is_running; bool is_running;
@ -81,25 +82,26 @@ private:
poolinfo_t info; poolinfo_t info;
bool is_open; bool is_open;
U context;
Queries queries; Queries queries;
std::vector<Stack*> stacks; std::vector<Stack*> stacks;
friend class Stack; friend class Stack;
}; };
template<class T> template<class T, class U>
Pool<T>::Pool() { Pool<T,U>::Pool() {
this->info = poolinfo_t(); this->info = poolinfo_t();
} }
template<class T> template<class T, class U>
void Pool<T>::Configure(const poolinfo_t& info) { void Pool<T,U>::Configure(const poolinfo_t& info) {
this->info = info; this->info = info;
this->is_open = false; this->is_open = false;
} }
template<class T> template<class T, class U>
void Pool<T>::Start() { void Pool<T,U>::Start() {
if(this->is_open) if(this->is_open)
return; return;
@ -113,8 +115,8 @@ void Pool<T>::Start() {
this->is_open = true; this->is_open = true;
} }
template<class T> template<class T, class U>
bool Pool<T>::IsStackFull(int stackCount) const { bool Pool<T,U>::IsStackFull(int stackCount) const {
const poolinfo_t *info = &this->info; const poolinfo_t *info = &this->info;
return info->max_size != -1 return info->max_size != -1
&& stackCount < && stackCount <
@ -124,14 +126,14 @@ bool Pool<T>::IsStackFull(int stackCount) const {
&& stackCount < info->max_size; && stackCount < info->max_size;
} }
template<class T> template<class T, class U>
bool Pool<T>::CanAddStack() const { bool Pool<T,U>::CanAddStack() const {
return this->info.max_count == -1 return this->info.max_count == -1
|| this->stacks.size() < this->info.max_count; || this->stacks.size() < this->info.max_count;
} }
template<class T> template<class T, class U>
bool Pool<T>::AddClient(T client) { bool Pool<T,U>::AddClient(T client) {
if(!this->is_open) if(!this->is_open)
return false; return false;
@ -160,8 +162,8 @@ bool Pool<T>::AddClient(T client) {
return true; return true;
} }
template<class T> template<class T, class U>
int Pool<T>::ClientCount() { int Pool<T,U>::ClientCount() {
if(!this->is_open) if(!this->is_open)
return 0; return 0;
@ -171,8 +173,8 @@ int Pool<T>::ClientCount() {
return count; return count;
} }
template<class T> template<class T, class U>
void Pool<T>::Stop() { void Pool<T,U>::Stop() {
if(!this->is_open) if(!this->is_open)
return; return;
@ -190,15 +192,15 @@ void Pool<T>::Stop() {
this->is_open = false; this->is_open = false;
} }
template<class T> template<class T, class U>
Pool<T>::Stack::Stack(Pool<T>* pool) { Pool<T,U>::Stack::Stack(Pool<T,U>* pool) {
this->pool = pool; this->pool = pool;
this->is_open = false; this->is_open = false;
this->is_running = false; this->is_running = false;
} }
template<class T> template<class T, class U>
void Pool<T>::Stack::Start() { void Pool<T,U>::Stack::Start() {
if(this->is_open || this->is_running) if(this->is_open || this->is_running)
return; return;
@ -212,8 +214,8 @@ void Pool<T>::Stack::Start() {
}); });
} }
template<class T> template<class T, class U>
void Pool<T>::Stack::AddClient(T client) { void Pool<T,U>::Stack::AddClient(T client) {
if(!this->is_open || !this->is_running) if(!this->is_open || !this->is_running)
return; return;
@ -222,8 +224,8 @@ void Pool<T>::Stack::AddClient(T client) {
this->clients_mtx.unlock(); this->clients_mtx.unlock();
} }
template<class T> template<class T, class U>
int Pool<T>::Stack::ClientCount() { int Pool<T,U>::Stack::ClientCount() {
if(!this->is_open || !this->is_running) if(!this->is_open || !this->is_running)
return 0; return 0;
@ -234,8 +236,8 @@ int Pool<T>::Stack::ClientCount() {
return count; return count;
} }
template<class T> template<class T, class U>
void Pool<T>::Stack::StackThread() { void Pool<T,U>::Stack::StackThread() {
while(this->is_running) { while(this->is_running) {
for(auto client = this->clients.begin(); for(auto client = this->clients.begin();
@ -246,15 +248,18 @@ void Pool<T>::Stack::StackThread() {
break; break;
this->clients_mtx.lock(); this->clients_mtx.lock();
if(!this->pool->ProcessClient(*client, &this->queries)) if(!this->pool->ProcessClient
(*client, &this->pool->context, &this->queries))
{
this->clients.erase(client); this->clients.erase(client);
}
this->clients_mtx.unlock(); this->clients_mtx.unlock();
} }
} }
} }
template<class T> template<class T, class U>
void Pool<T>::Stack::Stop() { void Pool<T,U>::Stack::Stop() {
if(!this->is_open || !this->is_running) if(!this->is_open || !this->is_running)
return; return;

View file

@ -10,8 +10,8 @@
#include "tcpsock.hpp" #include "tcpsock.hpp"
#define SOSC_SHAKE_ERR (-1) #define SOSC_SHAKE_ERR (-1)
#define SOSC_SHAKE_CONT 0 #define SOSC_SHAKE_CONT 0
#define SOSC_SHAKE_DONE 1 #define SOSC_SHAKE_DONE 1
namespace sosc { namespace sosc {
class ScapeConnection { class ScapeConnection {