46 lines
1.2 KiB
C++
46 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include "coroutine.hpp"
|
|
#include "fd_event.hpp"
|
|
#include "reactor.hpp"
|
|
#include "tcp_buffer.hpp"
|
|
|
|
namespace tinyrpc {
|
|
class TcpServer;
|
|
class AbstractTcpConnection {
|
|
public:
|
|
enum class State{
|
|
Disconnected,
|
|
Connected
|
|
};
|
|
// enum class Type{
|
|
// Server,
|
|
// Client
|
|
// };
|
|
|
|
public:
|
|
AbstractTcpConnection(int fd, Reactor& reactor, State state = State::Connected);
|
|
void clearClient();
|
|
void mainLoopFun();
|
|
State getState() {return m_state;}
|
|
// bool getResPackageData(const std::string& msg_req, std::shared_ptr<AbstractData>& pb_struct); //cli
|
|
virtual ~AbstractTcpConnection();
|
|
|
|
protected:
|
|
void input();
|
|
void output();
|
|
virtual void process() = 0;
|
|
|
|
protected:
|
|
FdEvent *m_fdEvent;
|
|
Coroutine m_mainCoroutine;
|
|
State m_state{State::Connected};
|
|
TcpBuffer m_writeBuffer{};
|
|
TcpBuffer m_readBuffer{};
|
|
Reactor& m_reactor;
|
|
// TcpServer& m_server;
|
|
// TcpClient& m_server;
|
|
// std::unordered_map<std::string, std::shared_ptr<AbstractData>> m_respond_datas; // cli
|
|
};
|
|
|
|
} |