diff --git a/Client/src/ClientManager/ClientManager.cpp b/Client/src/ClientManager/ClientManager.cpp index 087846f..9dba800 100644 --- a/Client/src/ClientManager/ClientManager.cpp +++ b/Client/src/ClientManager/ClientManager.cpp @@ -400,11 +400,11 @@ void ClientManager::run() { std::cout << "Commads:" << std::endl; std::cout << "/w : Send direct message to specified user" << std::endl; std::cout << "/join : Enter specified room" << std::endl; - std::cout << "/leave : Exit current room" << std::endl; + std::cout << "/exit : Exit current room" << std::endl; std::cout << "/create : 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_) { diff --git a/include/Socket/IOCP.hpp b/include/Socket/IOCP.hpp index d8ef7ed..db988d3 100644 --- a/include/Socket/IOCP.hpp +++ b/include/Socket/IOCP.hpp @@ -270,7 +270,7 @@ public: threadPool->enqueueJob(callback, data); } }; - static void iocpWatcher(ThreadPool* threadPool, int epollfd, std::function callback) { + static void iocpWatcher(ThreadPool* threadPool, int epollfd, int epollDetroyerFd, std::function 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 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 }