Loading .vscode/launch.json +19 Changes for .vscode/launch.json: 19 added lines, 0 removed lines. Original line number Diff line number Diff line { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(Windows) Launch", "type": "cppvsdbg", "request": "launch", "program": "${workspaceFolder}/build/test/Debug/base64.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "console": "externalTerminal" } ] } No newline at end of file .vscode/tasks.json +35 Changes for .vscode/tasks.json: 35 added lines, 0 removed lines. Original line number Diff line number Diff line { "tasks": [ { "type": "cppbuild", "label": "C/C++: cl.exe build active file", "command": "cl.exe", "args": [ "/Zi", "/EHsc", "/nologo", "/Fe${fileDirname}\\${fileBasenameNoExtension}.exe", "${file}" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$msCompile" ], "group": { "kind": "build", "isDefault": true }, "detail": "Task generated by Debugger." }, { "type": "cmake", "label": "CMake: package", "command": "package", "problemMatcher": [], "detail": "CMake template package task" } ], "version": "2.0.0" } No newline at end of file src/event/iocp.cpp +35 −26 Changes for src/event/iocp.cpp: 35 added lines, 26 removed lines. Original line number Diff line number Diff line Loading @@ -68,6 +68,7 @@ namespace netplus { } ~client() { api->DestroyConnection(CurCon); } int State; Loading @@ -93,6 +94,9 @@ namespace netplus { exp[NetException::Error] << "AssociateWithIOCP fehlgeschlagen: Fehlercode " << err; throw exp; } pClientContext->CurCon->csock->_Overlapped.hEvent = WSACreateEvent(); } void AcceptConnection(LPFN_ACCEPTEX lpfnAcceptEx, int tid, ULONG_PTR args) { Loading Loading @@ -215,9 +219,10 @@ namespace netplus { class EventWorker { public: EventWorker(int tid, ULONG_PTR args,EventWorkerArgs *eargs) { for (;;) { ULONG_PTR lpContext = 0; OVERLAPPED* pOverlapped = nullptr; ULONG_PTR lpContext = 0; DWORD dwBytesTransfered = 0; bool bReturn = GetQueuedCompletionStatus( Loading @@ -244,18 +249,15 @@ namespace netplus { } if (lpContext == 0) { NetException exp; exp[NetException::Critical] << "GetQueuedCompletionStatus returned zero bytes transferred and no context!"; throw exp; continue; } client *pClientContext = reinterpret_cast<client*>(lpContext); pClientContext->cltmtx.lock(); try { con *curCon = pClientContext->CurCon; std::lock_guard<std::mutex> clock(pClientContext->cltmtx); con *curCon = pClientContext->CurCon; switch (pClientContext->State) { case IO_WRITE_STATE: { eargs->event->ResponseEvent(*curCon, tid, args); Loading @@ -266,44 +268,51 @@ namespace netplus { buffer buf(curCon->SendData.data(),ssize); ret = curCon->csock->sendData(buf,0); curCon->SendData.resize(ret); if (curCon->SendData.empty()) // Erase the sent data from the beginning of the buffer curCon->SendData.erase(curCon->SendData.begin(), curCon->SendData.begin() + ret); if (curCon->SendData.empty()) { pClientContext->State = IO_READ_STATE; } else { PostQueuedCompletionStatus(eargs->eviocp, 0, lpContext, pOverlapped); continue; } }break; case IO_READ_STATE: { buffer buf(BLOCKSIZE); size_t recv = curCon->csock->recvData(buf, 0); std::cout.write(buf.data.buf, recv); std::copy(buf.data.buf,buf.data.buf+buf.size,std::back_inserter(curCon->RecvData)); std::copy(buf.data.buf,buf.data.buf+recv,std::back_inserter<std::vector<char,netplus::condataAlloc<char>>>(curCon->RecvData)); eargs->event->RequestEvent(*curCon, tid, args); if (!curCon->SendData.empty()) if (!curCon->SendData.empty()) { pClientContext->State = IO_WRITE_STATE; }break; PostQueuedCompletionStatus(eargs->eviocp, 0, lpContext, pOverlapped); continue; } }break; default: { NetException exp; exp[NetException::Error] << "Unknown IO state: " << pClientContext->State; throw exp; }break; } catch (NetException& e) { } catch (NetException& e) { std::cerr << e.what() << std::endl; if (e.getErrorType() == NetException::Note) { WSAResetEvent(pOverlapped->hEvent); continue; } WSACloseEvent(pOverlapped->hEvent); pOverlapped->hEvent=0; eargs->event->DisconnectEvent(*pClientContext->CurCon, tid, args); delete pClientContext; lpContext = 0; continue; } catch (...) { std::cerr << "unknown error close coonection !" << std::endl; WSACloseEvent(pOverlapped->hEvent); PostQueuedCompletionStatus(eargs->eviocp, 0, 0, pOverlapped); } catch (...) { std::cerr << "Eventworker unknown error !" << std::endl; pOverlapped->hEvent = 0; eargs->event->DisconnectEvent(*pClientContext->CurCon, tid, args); delete pClientContext; lpContext = 0; continue; PostQueuedCompletionStatus(eargs->eviocp, 0, 0, pOverlapped); } pClientContext->cltmtx.unlock(); } // for } }; Loading src/windows/tcp.cpp +2 −2 Changes for src/windows/tcp.cpp: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -220,7 +220,7 @@ size_t netplus::tcp::sendData(buffer &data,int flags){ << " ErrorMsg: " << lerror; throw exception; } return (size_t)dwsend != 0 ? dwsend : data.size; return (size_t)dwsend; } size_t netplus::tcp::recvData(buffer &data,int flags){ Loading Loading @@ -252,7 +252,7 @@ size_t netplus::tcp::recvData(buffer &data,int flags){ throw exception; } return (size_t)dwBytes != 0 ? dwBytes : data.size; return (size_t)dwBytes; } void netplus::tcp::connect(socket *ssock){ Loading src/windows/udp.cpp +2 −2 Changes for src/windows/udp.cpp: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -214,7 +214,7 @@ size_t netplus::udp::sendData(buffer &data, int flags) { << " ErrorMsg: " << GetLastError(); throw exception; } return (size_t)dwBytes != 0 ? dwBytes : data.size; return (size_t)dwBytes; } size_t netplus::udp::recvData(buffer &data, int flags) { Loading Loading @@ -246,7 +246,7 @@ size_t netplus::udp::recvData(buffer &data, int flags) { << " ErrorMsg: " << GetLastError(); throw exception; } return (size_t)dwBytes != 0 ? dwBytes : data.size; return (size_t)dwBytes; } void netplus::udp::connect(socket* ssock) { NetException exception; Loading Loading
.vscode/launch.json +19 Changes for .vscode/launch.json: 19 added lines, 0 removed lines. Original line number Diff line number Diff line { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(Windows) Launch", "type": "cppvsdbg", "request": "launch", "program": "${workspaceFolder}/build/test/Debug/base64.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "console": "externalTerminal" } ] } No newline at end of file
.vscode/tasks.json +35 Changes for .vscode/tasks.json: 35 added lines, 0 removed lines. Original line number Diff line number Diff line { "tasks": [ { "type": "cppbuild", "label": "C/C++: cl.exe build active file", "command": "cl.exe", "args": [ "/Zi", "/EHsc", "/nologo", "/Fe${fileDirname}\\${fileBasenameNoExtension}.exe", "${file}" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$msCompile" ], "group": { "kind": "build", "isDefault": true }, "detail": "Task generated by Debugger." }, { "type": "cmake", "label": "CMake: package", "command": "package", "problemMatcher": [], "detail": "CMake template package task" } ], "version": "2.0.0" } No newline at end of file
src/event/iocp.cpp +35 −26 Changes for src/event/iocp.cpp: 35 added lines, 26 removed lines. Original line number Diff line number Diff line Loading @@ -68,6 +68,7 @@ namespace netplus { } ~client() { api->DestroyConnection(CurCon); } int State; Loading @@ -93,6 +94,9 @@ namespace netplus { exp[NetException::Error] << "AssociateWithIOCP fehlgeschlagen: Fehlercode " << err; throw exp; } pClientContext->CurCon->csock->_Overlapped.hEvent = WSACreateEvent(); } void AcceptConnection(LPFN_ACCEPTEX lpfnAcceptEx, int tid, ULONG_PTR args) { Loading Loading @@ -215,9 +219,10 @@ namespace netplus { class EventWorker { public: EventWorker(int tid, ULONG_PTR args,EventWorkerArgs *eargs) { for (;;) { ULONG_PTR lpContext = 0; OVERLAPPED* pOverlapped = nullptr; ULONG_PTR lpContext = 0; DWORD dwBytesTransfered = 0; bool bReturn = GetQueuedCompletionStatus( Loading @@ -244,18 +249,15 @@ namespace netplus { } if (lpContext == 0) { NetException exp; exp[NetException::Critical] << "GetQueuedCompletionStatus returned zero bytes transferred and no context!"; throw exp; continue; } client *pClientContext = reinterpret_cast<client*>(lpContext); pClientContext->cltmtx.lock(); try { con *curCon = pClientContext->CurCon; std::lock_guard<std::mutex> clock(pClientContext->cltmtx); con *curCon = pClientContext->CurCon; switch (pClientContext->State) { case IO_WRITE_STATE: { eargs->event->ResponseEvent(*curCon, tid, args); Loading @@ -266,44 +268,51 @@ namespace netplus { buffer buf(curCon->SendData.data(),ssize); ret = curCon->csock->sendData(buf,0); curCon->SendData.resize(ret); if (curCon->SendData.empty()) // Erase the sent data from the beginning of the buffer curCon->SendData.erase(curCon->SendData.begin(), curCon->SendData.begin() + ret); if (curCon->SendData.empty()) { pClientContext->State = IO_READ_STATE; } else { PostQueuedCompletionStatus(eargs->eviocp, 0, lpContext, pOverlapped); continue; } }break; case IO_READ_STATE: { buffer buf(BLOCKSIZE); size_t recv = curCon->csock->recvData(buf, 0); std::cout.write(buf.data.buf, recv); std::copy(buf.data.buf,buf.data.buf+buf.size,std::back_inserter(curCon->RecvData)); std::copy(buf.data.buf,buf.data.buf+recv,std::back_inserter<std::vector<char,netplus::condataAlloc<char>>>(curCon->RecvData)); eargs->event->RequestEvent(*curCon, tid, args); if (!curCon->SendData.empty()) if (!curCon->SendData.empty()) { pClientContext->State = IO_WRITE_STATE; }break; PostQueuedCompletionStatus(eargs->eviocp, 0, lpContext, pOverlapped); continue; } }break; default: { NetException exp; exp[NetException::Error] << "Unknown IO state: " << pClientContext->State; throw exp; }break; } catch (NetException& e) { } catch (NetException& e) { std::cerr << e.what() << std::endl; if (e.getErrorType() == NetException::Note) { WSAResetEvent(pOverlapped->hEvent); continue; } WSACloseEvent(pOverlapped->hEvent); pOverlapped->hEvent=0; eargs->event->DisconnectEvent(*pClientContext->CurCon, tid, args); delete pClientContext; lpContext = 0; continue; } catch (...) { std::cerr << "unknown error close coonection !" << std::endl; WSACloseEvent(pOverlapped->hEvent); PostQueuedCompletionStatus(eargs->eviocp, 0, 0, pOverlapped); } catch (...) { std::cerr << "Eventworker unknown error !" << std::endl; pOverlapped->hEvent = 0; eargs->event->DisconnectEvent(*pClientContext->CurCon, tid, args); delete pClientContext; lpContext = 0; continue; PostQueuedCompletionStatus(eargs->eviocp, 0, 0, pOverlapped); } pClientContext->cltmtx.unlock(); } // for } }; Loading
src/windows/tcp.cpp +2 −2 Changes for src/windows/tcp.cpp: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -220,7 +220,7 @@ size_t netplus::tcp::sendData(buffer &data,int flags){ << " ErrorMsg: " << lerror; throw exception; } return (size_t)dwsend != 0 ? dwsend : data.size; return (size_t)dwsend; } size_t netplus::tcp::recvData(buffer &data,int flags){ Loading Loading @@ -252,7 +252,7 @@ size_t netplus::tcp::recvData(buffer &data,int flags){ throw exception; } return (size_t)dwBytes != 0 ? dwBytes : data.size; return (size_t)dwBytes; } void netplus::tcp::connect(socket *ssock){ Loading
src/windows/udp.cpp +2 −2 Changes for src/windows/udp.cpp: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -214,7 +214,7 @@ size_t netplus::udp::sendData(buffer &data, int flags) { << " ErrorMsg: " << GetLastError(); throw exception; } return (size_t)dwBytes != 0 ? dwBytes : data.size; return (size_t)dwBytes; } size_t netplus::udp::recvData(buffer &data, int flags) { Loading Loading @@ -246,7 +246,7 @@ size_t netplus::udp::recvData(buffer &data, int flags) { << " ErrorMsg: " << GetLastError(); throw exception; } return (size_t)dwBytes != 0 ? dwBytes : data.size; return (size_t)dwBytes; } void netplus::udp::connect(socket* ssock) { NetException exception; Loading