2024-12-25 19:37:28 +08:00
|
|
|
#pragma once
|
2025-01-10 15:00:50 +08:00
|
|
|
#include "reactor.hpp"
|
2024-12-25 19:37:28 +08:00
|
|
|
#include "tcp_connection.hpp"
|
|
|
|
#include <thread>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
|
|
|
|
namespace tinyrpc {
|
|
|
|
|
|
|
|
class IOThread {
|
|
|
|
public:
|
|
|
|
IOThread();
|
|
|
|
~IOThread();
|
2025-01-10 15:00:50 +08:00
|
|
|
void addClient(int fd);
|
|
|
|
static IOThread* getThisIoThread();
|
|
|
|
// void removeFd(int fd);
|
|
|
|
Reactor* getReactor() {return m_reactor;}
|
2024-12-25 19:37:28 +08:00
|
|
|
private:
|
|
|
|
void mainFunc();
|
|
|
|
private:
|
|
|
|
std::unordered_map<int, TcpConnection*> m_clients;
|
|
|
|
std::thread m_thread;
|
2025-01-10 15:00:50 +08:00
|
|
|
Reactor* m_reactor{nullptr};
|
2024-12-25 19:37:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|