일단은 멀티로 접속이 됨..
This commit is contained in:
@@ -24,80 +24,10 @@ typedef struct __WSABUF {
|
||||
|
||||
namespace Network {
|
||||
|
||||
class IOCP;
|
||||
struct IOCPPASSINDATA;
|
||||
|
||||
enum class IOCPEVENT { QUIT, READ, WRITE };
|
||||
|
||||
struct IOCPPASSINDATA {
|
||||
OVERLAPPED overlapped;
|
||||
IOCPEVENT event;
|
||||
std::shared_ptr<Socket> socket;
|
||||
std::uint32_t transferredbytes;
|
||||
WSABUF wsabuf;
|
||||
std::uint32_t bufsize;
|
||||
IOCP* IOCPInstance;
|
||||
#ifdef __linux__
|
||||
std::shared_ptr<std::queue<IOCPPASSINDATA*>> sendQueue;
|
||||
#endif
|
||||
|
||||
IOCPPASSINDATA(std::uint32_t bufsize) {
|
||||
std::memset(&overlapped, 0, sizeof(overlapped));
|
||||
event = IOCPEVENT::QUIT;
|
||||
socket = nullptr;
|
||||
transferredbytes = 0;
|
||||
this->bufsize = bufsize;
|
||||
IOCPInstance = nullptr;
|
||||
|
||||
wsabuf.buf = new char[bufsize];
|
||||
wsabuf.len = bufsize;
|
||||
}
|
||||
|
||||
/*IOCPPASSINDATA(const IOCPPASSINDATA& other) {
|
||||
if (this != &other) {
|
||||
std::memset(&overlapped, 0, sizeof(overlapped));
|
||||
event = other.event;
|
||||
socket = other.socket;
|
||||
ssl = other.ssl;
|
||||
transferredbytes = other.transferredbytes;
|
||||
bufsize = other.bufsize;
|
||||
IOCPInstance = other.IOCPInstance;
|
||||
#ifdef __linux__
|
||||
sendQueue = other.sendQueue;
|
||||
#endif
|
||||
wsabuf.buf = new char[other.bufsize];
|
||||
wsabuf.len = other.bufsize;
|
||||
std::memcpy(wsabuf.buf, other.wsabuf.buf, other.wsabuf.len);
|
||||
}
|
||||
}*/
|
||||
|
||||
~IOCPPASSINDATA() {
|
||||
if (wsabuf.buf != nullptr) delete[] wsabuf.buf;
|
||||
wsabuf.buf = nullptr;
|
||||
}
|
||||
|
||||
/*IOCPPASSINDATA& operator=(const IOCPPASSINDATA& other) {
|
||||
if (this != &other) {
|
||||
std::memset(&overlapped, 0, sizeof(overlapped));
|
||||
event = other.event;
|
||||
socket = other.socket;
|
||||
ssl = other.ssl;
|
||||
transferredbytes = other.transferredbytes;
|
||||
bufsize = other.bufsize;
|
||||
IOCPInstance = other.IOCPInstance;
|
||||
#ifdef __linux__
|
||||
sendQueue = other.sendQueue;
|
||||
#endif
|
||||
if (wsabuf.buf != nullptr) delete[] wsabuf.buf;
|
||||
wsabuf.buf = new char[other.bufsize];
|
||||
wsabuf.len = other.bufsize;
|
||||
std::memcpy(wsabuf.buf, other.wsabuf.buf, other.wsabuf.len);
|
||||
}
|
||||
return *this;
|
||||
}*/
|
||||
|
||||
IOCPPASSINDATA(const IOCPPASSINDATA& other) = delete;
|
||||
IOCPPASSINDATA& operator=(const IOCPPASSINDATA&) = delete;
|
||||
};
|
||||
std::list<char> DEFAULT_RECVALL_CALLBACK(utils::ThreadPool* th,
|
||||
IOCPPASSINDATA* data);
|
||||
|
||||
class IOCP {
|
||||
public:
|
||||
@@ -108,15 +38,26 @@ class IOCP {
|
||||
|
||||
void destruct();
|
||||
|
||||
void registerTCPSocket(Socket& sock, std::uint32_t bufsize);
|
||||
void registerUDPSocket(IOCPPASSINDATA* data, Address recv_addr);
|
||||
void registerSocket(std::shared_ptr<Socket> sock);
|
||||
|
||||
int recv(Socket& sock, std::vector<char>& data);
|
||||
std::future<std::vector<char>> recvFull(
|
||||
std::shared_ptr<Socket> sock, std::uint32_t bufsize);
|
||||
|
||||
std::future<std::list<char>> recv(
|
||||
std::shared_ptr<Socket> sock, std::uint32_t bufsize,
|
||||
std::function<std::list<char>(utils::ThreadPool*, IOCPPASSINDATA*)>
|
||||
callback = DEFAULT_RECVALL_CALLBACK);
|
||||
// data는 한 가지 소켓에 보내는 패킷만 담아야 합니다
|
||||
int send(Socket& sock, std::vector<char>& data);
|
||||
int send(std::shared_ptr<Socket> sock, std::vector<char>& data);
|
||||
|
||||
int GetRecvedBytes(SOCKET sock);
|
||||
|
||||
std::shared_ptr<std::list<IOCPPASSINDATA*>> GetSendQueue(SOCKET sock);
|
||||
std::shared_ptr<std::list<std::pair<std::vector<char>, std::uint32_t>>>
|
||||
GetRecvQueue(SOCKET sock);
|
||||
std::shared_ptr<std::mutex> GetSendQueueMutex(SOCKET sock);
|
||||
std::shared_ptr<std::mutex> GetRecvQueueMutex(SOCKET sock);
|
||||
|
||||
private:
|
||||
#ifdef _WIN32
|
||||
void iocpWatcher_(utils::ThreadPool* IOCPThread);
|
||||
@@ -124,12 +65,6 @@ class IOCP {
|
||||
|
||||
#endif
|
||||
|
||||
std::shared_ptr<std::list<IOCPPASSINDATA*>> GetSendQueue_(SOCKET sock);
|
||||
std::shared_ptr<std::list<std::pair<std::vector<char>, std::uint32_t>>>
|
||||
GetRecvQueue_(SOCKET sock);
|
||||
std::shared_ptr<std::mutex> GetSendQueueMutex_(SOCKET sock);
|
||||
std::shared_ptr<std::mutex> GetRecvQueueMutex_(SOCKET sock);
|
||||
|
||||
void packet_sender_(SOCKET sock);
|
||||
utils::ThreadPool* IOCPThread_;
|
||||
|
||||
@@ -182,4 +117,56 @@ class IOCP {
|
||||
#endif
|
||||
};
|
||||
|
||||
enum class IOCPEVENT { QUIT, READ, WRITE };
|
||||
|
||||
struct IOCPPASSINDATA {
|
||||
OVERLAPPED overlapped;
|
||||
IOCPEVENT event;
|
||||
std::shared_ptr<Socket> socket;
|
||||
std::uint32_t transferredbytes;
|
||||
WSABUF wsabuf;
|
||||
IOCP* IOCPInstance;
|
||||
std::packaged_task<std::list<char>(utils::ThreadPool*, IOCPPASSINDATA*)>
|
||||
callback;
|
||||
#ifdef __linux__
|
||||
std::shared_ptr<std::queue<IOCPPASSINDATA*>> sendQueue;
|
||||
#endif
|
||||
IOCPPASSINDATA(std::shared_ptr<Socket> socket, std::uint32_t bufsize,
|
||||
IOCP* IOCPInstance)
|
||||
: event(IOCPEVENT::QUIT),
|
||||
socket(socket),
|
||||
transferredbytes(0),
|
||||
IOCPInstance(IOCPInstance) {
|
||||
std::memset(&overlapped, 0, sizeof(overlapped));
|
||||
|
||||
wsabuf.buf = new char[bufsize];
|
||||
wsabuf.len = bufsize;
|
||||
}
|
||||
|
||||
IOCPPASSINDATA(
|
||||
std::shared_ptr<Socket> socket, std::uint32_t bufsize, IOCP* IOCPInstance,
|
||||
std::packaged_task<std::list<char>(utils::ThreadPool*, IOCPPASSINDATA*)>
|
||||
callback_)
|
||||
: event(IOCPEVENT::QUIT),
|
||||
socket(socket),
|
||||
transferredbytes(0),
|
||||
IOCPInstance(IOCPInstance),
|
||||
callback(std::move(callback_)) {
|
||||
std::memset(&overlapped, 0, sizeof(overlapped));
|
||||
|
||||
wsabuf.buf = new char[bufsize];
|
||||
wsabuf.len = bufsize;
|
||||
}
|
||||
|
||||
~IOCPPASSINDATA() {
|
||||
if (wsabuf.buf != nullptr) delete[] wsabuf.buf;
|
||||
wsabuf.buf = nullptr;
|
||||
}
|
||||
|
||||
IOCPPASSINDATA(const IOCPPASSINDATA& other) = delete;
|
||||
IOCPPASSINDATA& operator=(const IOCPPASSINDATA&) = delete;
|
||||
IOCPPASSINDATA(IOCPPASSINDATA&&) = default;
|
||||
IOCPPASSINDATA& operator=(IOCPPASSINDATA&&) = default;
|
||||
};
|
||||
|
||||
} // namespace Network
|
||||
|
||||
Reference in New Issue
Block a user