tinyrpc/includes/net/tcp/tcp_connection.hpp

40 lines
729 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);
2025-01-14 15:27:15 +08:00
void clearClient();
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:
2025-01-14 15:27:15 +08:00
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
};
}