최종본

This commit is contained in:
2025-05-10 19:44:45 +09:00
parent be6417cd40
commit 8b486008fa
2 changed files with 14 additions and 8 deletions

View File

@@ -400,11 +400,11 @@ void ClientManager::run() {
std::cout << "Commads:" << std::endl;
std::cout << "/w <username> : Send direct message to specified user" << std::endl;
std::cout << "/join <roomname> : Enter specified room" << std::endl;
std::cout << "/leave : Exit current room" << std::endl;
std::cout << "/exit : Exit current room" << std::endl;
std::cout << "/create <roomname> : Create room" << std::endl;
std::cout << "/userlist : Print all registred users" << std::endl;
std::cout << "/roomlist : Print all registred rooms" << std::endl;
std::cout << "/exit : Terminate this program" << std::endl;
std::cout << "/quit : Terminate this program" << std::endl;
while (true) {
std::string input;
@@ -453,7 +453,7 @@ void ClientManager::run() {
}
joinRoom(myID_, findRoomId_[roomName]);
}
else if (tokens[0] == "/leave") {
else if (tokens[0] == "/exit") {
if (!inRoom_) {
resourceMutex_.lock();
messageQueue_.push("You are not in any room");
@@ -470,7 +470,7 @@ void ClientManager::run() {
getUserList();
else if (tokens[0] == "/roomlist")
getRoomList();
else if (tokens[0] == "/exit") {
else if (tokens[0] == "/quit") {
break;
}
else if (inRoom_) {

View File

@@ -270,7 +270,7 @@ public:
threadPool->enqueueJob(callback, data);
}
};
static void iocpWatcher(ThreadPool* threadPool, int epollfd, std::function<void(ThreadPool*, IOCPPASSINDATA*)> callback) {
static void iocpWatcher(ThreadPool* threadPool, int epollfd, int epollDetroyerFd, std::function<void(ThreadPool*, IOCPPASSINDATA*)> callback) {
struct epoll_event events[FD_SETSIZE];
pthread_t tid = pthread_self();
@@ -280,6 +280,9 @@ public:
struct epoll_event current_event = events[i];
if (current_event.events & EPOLLIN) {
if (current_event.data.fd == epollDetroyerFd) {
return;
}
std::function<void(ThreadPool*, IOCPPASSINDATA*)> task(callback);
threadPool->enqueueJob(socketReader, current_event, epollfd, task);
}
@@ -290,7 +293,7 @@ public:
if (--nready <= 0)
break;
}
threadPool->enqueueJob(iocpWatcher, epollfd, callback);
threadPool->enqueueJob(iocpWatcher, epollfd, epollDetroyerFd, callback);
};
#endif
@@ -307,7 +310,10 @@ public:
#elif __linux__
epollfd_ = ::epoll_create(1);
epollDetroyerFd = ::eventfd(0, EFD_NONBLOCK);
::epoll_ctl(epollfd_, EPOLL_CTL_ADD, epollDetroyerFd, NULL);
struct epoll_event ev;
ev.events = EPOLLIN;
ev.data.fd = epollDetroyerFd;
::epoll_ctl(epollfd_, EPOLL_CTL_ADD, epollDetroyerFd, &ev);
#endif
auto boundFunc = [callback = std::move(callback)](ThreadPool* __IOCPThread, IOCPPASSINDATA* data) mutable {
callback(__IOCPThread, data);
@@ -327,7 +333,7 @@ public:
#elif __linux__
__IOCPThread->respawnWorker(__IOCPThread->threadCount + 1);
spdlog::info("Spawning 1 Epoll Waiter...");
__IOCPThread->enqueueJob(iocpWatcher, epollfd_, boundFunc);
__IOCPThread->enqueueJob(iocpWatcher, epollfd_, epollDetroyerFd, boundFunc);
#endif
}