Loading src/event/iocp.cpp +39 −40 Changes for src/event/iocp.cpp: 39 added lines, 40 removed lines. Original line number Diff line number Diff line Loading @@ -219,53 +219,17 @@ namespace netplus { }; class EventWorker { public: EventWorker(int tid, ULONG_PTR args, EventWorkerArgs* eargs) { while (event::Running) { OVERLAPPED* pOverlapped = nullptr; ULONG_PTR lpContext = 0; DWORD dwBytesTransfered = 0; bool bReturn = GetQueuedCompletionStatus( eargs->eviocp, &dwBytesTransfered, &lpContext, &pOverlapped, eargs->timeout); if (lpContext == 0) { continue; } client* pClientContext = reinterpret_cast<client*>(lpContext); std::unique_ptr<con> &curCon = pClientContext->CurCon; // Check for I/O completion errors or graceful disconnects if (!bReturn || (bReturn && dwBytesTransfered == 0)) { DWORD dwError = GetLastError(); if (dwError != WAIT_TIMEOUT && dwError != ERROR_OPERATION_ABORTED) { NetException exp; exp[NetException::Error] << "I/O operation failed or client disconnected. Error code: " << dwError; std::cerr << exp.what() << std::endl; } eargs->event->DisconnectEvent(*curCon, tid, args); delete pClientContext; continue; } auto start_read = [&](client* ctx) { private: void start_read(client* ctx) { ctx->CurCon->csock->recvData(ctx->RecvBuf, 0); }; auto start_write = [&](client* ctx) { void start_write (client* ctx) { con& c = *ctx->CurCon; while (!c.SendData.empty()) { buffer out(c.SendData.data(), std::min<size_t>(BLOCKSIZE, c.SendData.size())); size_t consumed = 0; try { consumed = c.csock->sendData(out, 0); // PLAINTEXT consumed Loading @@ -274,7 +238,7 @@ namespace netplus { ctx->State = IO_WRITE_STATE; return; } throw; throw e; } if (consumed == 0) { Loading Loading @@ -303,6 +267,41 @@ namespace netplus { start_read(ctx); } }; public: EventWorker(int tid, ULONG_PTR args, EventWorkerArgs* eargs) { while (event::Running) { OVERLAPPED* pOverlapped = nullptr; ULONG_PTR lpContext = 0; DWORD dwBytesTransfered = 0; bool bReturn = GetQueuedCompletionStatus( eargs->eviocp, &dwBytesTransfered, &lpContext, &pOverlapped, eargs->timeout); if (lpContext == 0) { continue; } client* pClientContext = reinterpret_cast<client*>(lpContext); std::unique_ptr<con> &curCon = pClientContext->CurCon; // Check for I/O completion errors or graceful disconnects if (!bReturn || (bReturn && dwBytesTransfered == 0)) { DWORD dwError = GetLastError(); if (dwError != WAIT_TIMEOUT && dwError != ERROR_OPERATION_ABORTED) { NetException exp; exp[NetException::Error] << "I/O operation failed or client disconnected. Error code: " << dwError; std::cerr << exp.what() << std::endl; } eargs->event->DisconnectEvent(*curCon, tid, args); delete pClientContext; continue; } try { std::unique_lock<std::mutex> guard(pClientContext->cltmtx); Loading Loading
src/event/iocp.cpp +39 −40 Changes for src/event/iocp.cpp: 39 added lines, 40 removed lines. Original line number Diff line number Diff line Loading @@ -219,53 +219,17 @@ namespace netplus { }; class EventWorker { public: EventWorker(int tid, ULONG_PTR args, EventWorkerArgs* eargs) { while (event::Running) { OVERLAPPED* pOverlapped = nullptr; ULONG_PTR lpContext = 0; DWORD dwBytesTransfered = 0; bool bReturn = GetQueuedCompletionStatus( eargs->eviocp, &dwBytesTransfered, &lpContext, &pOverlapped, eargs->timeout); if (lpContext == 0) { continue; } client* pClientContext = reinterpret_cast<client*>(lpContext); std::unique_ptr<con> &curCon = pClientContext->CurCon; // Check for I/O completion errors or graceful disconnects if (!bReturn || (bReturn && dwBytesTransfered == 0)) { DWORD dwError = GetLastError(); if (dwError != WAIT_TIMEOUT && dwError != ERROR_OPERATION_ABORTED) { NetException exp; exp[NetException::Error] << "I/O operation failed or client disconnected. Error code: " << dwError; std::cerr << exp.what() << std::endl; } eargs->event->DisconnectEvent(*curCon, tid, args); delete pClientContext; continue; } auto start_read = [&](client* ctx) { private: void start_read(client* ctx) { ctx->CurCon->csock->recvData(ctx->RecvBuf, 0); }; auto start_write = [&](client* ctx) { void start_write (client* ctx) { con& c = *ctx->CurCon; while (!c.SendData.empty()) { buffer out(c.SendData.data(), std::min<size_t>(BLOCKSIZE, c.SendData.size())); size_t consumed = 0; try { consumed = c.csock->sendData(out, 0); // PLAINTEXT consumed Loading @@ -274,7 +238,7 @@ namespace netplus { ctx->State = IO_WRITE_STATE; return; } throw; throw e; } if (consumed == 0) { Loading Loading @@ -303,6 +267,41 @@ namespace netplus { start_read(ctx); } }; public: EventWorker(int tid, ULONG_PTR args, EventWorkerArgs* eargs) { while (event::Running) { OVERLAPPED* pOverlapped = nullptr; ULONG_PTR lpContext = 0; DWORD dwBytesTransfered = 0; bool bReturn = GetQueuedCompletionStatus( eargs->eviocp, &dwBytesTransfered, &lpContext, &pOverlapped, eargs->timeout); if (lpContext == 0) { continue; } client* pClientContext = reinterpret_cast<client*>(lpContext); std::unique_ptr<con> &curCon = pClientContext->CurCon; // Check for I/O completion errors or graceful disconnects if (!bReturn || (bReturn && dwBytesTransfered == 0)) { DWORD dwError = GetLastError(); if (dwError != WAIT_TIMEOUT && dwError != ERROR_OPERATION_ABORTED) { NetException exp; exp[NetException::Error] << "I/O operation failed or client disconnected. Error code: " << dwError; std::cerr << exp.what() << std::endl; } eargs->event->DisconnectEvent(*curCon, tid, args); delete pClientContext; continue; } try { std::unique_lock<std::mutex> guard(pClientContext->cltmtx); Loading