유저 삭제 루틴을 IOCP로 넘김

This commit is contained in:
2025-05-09 23:00:27 +09:00
parent 0aa312f67e
commit 74e73ccc23
3 changed files with 33 additions and 11 deletions

View File

@@ -7,6 +7,11 @@
namespace Chattr { namespace Chattr {
void ClientManager::_IOCPClient(Chattr::ThreadPool* thread, Chattr::IOCPPASSINDATA* data) { void ClientManager::_IOCPClient(Chattr::ThreadPool* thread, Chattr::IOCPPASSINDATA* data) {
if (data->event == IOCPEVENT::QUIT) {
delete data;
return;
}
Chattr::Packet pack; Chattr::Packet pack;
int packetSize = data->transferredbytes; int packetSize = data->transferredbytes;

View File

@@ -5,6 +5,13 @@
namespace Chattr { namespace Chattr {
void ServerManager::_IOCPClient(Chattr::ThreadPool* thread, Chattr::IOCPPASSINDATA* data) { void ServerManager::_IOCPClient(Chattr::ThreadPool* thread, Chattr::IOCPPASSINDATA* data) {
if (data->event == IOCPEVENT::QUIT) {
if (userSocket2UID_.find(data->socket) != userSocket2UID_.end())
deleteUser(userSocket2UID_[data->socket]);
delete data;
return;
}
Chattr::Packet pack; Chattr::Packet pack;
int packetSize = data->transferredbytes; int packetSize = data->transferredbytes;

View File

@@ -28,7 +28,7 @@ namespace Chattr {
class IOCP; class IOCP;
enum class IOCPEVENT { enum class IOCPEVENT {
ERROR_, QUIT,
READ, READ,
WRITE WRITE
}; };
@@ -59,9 +59,11 @@ public:
DWORD cbTransfrred; DWORD cbTransfrred;
int retVal = GetQueuedCompletionStatus(completionPort_, &cbTransfrred, (PULONG_PTR)&sock, (LPOVERLAPPED*)&data, INFINITE); int retVal = GetQueuedCompletionStatus(completionPort_, &cbTransfrred, (PULONG_PTR)&sock, (LPOVERLAPPED*)&data, INFINITE);
if (retVal == 0 || cbTransfrred == 0) { if (retVal == 0 || cbTransfrred == 0) {
spdlog::debug("Client disconnected. [{}]", (std::string)(data->socket->remoteAddr)); data->event = IOCPEVENT::QUIT;
delete data; spdlog::debug("Disconnected. [{}]", (std::string)(data->socket->remoteAddr));
threadPool->enqueueJob(callback, data);
threadPool->enqueueJob(iocpWather, completionPort_, callback); threadPool->enqueueJob(iocpWather, completionPort_, callback);
// delete data;
return; return;
} }
data->transferredbytes = cbTransfrred; data->transferredbytes = cbTransfrred;
@@ -85,9 +87,11 @@ public:
int rc = rootIocpData->socket->recv(peekBuffer, 1, MSG_PEEK); int rc = rootIocpData->socket->recv(peekBuffer, 1, MSG_PEEK);
if (rc > 0); if (rc > 0);
else if (rc == 0) { else if (rc == 0) {
spdlog::debug("Client disconnected. [{}]", (std::string)(rootIocpData->socket->remoteAddr)); rootIocpData->event = IOCPEVENT::QUIT;
spdlog::debug("Disconnected. [{}]", (std::string)(rootIocpData->socket->remoteAddr));
::epoll_ctl(epollfd, EPOLL_CTL_DEL, rootIocpData->socket->sock, NULL); ::epoll_ctl(epollfd, EPOLL_CTL_DEL, rootIocpData->socket->sock, NULL);
delete rootIocpData; threadPool->enqueueJob(callback, rootIocpData);
// delete rootIocpData;
return; return;
} }
else { else {
@@ -123,9 +127,11 @@ public:
return; return;
} }
else if (redSize == 0) { else if (redSize == 0) {
spdlog::debug("Client disconnected. [{}]", (std::string)ptr->socket->remoteAddr); ptr->event = IOCPEVENT::QUIT;
spdlog::debug("Disconnected. [{}]", (std::string)(ptr->socket->remoteAddr));
::epoll_ctl(epollfd, EPOLL_CTL_DEL, ptr->socket->sock, NULL); ::epoll_ctl(epollfd, EPOLL_CTL_DEL, ptr->socket->sock, NULL);
delete ptr; threadPool->enqueueJob(callback, ptr);
// delete ptr;
return; return;
} }
totalRedSize += redSize; totalRedSize += redSize;
@@ -151,9 +157,11 @@ public:
return; return;
} }
else if (redSize == 0) { else if (redSize == 0) {
spdlog::debug("Client disconnected. [{}]", (std::string)ptr->socket->remoteAddr); ptr->event = IOCPEVENT::QUIT;
spdlog::debug("Disconnected. [{}]", (std::string)(ptr->socket->remoteAddr));
::epoll_ctl(epollfd, EPOLL_CTL_DEL, ptr->socket->sock, NULL); ::epoll_ctl(epollfd, EPOLL_CTL_DEL, ptr->socket->sock, NULL);
delete ptr; threadPool->enqueueJob(callback, ptr);
// delete ptr;
return; return;
} }
totalRedSize += redSize; totalRedSize += redSize;
@@ -196,9 +204,11 @@ public:
spdlog::warn("buffer full"); spdlog::warn("buffer full");
continue; continue;
} }
spdlog::error("send() [{}]", strerror(errno)); data->event = IOCPEVENT::QUIT;
spdlog::debug("Disconnected. [{}]", (std::string)(data->socket->remoteAddr));
::epoll_ctl(epollfd, EPOLL_CTL_DEL, data->socket->sock, NULL); ::epoll_ctl(epollfd, EPOLL_CTL_DEL, data->socket->sock, NULL);
delete data; threadPool->enqueueJob(callback, data);
// delete data;
return; return;
} }
totalSentSize += sentSize; totalSentSize += sentSize;