Loading src/event/iocp.cpp +65 −45 Original line number Diff line number Diff line Loading @@ -154,42 +154,56 @@ namespace netplus { class EventWorker { private: static void start_read(client* ctx) { if (!ctx || !ctx->CurCon->csock) return; public: class EventWorker { public: /** * @brief Initiates an asynchronous read. * Uses the specialized WSA methods to interact with the IOCP. */ static void start_read(client* ctx) { con& c = *ctx->CurCon; // WICHTIG: Erzeuge ein temporäres buffer-Objekt für die WSA-Methoden // Temporary buffer for the overlapped operation buffer buf(ctx->readCtx.buffer, BLOCKSIZE); if (c.csock->_Type == sockettype::SSL) { static_cast<ssl*>(c.csock.get())->recvDataWSA(buf, 0); } else { if (c.csock->_Type == sockettype::TCP) { static_cast<tcp*>(c.csock.get())->recvDataWSA(buf, 0); } else if (c.csock->_Type == sockettype::UDP) { static_cast<udp*>(c.csock.get())->recvDataWSA(buf, 0); } else if (c.csock->_Type == sockettype::SSL) { // SSL recvDataWSA prepares the internal _rx_netbuf for ciphertext static_cast<ssl*>(c.csock.get())->recvDataWSA(buf, 0); } } /** * @brief Initiates an asynchronous write. * For SSL, this triggers encryption before the WSASend call. */ static void start_write(client* ctx) { con& c = *ctx->CurCon; if (c.SendData.empty()) return; size_t toSend = (std::min)((size_t)BLOCKSIZE, c.SendData.size()); size_t toSend = std::min<size_t>(BLOCKSIZE, c.SendData.size()); buffer out(c.SendData.data(), toSend); if (c.csock->_Type == sockettype::SSL) { static_cast<ssl*>(c.csock.get())->sendDataWSA(out, 0); } else { if (c.csock->_Type == sockettype::TCP) { static_cast<tcp*>(c.csock.get())->sendDataWSA(out, 0); } else if (c.csock->_Type == sockettype::UDP) { static_cast<udp*>(c.csock.get())->sendDataWSA(out, 0); } else if (c.csock->_Type == sockettype::SSL) { static_cast<ssl*>(c.csock.get())->sendDataWSA(out, 0); } } public: EventWorker(int tid, ULONG_PTR args, EventWorkerArgs* eargs) { while (event::Running) { DWORD dwBytesTransfered = 0; ULONG_PTR lpContext = 0; OVERLAPPED* pOverlapped = nullptr; // Wait for completion from the port BOOL bReturn = GetQueuedCompletionStatus(eargs->eviocp, &dwBytesTransfered, &lpContext, &pOverlapped, eargs->timeout); Loading @@ -199,9 +213,9 @@ namespace netplus { IO_CONTEXT* pIoCtx = CONTAINING_RECORD(pOverlapped, IO_CONTEXT, overlapped); con& c = *pClientContext->CurCon; // Handle Disconnection or Errors // Handle Disconnection or Reset (Fixes PR_CONNECT_RESET_ERROR logic) if (!bReturn || (bReturn && dwBytesTransfered == 0)) { eargs->event->DisconnectEvent(c, tid, args); eargs->event->DisconnectEvent(c, tid, (ULONG_PTR)eargs->args); delete pClientContext; continue; } Loading Loading @@ -258,11 +272,17 @@ namespace netplus { } catch (NetException& e) { std::cerr << "IOCP Worker Error: " << e.what() << std::endl; eargs->event->DisconnectEvent(c, tid, args); ======= } catch (NetException& e) { // Ignore non-critical notes, disconnect on actual errors if (e.getErrorType() != NetException::Note) { eargs->event->DisconnectEvent(c, tid, (ULONG_PTR)eargs->args); >>>>>>> 3c87b5c4fc8a9e4711e076e710a2dc74748f2b6f delete pClientContext; } } } friend class event; } }; event::event(socket* serversocket, int timeout) : _ServerSocket(serversocket) { Loading Loading
src/event/iocp.cpp +65 −45 Original line number Diff line number Diff line Loading @@ -154,42 +154,56 @@ namespace netplus { class EventWorker { private: static void start_read(client* ctx) { if (!ctx || !ctx->CurCon->csock) return; public: class EventWorker { public: /** * @brief Initiates an asynchronous read. * Uses the specialized WSA methods to interact with the IOCP. */ static void start_read(client* ctx) { con& c = *ctx->CurCon; // WICHTIG: Erzeuge ein temporäres buffer-Objekt für die WSA-Methoden // Temporary buffer for the overlapped operation buffer buf(ctx->readCtx.buffer, BLOCKSIZE); if (c.csock->_Type == sockettype::SSL) { static_cast<ssl*>(c.csock.get())->recvDataWSA(buf, 0); } else { if (c.csock->_Type == sockettype::TCP) { static_cast<tcp*>(c.csock.get())->recvDataWSA(buf, 0); } else if (c.csock->_Type == sockettype::UDP) { static_cast<udp*>(c.csock.get())->recvDataWSA(buf, 0); } else if (c.csock->_Type == sockettype::SSL) { // SSL recvDataWSA prepares the internal _rx_netbuf for ciphertext static_cast<ssl*>(c.csock.get())->recvDataWSA(buf, 0); } } /** * @brief Initiates an asynchronous write. * For SSL, this triggers encryption before the WSASend call. */ static void start_write(client* ctx) { con& c = *ctx->CurCon; if (c.SendData.empty()) return; size_t toSend = (std::min)((size_t)BLOCKSIZE, c.SendData.size()); size_t toSend = std::min<size_t>(BLOCKSIZE, c.SendData.size()); buffer out(c.SendData.data(), toSend); if (c.csock->_Type == sockettype::SSL) { static_cast<ssl*>(c.csock.get())->sendDataWSA(out, 0); } else { if (c.csock->_Type == sockettype::TCP) { static_cast<tcp*>(c.csock.get())->sendDataWSA(out, 0); } else if (c.csock->_Type == sockettype::UDP) { static_cast<udp*>(c.csock.get())->sendDataWSA(out, 0); } else if (c.csock->_Type == sockettype::SSL) { static_cast<ssl*>(c.csock.get())->sendDataWSA(out, 0); } } public: EventWorker(int tid, ULONG_PTR args, EventWorkerArgs* eargs) { while (event::Running) { DWORD dwBytesTransfered = 0; ULONG_PTR lpContext = 0; OVERLAPPED* pOverlapped = nullptr; // Wait for completion from the port BOOL bReturn = GetQueuedCompletionStatus(eargs->eviocp, &dwBytesTransfered, &lpContext, &pOverlapped, eargs->timeout); Loading @@ -199,9 +213,9 @@ namespace netplus { IO_CONTEXT* pIoCtx = CONTAINING_RECORD(pOverlapped, IO_CONTEXT, overlapped); con& c = *pClientContext->CurCon; // Handle Disconnection or Errors // Handle Disconnection or Reset (Fixes PR_CONNECT_RESET_ERROR logic) if (!bReturn || (bReturn && dwBytesTransfered == 0)) { eargs->event->DisconnectEvent(c, tid, args); eargs->event->DisconnectEvent(c, tid, (ULONG_PTR)eargs->args); delete pClientContext; continue; } Loading Loading @@ -258,11 +272,17 @@ namespace netplus { } catch (NetException& e) { std::cerr << "IOCP Worker Error: " << e.what() << std::endl; eargs->event->DisconnectEvent(c, tid, args); ======= } catch (NetException& e) { // Ignore non-critical notes, disconnect on actual errors if (e.getErrorType() != NetException::Note) { eargs->event->DisconnectEvent(c, tid, (ULONG_PTR)eargs->args); >>>>>>> 3c87b5c4fc8a9e4711e076e710a2dc74748f2b6f delete pClientContext; } } } friend class event; } }; event::event(socket* serversocket, int timeout) : _ServerSocket(serversocket) { Loading