Loading src/connection.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -74,6 +74,8 @@ bool netplus::condata<char>::empty(){ } void netplus::condata<char>::append(const char* data, size_t datalen){ if (data == data + datalen) return; std::copy(data,data+datalen,std::inserter<std::vector<char,condataAlloc<char>>>(*this,end())); } Loading src/event/iocp.cpp +35 −15 Original line number Diff line number Diff line Loading @@ -100,7 +100,7 @@ namespace netplus { bool AssociateWithIOCP(client* pClientContext){ //Associate the socket with IOCP HANDLE htemp = CreateIoCompletionPort((HANDLE)(pClientContext)->CurCon->csock->fd(), g_iocp, (ULONG_PTR)&pClientContext, 0); HANDLE htemp = CreateIoCompletionPort((HANDLE)(pClientContext)->CurCon->csock->fd(), g_iocp, (ULONG_PTR)pClientContext, 0); if (htemp == nullptr){ RemoveFromClientList(pClientContext); Loading Loading @@ -163,7 +163,7 @@ namespace netplus { RECONNECT: int nBytesRecv = WSARecv(pClientContext->CurCon->csock->fd(), &wbuf, 1, &dwBytes, &dwFlags, &pClientContext->m_pol,nullptr); &dwBytes, &dwFlags, nullptr,nullptr); if (SOCKET_ERROR == nBytesRecv){ if ( WSA_IO_PENDING == WSAGetLastError() || WSAEWOULDBLOCK == WSAGetLastError() ) { Loading @@ -180,6 +180,20 @@ RECONNECT: pClientContext->CurCon->RecvData.append(wbuf.buf,dwBytes); delete wbuf.buf; try{ g_eventapi->RequestEvent(pClientContext->CurCon, 0, args); } catch (NetException &e) { std::cerr << e.what() << std::endl; } ULONG ssize = BLOCKSIZE < pClientContext->CurCon->SendData.size() ? BLOCKSIZE : (ULONG)pClientContext->CurCon->SendData.size(); wbuf.buf = pClientContext->CurCon->SendData.data(); wbuf.len = ssize; int nBytesSend = WSASend(pClientContext->CurCon->csock->fd(), &wbuf, 1, &dwBytes, dwFlags, &pClientContext->m_pol, nullptr); } LeaveCriticalSection(&g_csClientList); } Loading Loading @@ -273,7 +287,7 @@ RECONNECT: DWORD dwBytes = 0, dwFlags = 0; DWORD ret = 0; ULONG ssize = 0; EnterCriticalSection(&eargs->evpoll->g_csClientList); for (;;){ int bReturn = GetQueuedCompletionStatus( eargs->eviocp, Loading @@ -293,17 +307,13 @@ RECONNECT: continue; } EnterCriticalSection(&eargs->evpoll->g_csClientList); std::cerr << pClientContext->OpCode << std::endl; switch (pClientContext->OpCode) { case poll::OP_READ: //Write operation was finished, see if all the data was sent. //Else post another write. if (!((con*)pClientContext->CurCon)->SendData.empty()){ pClientContext->OpCode=poll::OP_READ; std::cerr << "oh no3" << std::endl; dwFlags = 0; ssize = BLOCKSIZE < pClientContext->CurCon->SendData.size() ? BLOCKSIZE : (ULONG) pClientContext->CurCon->SendData.size(); Loading @@ -323,8 +333,11 @@ RECONNECT: pClientContext->CurCon->SendData.resize(dwBytes); try{ eargs->event->ResponseEvent(pClientContext->CurCon, tid, args); } catch (NetException& e) { std::cerr << e.what() << std::endl; } } else { pClientContext->OpCode=poll::OP_WRITE; Loading @@ -345,13 +358,18 @@ RECONNECT: //Let's not work with this client eargs->event->DisconnectEvent(pClientContext->CurCon, tid, args); eargs->evpoll->RemoveFromClientList(pClientContext); continue; } pClientContext->CurCon->RecvData.append(wbuf.buf, dwBytes); delete wbuf.buf; try{ eargs->event->RequestEvent(pClientContext->CurCon, tid, args); }catch (NetException& e) { std::cerr << e.what() << std::endl; } } break; Loading Loading @@ -380,11 +398,13 @@ RECONNECT: pClientContext->CurCon->SendData.resize(dwBytes); try{ eargs->event->ResponseEvent(pClientContext->CurCon, tid, args); } catch (NetException& e) { std::cerr << e.what() << std::endl; } if (pClientContext->CurCon->SendData.empty()) { pClientContext->OpCode = poll::OP_READ; break; } break; Loading @@ -392,8 +412,8 @@ RECONNECT: eargs->evpoll->RemoveFromClientList(pClientContext); break; } // switch LeaveCriticalSection(&eargs->evpoll->g_csClientList); } // while LeaveCriticalSection(&eargs->evpoll->g_csClientList); } }; Loading src/windows/tcp.cpp +1 −3 Original line number Diff line number Diff line Loading @@ -132,8 +132,6 @@ int netplus::tcp::getMaxconnections(){ void netplus::tcp::accept(socket *csock){ NetException exception; getaddrinfo(nullptr,nullptr,(struct addrinfo*)_SocketInfo,(struct addrinfo**)&csock->_SocketInfo); csock->_Socket=::WSAAccept(_Socket, ((struct addrinfo*)csock->_SocketInfo)->ai_addr, (LPINT)((struct addrinfo*)csock->_SocketInfo)->ai_addrlen, nullptr, 0); if(csock->_Socket==SOCKET_ERROR){ Loading Loading
src/connection.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -74,6 +74,8 @@ bool netplus::condata<char>::empty(){ } void netplus::condata<char>::append(const char* data, size_t datalen){ if (data == data + datalen) return; std::copy(data,data+datalen,std::inserter<std::vector<char,condataAlloc<char>>>(*this,end())); } Loading
src/event/iocp.cpp +35 −15 Original line number Diff line number Diff line Loading @@ -100,7 +100,7 @@ namespace netplus { bool AssociateWithIOCP(client* pClientContext){ //Associate the socket with IOCP HANDLE htemp = CreateIoCompletionPort((HANDLE)(pClientContext)->CurCon->csock->fd(), g_iocp, (ULONG_PTR)&pClientContext, 0); HANDLE htemp = CreateIoCompletionPort((HANDLE)(pClientContext)->CurCon->csock->fd(), g_iocp, (ULONG_PTR)pClientContext, 0); if (htemp == nullptr){ RemoveFromClientList(pClientContext); Loading Loading @@ -163,7 +163,7 @@ namespace netplus { RECONNECT: int nBytesRecv = WSARecv(pClientContext->CurCon->csock->fd(), &wbuf, 1, &dwBytes, &dwFlags, &pClientContext->m_pol,nullptr); &dwBytes, &dwFlags, nullptr,nullptr); if (SOCKET_ERROR == nBytesRecv){ if ( WSA_IO_PENDING == WSAGetLastError() || WSAEWOULDBLOCK == WSAGetLastError() ) { Loading @@ -180,6 +180,20 @@ RECONNECT: pClientContext->CurCon->RecvData.append(wbuf.buf,dwBytes); delete wbuf.buf; try{ g_eventapi->RequestEvent(pClientContext->CurCon, 0, args); } catch (NetException &e) { std::cerr << e.what() << std::endl; } ULONG ssize = BLOCKSIZE < pClientContext->CurCon->SendData.size() ? BLOCKSIZE : (ULONG)pClientContext->CurCon->SendData.size(); wbuf.buf = pClientContext->CurCon->SendData.data(); wbuf.len = ssize; int nBytesSend = WSASend(pClientContext->CurCon->csock->fd(), &wbuf, 1, &dwBytes, dwFlags, &pClientContext->m_pol, nullptr); } LeaveCriticalSection(&g_csClientList); } Loading Loading @@ -273,7 +287,7 @@ RECONNECT: DWORD dwBytes = 0, dwFlags = 0; DWORD ret = 0; ULONG ssize = 0; EnterCriticalSection(&eargs->evpoll->g_csClientList); for (;;){ int bReturn = GetQueuedCompletionStatus( eargs->eviocp, Loading @@ -293,17 +307,13 @@ RECONNECT: continue; } EnterCriticalSection(&eargs->evpoll->g_csClientList); std::cerr << pClientContext->OpCode << std::endl; switch (pClientContext->OpCode) { case poll::OP_READ: //Write operation was finished, see if all the data was sent. //Else post another write. if (!((con*)pClientContext->CurCon)->SendData.empty()){ pClientContext->OpCode=poll::OP_READ; std::cerr << "oh no3" << std::endl; dwFlags = 0; ssize = BLOCKSIZE < pClientContext->CurCon->SendData.size() ? BLOCKSIZE : (ULONG) pClientContext->CurCon->SendData.size(); Loading @@ -323,8 +333,11 @@ RECONNECT: pClientContext->CurCon->SendData.resize(dwBytes); try{ eargs->event->ResponseEvent(pClientContext->CurCon, tid, args); } catch (NetException& e) { std::cerr << e.what() << std::endl; } } else { pClientContext->OpCode=poll::OP_WRITE; Loading @@ -345,13 +358,18 @@ RECONNECT: //Let's not work with this client eargs->event->DisconnectEvent(pClientContext->CurCon, tid, args); eargs->evpoll->RemoveFromClientList(pClientContext); continue; } pClientContext->CurCon->RecvData.append(wbuf.buf, dwBytes); delete wbuf.buf; try{ eargs->event->RequestEvent(pClientContext->CurCon, tid, args); }catch (NetException& e) { std::cerr << e.what() << std::endl; } } break; Loading Loading @@ -380,11 +398,13 @@ RECONNECT: pClientContext->CurCon->SendData.resize(dwBytes); try{ eargs->event->ResponseEvent(pClientContext->CurCon, tid, args); } catch (NetException& e) { std::cerr << e.what() << std::endl; } if (pClientContext->CurCon->SendData.empty()) { pClientContext->OpCode = poll::OP_READ; break; } break; Loading @@ -392,8 +412,8 @@ RECONNECT: eargs->evpoll->RemoveFromClientList(pClientContext); break; } // switch LeaveCriticalSection(&eargs->evpoll->g_csClientList); } // while LeaveCriticalSection(&eargs->evpoll->g_csClientList); } }; Loading
src/windows/tcp.cpp +1 −3 Original line number Diff line number Diff line Loading @@ -132,8 +132,6 @@ int netplus::tcp::getMaxconnections(){ void netplus::tcp::accept(socket *csock){ NetException exception; getaddrinfo(nullptr,nullptr,(struct addrinfo*)_SocketInfo,(struct addrinfo**)&csock->_SocketInfo); csock->_Socket=::WSAAccept(_Socket, ((struct addrinfo*)csock->_SocketInfo)->ai_addr, (LPINT)((struct addrinfo*)csock->_SocketInfo)->ai_addrlen, nullptr, 0); if(csock->_Socket==SOCKET_ERROR){ Loading