slave boob

This commit is contained in:
malloc 2018-04-16 16:56:02 -05:00
parent 8976efe29b
commit 9baa9a73a4
7 changed files with 117 additions and 5 deletions

View file

@ -0,0 +1,38 @@
#ifndef SOSC_HOST_MASTER_H
#define SOSC_HOST_MASTER_H
#include "../sock/intrasock.hpp"
#include "../sock/scapesock.hpp"
#include "../sock/pool.hpp"
namespace sosc {
/** MASTER -> CLIENT **/
class MasterClient {
public:
private:
ScapeConnection sock;
};
class MasterClientPool : public Pool<MasterClient> {
protected:
bool ProcessClient(MasterClient* client) override;
};
/** MASTER -> SLAVE **/
class MasterIntra {
public:
MasterIntra(IntraClient client);
private:
IntraClient sock;
};
class MasterIntraPool : public Pool<MasterIntra> {
protected:
bool ProcessClient(MasterIntra* client) override;
};
}
#endif

View file

@ -0,0 +1,2 @@
#include "master.hpp"

View file

@ -0,0 +1,2 @@
#include "master.hpp"

View file

@ -0,0 +1,5 @@
#include "slave.hpp"
bool sosc::SlavePool::ProcessClient(SlaveClient* client) {
return true;
}

View file

@ -0,0 +1,21 @@
#ifndef SOSC_HOST_SLAVE_H
#define SOSC_HOST_SLAVE_H
#include "../sock/scapesock.hpp"
#include "../sock/pool.hpp"
namespace sosc {
class SlaveClient {
public:
private:
ScapeConnection sock;
};
class SlavePool : public Pool<SlaveClient> {
protected:
bool ProcessClient(SlaveClient* client) override;
};
}
#endif

View file

@ -1,6 +1,7 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <ctime> #include <ctime>
#include <thread>
#include "sock/tcpsock.hpp" #include "sock/tcpsock.hpp"
#include "utils/string.hpp" #include "utils/string.hpp"
#include "utils/net.hpp" #include "utils/net.hpp"
@ -15,11 +16,18 @@
#include "sock/scapesock.hpp" #include "sock/scapesock.hpp"
#include "sock/pool.hpp" #include "sock/pool.hpp"
class User; #include "hosts/master.hpp"
#include "hosts/slave.hpp"
/*class User;
class Test : sosc::Pool<User> { class Test : sosc::Pool<User> {
protected: protected:
bool ProcessClient(User* client) override; bool ProcessClient(User* client) override;
}; };*/
bool master_intra(uint16_t port);
bool master_client(uint16_t port);
bool slave(uint16_t port);
int main(int argc, char **argv) { int main(int argc, char **argv) {
sosc::ScapeServer server; sosc::ScapeServer server;
@ -49,3 +57,33 @@ int main(int argc, char **argv) {
server.Close(); server.Close();
return 0; return 0;
} }
bool master_intra(uint16_t port, sosc::poolinfo_t info) {
using namespace sosc;
IntraServer server;
IntraClient client;
if(!server.Listen(port))
return false;
MasterIntraPool pool;
pool.Configure(info);
pool.Start();
while(server.Accept(&client))
pool.AddClient(MasterIntra(client));
return true;
}
bool master_client(uint16_t port, sosc::poolinfo_t info) {
/*
auto pooler = std::thread([&]() {
});
*/
}
bool slave(uint16_t port, sosc::poolinfo_t info) {
}

View file

@ -29,7 +29,8 @@ typedef struct {
template<class T> template<class T>
class Pool { class Pool {
public: public:
Pool(const poolinfo_t& info); Pool();
void Configure(const poolinfo_t& info);
void Start(); void Start();
bool AddClient(T* client); bool AddClient(T* client);
@ -78,7 +79,12 @@ private:
}; };
template<class T> template<class T>
Pool<T>::Pool(const poolinfo_t& info) { Pool<T>::Pool() {
this->info = poolinfo_t();
}
template<class T>
void Pool<T>::Configure(const poolinfo_t& info) {
this->info = info; this->info = info;
this->is_running = false; this->is_running = false;
} }
@ -116,7 +122,7 @@ 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_running)
return; return false;
if(this->info.max_total != -1) if(this->info.max_total != -1)
if(this->ClientCount() >= this->info.max_total) if(this->ClientCount() >= this->info.max_total)