Files
biboumi/louloulibs/network/socket_handler.hpp
T
louiz’ 0c8adc85f7 Move all the connect() logic from TCPSocketHandler into a subclass
This way, TCPSocketHandler only deal with the message sending/receiving, not
the connect() or anything else.  This will be used for implementing servers
(because when a client is accepted, we don’t need all the connect() and dns
resolution stuff).
2016-11-11 02:54:48 +01:00

44 lines
933 B
C++

#pragma once
#include <louloulibs.h>
#include <memory>
class Poller;
using socket_t = int;
class SocketHandler
{
public:
explicit SocketHandler(std::shared_ptr<Poller> poller, const socket_t socket):
poller(poller),
socket(socket)
{}
virtual ~SocketHandler() = default;
SocketHandler(const SocketHandler&) = delete;
SocketHandler(SocketHandler&&) = delete;
SocketHandler& operator=(const SocketHandler&) = delete;
SocketHandler& operator=(SocketHandler&&) = delete;
virtual void on_recv() = 0;
virtual void on_send() = 0;
virtual void connect() = 0;
virtual bool is_connected() const = 0;
virtual bool is_connecting() const = 0;
socket_t get_socket() const
{ return this->socket; }
protected:
/**
* A pointer to the poller that manages us, because we need to communicate
* with it.
*/
std::shared_ptr<Poller> poller;
/**
* The handled socket.
*/
socket_t socket;
};