자잘한 수정

This commit is contained in:
2025-05-02 12:59:59 +09:00
parent 925d3874c8
commit 7fabc98456
5 changed files with 41 additions and 25 deletions

View File

@@ -5,14 +5,23 @@
#include "Socket/Log.hpp"
#include <functional>
namespace Chattr {
#ifndef _WIN32
typedef struct _OVERLAPPED {
char dummy;
} OVERLAPPED;
typedef struct __WSABUF {
std::uint32_t len;
char *buf;
} WSABUF;
#endif
namespace Chattr {
class IOCP;
struct IOCPPASSINDATA {
OVERLAPPED overlapped;
TCPSocket socket;
@@ -20,6 +29,7 @@ struct IOCPPASSINDATA {
int recvbytes;
int sendbytes;
WSABUF wsabuf;
IOCP* IOCPInstance;
};
class IOCP {
@@ -42,21 +52,21 @@ public:
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);
static void iocpWather(ThreadPool* threadPool, 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
@@ -83,7 +93,7 @@ public:
spdlog::info("Set IOCP Worker count to: {}", tCount);
for (int i = 0; i < tCount; i++) {
std::function<void(ThreadPool*, IOCPPASSINDATA*)> task(boundFunc);
__IOCPThread->enqueueJob(iocpWather, completionPort_, task);
__IOCPThread->enqueueJob(iocpWather, task);
}
}
@@ -99,7 +109,7 @@ private:
#ifdef _WIN32
HANDLE completionPort_ = INVALID_HANDLE_VALUE;
#elif __linux__
int epollfd = -1;
#endif
};

View File

@@ -16,7 +16,7 @@ public:
operator SOCKET();
void set(const SOCKET __sock, int __domain);
int setsockopt(int level, int optname, const char FAR* optval, int optlen);
int setsockopt(int level, int optname, const char* optval, int optlen);
int bind(Address __addr);