자잘한 수정
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user