This commit is contained in:
malloc 2018-07-24 16:41:22 -05:00
parent 8e56fec1a9
commit c5c1441287
5 changed files with 43 additions and 38 deletions

View file

@ -26,6 +26,7 @@ private:
class MasterClientPool : public Pool<MasterClient> {
protected:
void SetupQueries(Queries* queries) override;
bool ProcessClient(MasterClient& client, const Queries* queries) override {
// TODO implement
return true;

View file

@ -1,2 +1,9 @@
#include "master.hpp"
/** MASTERCLIENTPOOL CODE **/
void sosc::MasterClientPool::SetupQueries(Queries *queries) {
}
/** MASTERCLIENT CODE **/

View file

@ -9,14 +9,14 @@ namespace sosc {
class SlaveClient {
public:
SlaveClient(const ScapeConnection& client);
explicit SlaveClient(const ScapeConnection& client);
private:
ScapeConnection sock;
};
class SlaveClientPool : Pool<SlaveClient*> {
class SlaveClientPool : public Pool<SlaveClient> {
protected:
bool ProcessClient(SlaveClient*& client) override {
bool ProcessClient(SlaveClient& client, const Queries* queries) override {
// TODO implement
return true;
}

View file

@ -19,36 +19,20 @@
#include "hosts/master.hpp"
#include "hosts/slave.hpp"
bool master_intra(uint16_t port);
bool master_client(uint16_t port);
bool slave(uint16_t port);
bool master_intra(uint16_t port, const sosc::poolinfo_t& info);
bool master_client(uint16_t port, const sosc::poolinfo_t& info);
bool slave(uint16_t port, const sosc::poolinfo_t& info);
int main(int argc, char **argv) {
sosc::ScapeServer server;
sosc::ScapeConnection client;
std::string buffer;
if(!server.Listen(8080)) {
std::cout << "Listening failed." << std::endl;
if(argc < 2)
return -1;
if(argv[1][0] == 'm') {
master_intra(1234, sosc::poolinfo_t());
} else {
slave(1234, sosc::poolinfo_t());
}
std::cout << "Listening ..." << std::endl;
bool check = server.Accept(&client);
std::cout << "Shaking ..." << std::endl;
bool loop = true;
while(loop) {
if(!client.Handshaked())
client.Handshake();
else {
sosc::Packet pck;
client.Receive(&pck, true);
std::cout << pck.RegionCount() << std::endl;
}
}
server.Close();
return 0;
}
@ -71,17 +55,29 @@ bool master_intra(uint16_t port, const sosc::poolinfo_t& info) {
return true;
}
bool master_client(uint16_t port, sosc::poolinfo_t info) {
/*
auto pooler = std::thread([&]() {
});
*/
bool master_client(uint16_t port, const sosc::poolinfo_t& info) {
using namespace sosc;
return true;
}
bool slave(uint16_t port, sosc::poolinfo_t info) {
bool slave(uint16_t port, const sosc::poolinfo_t& info) {
using namespace sosc;
ScapeServer server;
ScapeConnection client;
if(!server.Listen(port))
return false;
SlaveClientPool pool;
pool.Configure(info);
pool.Start();
while(server.Accept(&client))
pool.AddClient(SlaveClient(client));
pool.Stop();
return true;
}

View file

@ -21,6 +21,7 @@ bool sosc::ScapeConnection::IsCiphered() const {
void sosc::ScapeConnection::SetCipher(cgc::Cipher* cipher) {
this->cipher = cipher;
cipher->Parse(&this->buffer);
}
int sosc::ScapeConnection::Handshake() {