windows 살짝 분리!

This commit is contained in:
2025-05-02 12:42:21 +09:00
parent 40d522e755
commit 925d3874c8
3 changed files with 38 additions and 10 deletions

View File

@@ -7,6 +7,12 @@
namespace Chattr {
#ifndef _WIN32
typedef struct _OVERLAPPED {
char dummy;
} OVERLAPPED;
#endif
struct IOCPPASSINDATA {
OVERLAPPED overlapped;
TCPSocket socket;
@@ -18,6 +24,7 @@ struct IOCPPASSINDATA {
class IOCP {
public:
#ifdef _WIN32
static void iocpWather(ThreadPool* threadPool, HANDLE completionPort_, std::function<void(ThreadPool*, IOCPPASSINDATA*)> callback) {
DWORD tid = GetCurrentThreadId();
spdlog::debug("Waiting IO to complete on TID: {}.", tid);
@@ -34,6 +41,24 @@ public:
threadPool->enqueueJob(callback, data);
threadPool->enqueueJob(iocpWather, completionPort_, callback);
};
#elif __linux__
static void iocpWather(ThreadPool* threadPool, HANDLE completionPort_, std::function<void(ThreadPool*, IOCPPASSINDATA*)> callback) {
DWORD tid = GetCurrentThreadId();
spdlog::debug("Waiting IO to complete on TID: {}.", tid);
IOCPPASSINDATA* data;
SOCKET sock;
DWORD cbTransfrred;
int retVal = GetQueuedCompletionStatus(completionPort_, &cbTransfrred, (PULONG_PTR)&sock, (LPOVERLAPPED*)&data, INFINITE);
if (retVal == 0 || cbTransfrred == 0) {
spdlog::info("Client disconnected. [{}]", (std::string)(data->socket.remoteAddr));
delete data;
threadPool->enqueueJob(iocpWather, completionPort_, callback);
return;
}
threadPool->enqueueJob(callback, data);
threadPool->enqueueJob(iocpWather, completionPort_, callback);
};
#endif
template<typename _Callable>
void init(ThreadPool* __IOCPThread, _Callable&& callback) {
@@ -42,10 +67,12 @@ public:
completionPort_ = ::CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0);
if (completionPort_ == NULL)
log::critical("CreateIoCompletionPort()");
#elif __linux__
#endif
auto boundFunc = [callback = std::move(callback)](ThreadPool* __IOCPThread, IOCPPASSINDATA* data) mutable {
callback(__IOCPThread, data);
};
};
int tCount = __IOCPThread->threadCount;
@@ -58,15 +85,12 @@ public:
std::function<void(ThreadPool*, IOCPPASSINDATA*)> task(boundFunc);
__IOCPThread->enqueueJob(iocpWather, completionPort_, task);
}
#elif __linux__
#endif
}
void registerSocket(SOCKET sock);
int recv(void* __restrict __buf, size_t __n, int __flags);
int send(const void* __buf, size_t __n, int __flags);
int recv(Chattr::IOCPPASSINDATA* data);
int send(Chattr::IOCPPASSINDATA* data, int __flags);
private:
struct Chattr::WSAManager wsaManager;