tinyrpc/includes/net/tcp/tcp_server.hpp

46 lines
1.1 KiB
C++
Raw Normal View History

2024-12-23 21:12:18 +08:00
#pragma once
2025-01-21 16:35:26 +08:00
#include "abstract_coder.hpp"
#include "abstract_dispatcher.hpp"
2024-12-23 21:12:18 +08:00
#include "coroutine.hpp"
#include "io_thread.hpp"
2024-12-23 21:12:18 +08:00
#include "net_address.hpp"
2025-01-14 15:27:15 +08:00
#include <cstdint>
2024-12-25 19:40:27 +08:00
// #include "reactor.hpp"
2024-12-23 21:12:18 +08:00
namespace tinyrpc {
class TcpAcceptor{
public:
TcpAcceptor(const NetAddress& netAddr);
void init();
int accept();
private:
int m_listenfd{-1};
NetAddress m_bindNetAddr;
};
class TcpServer{
public:
TcpServer();
TcpServer(const NetAddress& addr);
2025-01-14 15:27:15 +08:00
TcpServer(const std::string& ip, uint16_t port);
2025-01-21 16:35:26 +08:00
~TcpServer();
2024-12-23 21:12:18 +08:00
void start();
2025-01-21 16:35:26 +08:00
AbstractCoder& getCoder() {return *m_coder;}
AbstractDispatcher& getDispatcher() {return *m_dispatcher;}
2024-12-23 21:12:18 +08:00
private:
void mainAcceptCorFun();
private:
// Reactor* m_reactor{nullptr};
Coroutine m_accept_cor;
TcpAcceptor m_acceptor;
bool m_stop_accept{false};
// int m_conn_cnt{0};
2025-01-16 14:41:46 +08:00
// IOThread m_ioThread{};
IOThreadPool m_ioThreadPool{4};
2025-01-21 16:35:26 +08:00
AbstractCoder* m_coder{};
AbstractDispatcher* m_dispatcher{};
2024-12-23 21:12:18 +08:00
};
}