유저 삭제 루틴을 IOCP로 넘김
This commit is contained in:
@@ -7,6 +7,11 @@
|
||||
namespace Chattr {
|
||||
|
||||
void ClientManager::_IOCPClient(Chattr::ThreadPool* thread, Chattr::IOCPPASSINDATA* data) {
|
||||
if (data->event == IOCPEVENT::QUIT) {
|
||||
delete data;
|
||||
return;
|
||||
}
|
||||
|
||||
Chattr::Packet pack;
|
||||
int packetSize = data->transferredbytes;
|
||||
|
||||
|
||||
@@ -5,6 +5,13 @@
|
||||
namespace Chattr {
|
||||
|
||||
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;
|
||||
int packetSize = data->transferredbytes;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Chattr {
|
||||
class IOCP;
|
||||
|
||||
enum class IOCPEVENT {
|
||||
ERROR_,
|
||||
QUIT,
|
||||
READ,
|
||||
WRITE
|
||||
};
|
||||
@@ -59,9 +59,11 @@ public:
|
||||
DWORD cbTransfrred;
|
||||
int retVal = GetQueuedCompletionStatus(completionPort_, &cbTransfrred, (PULONG_PTR)&sock, (LPOVERLAPPED*)&data, INFINITE);
|
||||
if (retVal == 0 || cbTransfrred == 0) {
|
||||
spdlog::debug("Client disconnected. [{}]", (std::string)(data->socket->remoteAddr));
|
||||
delete data;
|
||||
data->event = IOCPEVENT::QUIT;
|
||||
spdlog::debug("Disconnected. [{}]", (std::string)(data->socket->remoteAddr));
|
||||
threadPool->enqueueJob(callback, data);
|
||||
threadPool->enqueueJob(iocpWather, completionPort_, callback);
|
||||
// delete data;
|
||||
return;
|
||||
}
|
||||
data->transferredbytes = cbTransfrred;
|
||||
@@ -85,9 +87,11 @@ public:
|
||||
int rc = rootIocpData->socket->recv(peekBuffer, 1, MSG_PEEK);
|
||||
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);
|
||||
delete rootIocpData;
|
||||
threadPool->enqueueJob(callback, rootIocpData);
|
||||
// delete rootIocpData;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
@@ -123,9 +127,11 @@ public:
|
||||
return;
|
||||
}
|
||||
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);
|
||||
delete ptr;
|
||||
threadPool->enqueueJob(callback, ptr);
|
||||
// delete ptr;
|
||||
return;
|
||||
}
|
||||
totalRedSize += redSize;
|
||||
@@ -151,9 +157,11 @@ public:
|
||||
return;
|
||||
}
|
||||
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);
|
||||
delete ptr;
|
||||
threadPool->enqueueJob(callback, ptr);
|
||||
// delete ptr;
|
||||
return;
|
||||
}
|
||||
totalRedSize += redSize;
|
||||
@@ -196,9 +204,11 @@ public:
|
||||
spdlog::warn("buffer full");
|
||||
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);
|
||||
delete data;
|
||||
threadPool->enqueueJob(callback, data);
|
||||
// delete data;
|
||||
return;
|
||||
}
|
||||
totalSentSize += sentSize;
|
||||
|
||||
Reference in New Issue
Block a user