Prepare new server types

This commit is contained in:
momo5502 2021-02-24 21:20:26 +01:00
parent e361a50c53
commit bdc26f6dce
3 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1,42 @@
#pragma once
#include <utils/cryptography.hpp>
class base_server
{
public:
base_server(std::string name)
: name_(std::move(name))
{
this->address_ = utils::cryptography::jenkins_one_at_a_time::compute(this->name_);
}
base_server(base_server&&) = delete;
base_server(const base_server&) = delete;
base_server& operator=(base_server&&) = delete;
base_server& operator=(const base_server&) = delete;
virtual ~base_server() = default;
const std::string& get_name() const
{
return this->name_;
}
uint32_t get_address() const
{
return this->address_;
}
virtual void frame()
{
}
virtual bool pending_data()
{
return false;
}
private:
std::string name_;
std::uint32_t address_ = 0;
};

View File

@ -0,0 +1,41 @@
#pragma once
#include "base_server.hpp"
#include <queue>
#include <utils/concurrency.hpp>
class tcp_server : public base_server
{
public:
using base_server::base_server;
int handle_input(const char* buf, int size)
{
return 0;
}
int handle_output(char* buf, int size)
{
return 0;
}
protected:
virtual void handle(const std::string& data) = 0;
void send(const std::string&)
{
}
private:
using stream_queue = std::queue<char>;
using data_queue = std::queue<std::string>;
utils::concurrency::container<data_queue> in_queue_;
utils::concurrency::container<stream_queue> out_queue_;
void frame() override
{
}
};