2024-12-25 19:39:38 +08:00
|
|
|
#pragma once
|
|
|
|
|
2025-01-21 16:35:26 +08:00
|
|
|
#include "abstract_coder.hpp"
|
2025-01-10 15:00:50 +08:00
|
|
|
#include "coroutine.hpp"
|
2024-12-25 19:39:38 +08:00
|
|
|
#include "fd_event.hpp"
|
2025-01-10 15:00:50 +08:00
|
|
|
#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 {
|
2025-01-10 15:00:50 +08:00
|
|
|
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();
|
2025-01-10 15:00:50 +08:00
|
|
|
void mainLoopFun();
|
2024-12-25 19:39:38 +08:00
|
|
|
|
|
|
|
~TcpConnection();
|
2025-01-10 15:00:50 +08:00
|
|
|
|
|
|
|
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;
|
2025-01-10 15:00:50 +08:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|