tinyrpc/includes/net/tcp/tcp_connection.hpp

41 lines
747 B
C++
Raw Normal View History

2024-12-25 19:39:38 +08:00
#pragma once
#include "coroutine.hpp"
2024-12-25 19:39:38 +08:00
#include "fd_event.hpp"
#include "reactor.hpp"
#include "tcp_buffer.hpp"
2024-12-25 19:39:38 +08:00
namespace tinyrpc {
class TcpConnection {
public:
enum class State{
Disconnected,
Connected
};
2024-12-25 19:39:38 +08:00
public:
TcpConnection(int fd, Reactor* reactor);
void mainLoopFun();
2024-12-25 19:39:38 +08:00
~TcpConnection();
private:
void input();
void output();
void process();
2024-12-25 19:39:38 +08:00
private:
FdEvent m_fdEvent;
Coroutine m_mainCoroutine;
State m_state{State::Connected};
TcpBuffer m_writeBuffer{};
TcpBuffer m_readBuffer{};
Reactor* m_reactor{};
2024-12-25 19:39:38 +08:00
// TODO .... 完善 TcpConnection 类
};
}