Loading src/event/iocp.cpp +20 −11 Changes for src/event/iocp.cpp: 20 added lines, 11 removed lines. Original line number Diff line number Diff line Loading @@ -88,9 +88,9 @@ namespace netplus { bool AssociateWithIOCP(client* pClientContext) { const std::lock_guard<std::mutex> lock(g_polllock); //Associate the socket with IOCP g_iocp = CreateIoCompletionPort((HANDLE)(pClientContext)->CurCon->csock->fd(), g_iocp, (ULONG_PTR)pClientContext, 0); HANDLE giocp2 = CreateIoCompletionPort((HANDLE)(pClientContext)->CurCon->csock->fd(), g_iocp, (ULONG_PTR)pClientContext, 0); if (g_iocp == nullptr) { if (!giocp2 || g_iocp != giocp2) { RemoveFromClientList(pClientContext); std::cerr << "AssociateWithIOCP: " << GetLastError() << std::endl; return false; Loading Loading @@ -240,22 +240,21 @@ namespace netplus { ULONG ssize = 0; for (;;) { int bReturn = GetQueuedCompletionStatus( bool bReturn = GetQueuedCompletionStatus( eargs->eviocp, &dwBytesTransfered, &lpContext, &pOverlapped, WSA_INFINITE); if (lpContext == 0) { if (lpContext == nullptr) { continue; } pClientContext = (client*)lpContext; if ((bReturn == 0) && (0 == dwBytesTransfered)) { if ( !bReturn && dwBytesTransfered == 0) { eargs->evpoll->RemoveFromClientList(pClientContext); eargs->mtx->unlock(); continue; } Loading @@ -273,17 +272,27 @@ namespace netplus { try { eargs->event->ResponseEvent(pClientContext->CurCon, tid, args); } catch (NetException& e) { } catch (NetException& e) { std::cerr << e.what() << std::endl; } } else { } else { //Get the data. pClientContext->CurCon->csock->sendData(nullptr,0, 0); std::shared_ptr<char[]> buf(new char[BLOCKSIZE], std::default_delete<char[]>()); size_t recv = pClientContext->CurCon->csock->recvData(buf.get(), BLOCKSIZE, 0); pClientContext->CurCon->RecvData.append(buf.get(), recv); try { eargs->event->RequestEvent(pClientContext->CurCon, tid, args); } catch (NetException& e) { std::cerr << e.what() << std::endl; } } catch (NetException& e) { } catch (NetException& e) { std::cerr << e.what() << std::endl; if(e.getErrorType()!=NetException::Note) eargs->evpoll->RemoveFromClientList(pClientContext); Loading src/windows/tcp.cpp +4 −2 Changes for src/windows/tcp.cpp: 4 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -226,10 +226,12 @@ size_t netplus::tcp::recvData(void* data, unsigned long size,int flags){ buf.len = size; DWORD dwFlags = 0; int recvsize=::WSARecv(_Socket, &buf, 1,nullptr,(LPDWORD) &flags, &_Overlapped, nullptr); DWORD dwBytes = 0; int recvsize=::WSARecv(_Socket, &buf, 1,&dwBytes,(LPDWORD) &flags, &_Overlapped, nullptr); if(recvsize==SOCKET_ERROR){ DWORD lerror = GetLastError(); DWORD lerror = WSAGetLastError(); int etype = NetException::Error; Loading Loading
src/event/iocp.cpp +20 −11 Changes for src/event/iocp.cpp: 20 added lines, 11 removed lines. Original line number Diff line number Diff line Loading @@ -88,9 +88,9 @@ namespace netplus { bool AssociateWithIOCP(client* pClientContext) { const std::lock_guard<std::mutex> lock(g_polllock); //Associate the socket with IOCP g_iocp = CreateIoCompletionPort((HANDLE)(pClientContext)->CurCon->csock->fd(), g_iocp, (ULONG_PTR)pClientContext, 0); HANDLE giocp2 = CreateIoCompletionPort((HANDLE)(pClientContext)->CurCon->csock->fd(), g_iocp, (ULONG_PTR)pClientContext, 0); if (g_iocp == nullptr) { if (!giocp2 || g_iocp != giocp2) { RemoveFromClientList(pClientContext); std::cerr << "AssociateWithIOCP: " << GetLastError() << std::endl; return false; Loading Loading @@ -240,22 +240,21 @@ namespace netplus { ULONG ssize = 0; for (;;) { int bReturn = GetQueuedCompletionStatus( bool bReturn = GetQueuedCompletionStatus( eargs->eviocp, &dwBytesTransfered, &lpContext, &pOverlapped, WSA_INFINITE); if (lpContext == 0) { if (lpContext == nullptr) { continue; } pClientContext = (client*)lpContext; if ((bReturn == 0) && (0 == dwBytesTransfered)) { if ( !bReturn && dwBytesTransfered == 0) { eargs->evpoll->RemoveFromClientList(pClientContext); eargs->mtx->unlock(); continue; } Loading @@ -273,17 +272,27 @@ namespace netplus { try { eargs->event->ResponseEvent(pClientContext->CurCon, tid, args); } catch (NetException& e) { } catch (NetException& e) { std::cerr << e.what() << std::endl; } } else { } else { //Get the data. pClientContext->CurCon->csock->sendData(nullptr,0, 0); std::shared_ptr<char[]> buf(new char[BLOCKSIZE], std::default_delete<char[]>()); size_t recv = pClientContext->CurCon->csock->recvData(buf.get(), BLOCKSIZE, 0); pClientContext->CurCon->RecvData.append(buf.get(), recv); try { eargs->event->RequestEvent(pClientContext->CurCon, tid, args); } catch (NetException& e) { std::cerr << e.what() << std::endl; } } catch (NetException& e) { } catch (NetException& e) { std::cerr << e.what() << std::endl; if(e.getErrorType()!=NetException::Note) eargs->evpoll->RemoveFromClientList(pClientContext); Loading
src/windows/tcp.cpp +4 −2 Changes for src/windows/tcp.cpp: 4 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -226,10 +226,12 @@ size_t netplus::tcp::recvData(void* data, unsigned long size,int flags){ buf.len = size; DWORD dwFlags = 0; int recvsize=::WSARecv(_Socket, &buf, 1,nullptr,(LPDWORD) &flags, &_Overlapped, nullptr); DWORD dwBytes = 0; int recvsize=::WSARecv(_Socket, &buf, 1,&dwBytes,(LPDWORD) &flags, &_Overlapped, nullptr); if(recvsize==SOCKET_ERROR){ DWORD lerror = GetLastError(); DWORD lerror = WSAGetLastError(); int etype = NetException::Error; Loading