Newer
Older
/*
* connection_client.hpp
*
* Created on: 03.01.2021
* Author: doralitze
*/
#pragma once
#include <functional>
#include <memory>
#include <string>
#if EAGAIN != EWOULDBLOCK
#define EAGAIN_WRAPPER ((errno != EAGAIN) && (errno != EWOULDBLOCK))
#else
#define EAGAIN_WRAPPER (errno != EAGAIN)
#endif
template<class client>
class connection_client : public std::enable_shared_from_this<client> {
/**
* This function type accepts a reference to the incomming data string which it may not alter
* and may not return any data.
*/
typedef std::function<void(const std::string&)> incomming_data_cb;
connection_client() : in_data_cb{} {};
/**
* Use this method to send data to the other endpoint.
*/
virtual void write_data(const std::string& data) = 0;
/**
* Use this method in order to register your callback function that should be
* called when the client got data to process.
* @param cb The callback function to register [void(std::string data)]
*/
inline void set_incomming_data_callback(const incomming_data_cb& cb) {
this->in_data_cb = cb;
};