자잘한 수정, 이제 다른 소켓으로 쓰기 요청 할 수 있을 듯

This commit is contained in:
2025-05-03 13:59:04 +09:00
parent 181d30ff28
commit f765c163bf
12 changed files with 512 additions and 310 deletions

View File

@@ -4,6 +4,8 @@
#include "Socket/TCPSocket.hpp"
#include "Socket/Log.hpp"
#include <functional>
#include <vector>
#include "precomp.hpp"
#ifndef _WIN32
@@ -25,10 +27,11 @@ class IOCP;
struct IOCPPASSINDATA {
OVERLAPPED overlapped;
TCPSocket socket;
std::shared_ptr<TCPSocket> socket;
char buf[1501];
int recvbytes;
int sendbytes;
std::uint32_t recvbytes;
std::uint32_t sendbytes;
std::uint32_t transfrredbytes;
WSABUF wsabuf;
IOCP* IOCPInstance;
};
@@ -38,17 +41,18 @@ 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);
spdlog::trace("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));
spdlog::debug("Client disconnected. [{}]", (std::string)(data->socket->remoteAddr));
delete data;
threadPool->enqueueJob(iocpWather, completionPort_, callback);
return;
}
data->transfrredbytes = cbTransfrred;
threadPool->enqueueJob(callback, data);
threadPool->enqueueJob(iocpWather, completionPort_, callback);
};
@@ -63,7 +67,7 @@ public:
return;
}
spdlog::info("reading on tid: {} [{}]", tid, (std::string)iocpData->socket.remoteAddr);
spdlog::trace("reading on tid: {} [{}]", tid, (std::string)iocpData->socket.remoteAddr);
int redSize = 0;
int packetSize = iocpData->wsabuf.len;
@@ -73,7 +77,7 @@ public:
redSize = iocpData->socket.recv(iocpData->buf, packetSize - totalRedSize, 0);
if (redSize <= 0) {
spdlog::info("Client disconnected. [{}]", (std::string)iocpData->socket.remoteAddr);
spdlog::debug("Client disconnected. [{}]", (std::string)iocpData->socket.remoteAddr);
::epoll_ctl(epollfd, EPOLL_CTL_DEL, iocpData->socket.sock, NULL);
delete iocpData;
return;
@@ -91,13 +95,13 @@ public:
int totalSentSize = 0;
int sentSize = 0;
spdlog::info("Sending to: [{}]", (std::string)iocpData->socket.remoteAddr);
spdlog::trace("Sending to: [{}]", (std::string)iocpData->socket.remoteAddr);
while (totalSentSize < packetSize) {
sentSize = iocpData->socket.send(iocpData->buf, packetSize - totalSentSize, 0);
if (sentSize <= 0) {
spdlog::info("Client disconnected. [{}]", (std::string)iocpData->socket.remoteAddr);
spdlog::debug("Client disconnected. [{}]", (std::string)iocpData->socket.remoteAddr);
::epoll_ctl(epollfd, EPOLL_CTL_DEL, iocpData->socket.sock, NULL);
delete iocpData;
return;
@@ -112,7 +116,7 @@ public:
struct epoll_event events[FD_SETSIZE];
pthread_t tid = pthread_self();
spdlog::debug("epoll waiting on {}", tid);
spdlog::trace("epoll waiting on {}", tid);
int nready = ::epoll_wait(epollfd, events, FD_SETSIZE, -1);
for (int i=0; i<nready; i++) {
@@ -164,8 +168,8 @@ public:
void registerSocket(Chattr::IOCPPASSINDATA* data);
int recv(Chattr::IOCPPASSINDATA* data);
int send(Chattr::IOCPPASSINDATA* data, int __flags);
int recv(Chattr::IOCPPASSINDATA* data, int bufferCount);
int send(Chattr::IOCPPASSINDATA* data, int bufferCount, int __flags);
private:
struct Chattr::WSAManager wsaManager;

View File

@@ -23,9 +23,9 @@ public:
int recvfrom(void *__restrict __buf, size_t __n, int __flags, struct Address& __addr);
int sendto(const void *__buf, size_t __n, int __flags, struct Address __addr);
Socket(const Socket&) = delete;
Socket(const Socket&);
Socket(Socket&&) noexcept;
Socket& operator=(const Socket&) = delete;
Socket& operator=(const Socket&);
Socket& operator=(Socket&&) noexcept;
struct Address bindAddr = {};