Loading src/event/iocp.cpp +11 −7 Changes for src/event/iocp.cpp: 11 added lines, 7 removed lines. Original line number Diff line number Diff line Loading @@ -55,6 +55,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define BLOCKSIZE 16384 namespace netplus { std::mutex EventLock; class client { public: client(eventapi* eapi) { Loading @@ -67,6 +70,7 @@ namespace netplus { }; std::mutex ConLock; HANDLE State; eventapi* api; con* CurCon; }; Loading @@ -74,19 +78,17 @@ namespace netplus { class poll { public: poll(HANDLE iocp,std::mutex &amtx,eventapi* api, socket* ssock) : g_amtx (amtx){ poll(HANDLE iocp,std::mutex &amtx,eventapi* api, socket* ssock) { g_iocp = iocp; g_eventapi = api; g_serversocket = ssock; }; void AddToClientList(client* pClientContext) { const std::lock_guard<std::mutex> lock(g_polllock); g_ClientContext.push_back(pClientContext); } bool AssociateWithIOCP(client* pClientContext) { const std::lock_guard<std::mutex> lock(g_polllock); //Associate the socket with IOCP HANDLE giocp2 = CreateIoCompletionPort((HANDLE)(pClientContext)->CurCon->csock->fd(), g_iocp, (ULONG_PTR)pClientContext, 0); Loading @@ -100,7 +102,6 @@ namespace netplus { } void RemoveFromClientList(client* pClientContext) { const std::lock_guard<std::mutex> lock(g_polllock); std::vector <client*>::iterator IterClientContext; for (IterClientContext = g_ClientContext.begin(); IterClientContext != g_ClientContext.end(); IterClientContext++) { if (pClientContext == *IterClientContext) { Loading @@ -112,10 +113,11 @@ namespace netplus { } void AcceptConnection(LPFN_ACCEPTEX lpfnAcceptEx,int tid, ULONG_PTR args) { std::lock_guard<std::mutex> lock(EventLock); client* pClientContext = new client(g_eventapi); if (g_serversocket->_Type == TCP) pClientContext->CurCon->csock = new tcp; pClientContext->CurCon->csock = new tcp(); try { g_serversocket->accept(lpfnAcceptEx,pClientContext->CurCon->csock); Loading Loading @@ -149,8 +151,6 @@ namespace netplus { socket* g_serversocket; eventapi* g_eventapi; std::vector<client*> g_ClientContext; std::mutex g_polllock; std::mutex& g_amtx; friend class client; friend class EventWorker; }; Loading Loading @@ -244,6 +244,8 @@ namespace netplus { &pOverlapped, WSA_INFINITE); std::lock_guard<std::mutex> lock(EventLock); if (lpContext == 0) { continue; } Loading @@ -255,6 +257,8 @@ namespace netplus { continue; } std::cout.write(pClientContext->CurCon->RecvData.data(), pClientContext->CurCon->RecvData.size())<<std::endl; try { if (!pClientContext->CurCon->SendData.empty()) { Loading src/windows/tcp.cpp +15 −5 Changes for src/windows/tcp.cpp: 15 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -233,17 +233,27 @@ size_t netplus::tcp::recvData(void* data, unsigned long size,int flags){ if(recvsize==SOCKET_ERROR){ DWORD lerror = WSAGetLastError(); int etype = NetException::Error; if (lerror != WSA_IO_PENDING) { exception[NetException::Error] << "Socket recvdata failed on Socket: " << (int)_Socket << " ErrorMsg: " << lerror; throw exception; } } if (lerror == WSA_IO_PENDING) { etype = NetException::Note; int rc = WSAWaitForMultipleEvents(1, &_Overlapped.hEvent, TRUE, INFINITE, TRUE); if (rc == WSA_WAIT_FAILED) { exception[NetException::Error] << "WSAWaitForMultipleEvents failed with error: " << WSAGetLastError(); throw exception; } exception[etype] << "Socket recvdata failed on Socket: " << (int)_Socket << " ErrorMsg: " << lerror; rc = WSAGetOverlappedResult(_Socket, &_Overlapped, &dwBytes, FALSE, (LPDWORD) &flags); if (rc == FALSE) { exception[NetException::Error] << "WSARecv operation failed with error: "<< WSAGetLastError(); throw exception; } WSAResetEvent(_Overlapped.hEvent); return (size_t) recvsize; } Loading Loading
src/event/iocp.cpp +11 −7 Changes for src/event/iocp.cpp: 11 added lines, 7 removed lines. Original line number Diff line number Diff line Loading @@ -55,6 +55,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define BLOCKSIZE 16384 namespace netplus { std::mutex EventLock; class client { public: client(eventapi* eapi) { Loading @@ -67,6 +70,7 @@ namespace netplus { }; std::mutex ConLock; HANDLE State; eventapi* api; con* CurCon; }; Loading @@ -74,19 +78,17 @@ namespace netplus { class poll { public: poll(HANDLE iocp,std::mutex &amtx,eventapi* api, socket* ssock) : g_amtx (amtx){ poll(HANDLE iocp,std::mutex &amtx,eventapi* api, socket* ssock) { g_iocp = iocp; g_eventapi = api; g_serversocket = ssock; }; void AddToClientList(client* pClientContext) { const std::lock_guard<std::mutex> lock(g_polllock); g_ClientContext.push_back(pClientContext); } bool AssociateWithIOCP(client* pClientContext) { const std::lock_guard<std::mutex> lock(g_polllock); //Associate the socket with IOCP HANDLE giocp2 = CreateIoCompletionPort((HANDLE)(pClientContext)->CurCon->csock->fd(), g_iocp, (ULONG_PTR)pClientContext, 0); Loading @@ -100,7 +102,6 @@ namespace netplus { } void RemoveFromClientList(client* pClientContext) { const std::lock_guard<std::mutex> lock(g_polllock); std::vector <client*>::iterator IterClientContext; for (IterClientContext = g_ClientContext.begin(); IterClientContext != g_ClientContext.end(); IterClientContext++) { if (pClientContext == *IterClientContext) { Loading @@ -112,10 +113,11 @@ namespace netplus { } void AcceptConnection(LPFN_ACCEPTEX lpfnAcceptEx,int tid, ULONG_PTR args) { std::lock_guard<std::mutex> lock(EventLock); client* pClientContext = new client(g_eventapi); if (g_serversocket->_Type == TCP) pClientContext->CurCon->csock = new tcp; pClientContext->CurCon->csock = new tcp(); try { g_serversocket->accept(lpfnAcceptEx,pClientContext->CurCon->csock); Loading Loading @@ -149,8 +151,6 @@ namespace netplus { socket* g_serversocket; eventapi* g_eventapi; std::vector<client*> g_ClientContext; std::mutex g_polllock; std::mutex& g_amtx; friend class client; friend class EventWorker; }; Loading Loading @@ -244,6 +244,8 @@ namespace netplus { &pOverlapped, WSA_INFINITE); std::lock_guard<std::mutex> lock(EventLock); if (lpContext == 0) { continue; } Loading @@ -255,6 +257,8 @@ namespace netplus { continue; } std::cout.write(pClientContext->CurCon->RecvData.data(), pClientContext->CurCon->RecvData.size())<<std::endl; try { if (!pClientContext->CurCon->SendData.empty()) { Loading
src/windows/tcp.cpp +15 −5 Changes for src/windows/tcp.cpp: 15 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -233,17 +233,27 @@ size_t netplus::tcp::recvData(void* data, unsigned long size,int flags){ if(recvsize==SOCKET_ERROR){ DWORD lerror = WSAGetLastError(); int etype = NetException::Error; if (lerror != WSA_IO_PENDING) { exception[NetException::Error] << "Socket recvdata failed on Socket: " << (int)_Socket << " ErrorMsg: " << lerror; throw exception; } } if (lerror == WSA_IO_PENDING) { etype = NetException::Note; int rc = WSAWaitForMultipleEvents(1, &_Overlapped.hEvent, TRUE, INFINITE, TRUE); if (rc == WSA_WAIT_FAILED) { exception[NetException::Error] << "WSAWaitForMultipleEvents failed with error: " << WSAGetLastError(); throw exception; } exception[etype] << "Socket recvdata failed on Socket: " << (int)_Socket << " ErrorMsg: " << lerror; rc = WSAGetOverlappedResult(_Socket, &_Overlapped, &dwBytes, FALSE, (LPDWORD) &flags); if (rc == FALSE) { exception[NetException::Error] << "WSARecv operation failed with error: "<< WSAGetLastError(); throw exception; } WSAResetEvent(_Overlapped.hEvent); return (size_t) recvsize; } Loading