tinyrpc/includes/net/tcp/tcp_connection.hpp

42 lines
832 B
C++
Raw Permalink Normal View History

2024-12-25 19:39:38 +08:00
#pragma once
2025-01-21 16:35:26 +08:00
#include "abstract_coder.hpp"
#include "coroutine.hpp"
2024-12-25 19:39:38 +08:00
#include "fd_event.hpp"
#include "reactor.hpp"
#include "tcp_buffer.hpp"
2025-01-21 16:35:26 +08:00
namespace tinyrpc {
class TcpServer;
2024-12-25 19:39:38 +08:00
class TcpConnection {
public:
enum class State{
Disconnected,
Connected
};
2025-01-21 16:35:26 +08:00
2024-12-25 19:39:38 +08:00
public:
2025-01-21 16:35:26 +08:00
TcpConnection(int fd, Reactor& reactor, TcpServer& ser);
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{};
2025-01-21 16:35:26 +08:00
Reactor& m_reactor;
TcpServer& m_server;
2024-12-25 19:39:38 +08:00
};
}