Loading src/event/iocp.cpp +14 −69 Original line number Diff line number Diff line Loading @@ -312,21 +312,13 @@ namespace netplus { ssize = BLOCKSIZE < pClientContext->CurCon->SendData.size() ? BLOCKSIZE : (ULONG)pClientContext->CurCon->SendData.size(); WSABUF wbuf; wbuf.buf = pClientContext->CurCon->SendData.data(); wbuf.len = ssize; //Overlapped send ret = WSASend(pClientContext->CurCon->csock->fd(), &wbuf, 1, &dwBytes, dwFlags, &pClientContext->CurCon->csock->_Overlapped, nullptr); std::shared_ptr<char[]> buf(new char[16384], std::default_delete<char[]>()); if ((SOCKET_ERROR == ret) && (WSA_IO_PENDING != WSAGetLastError())) { //Let's not work with this client eargs->evpoll->RemoveFromClientList(pClientContext); continue; } //Overlapped send ret = pClientContext->CurCon->csock->sendData(buf.get(),ssize, WSA_FLAG_OVERLAPPED); pClientContext->CurCon->SendData.resize(dwBytes); pClientContext->CurCon->SendData.resize(ret); try { eargs->event->ResponseEvent(pClientContext->CurCon, tid, args); Loading @@ -340,27 +332,11 @@ namespace netplus { dwFlags = 0; WSABUF wbuf; wbuf.buf = new char[BLOCKSIZE]; wbuf.len = BLOCKSIZE; std::shared_ptr<char[]> buf(new char[16384], std::default_delete<char[]>()); //Get the data. ret = WSARecv(pClientContext->CurCon->csock->fd(), &wbuf, 1, &dwBytes, &dwFlags, &pClientContext->CurCon->csock->_Overlapped, nullptr); ret = pClientContext->CurCon->csock->recvData(buf.get(), 16384, WSA_FLAG_OVERLAPPED); if ((SOCKET_ERROR == ret)) { std::cerr << "Thread " << tid << " : Error occurred while executing WSARecv()." << std::endl; //Let's not work with this client if (WSA_IO_PENDING != WSAGetLastError()) { eargs->event->DisconnectEvent(pClientContext->CurCon, tid, args); eargs->evpoll->RemoveFromClientList(pClientContext); } continue; } pClientContext->CurCon->RecvData.append(wbuf.buf, ret); delete wbuf.buf; pClientContext->CurCon->RecvData.append(buf.get(), ret); try { eargs->event->RequestEvent(pClientContext->CurCon, tid, args); Loading @@ -378,23 +354,10 @@ namespace netplus { if (!((con*)pClientContext->CurCon)->SendData.empty()) { ssize = BLOCKSIZE < pClientContext->CurCon->SendData.size() ? BLOCKSIZE : (ULONG)pClientContext->CurCon->SendData.size(); WSABUF wbuf; wbuf.buf = pClientContext->CurCon->SendData.data(); wbuf.len = ssize; std::shared_ptr<char[]> buf(new char[16384], std::default_delete<char[]>()); //Overlapped send ret = WSASend(pClientContext->CurCon->csock->fd(), &wbuf, 1, &dwBytes, dwFlags, &pClientContext->CurCon->csock->_Overlapped, NULL); TEST2: if (ret == SOCKET_ERROR) { std::cerr << "Thread " << tid << " <<: Error occurred while executing WSASend()." << std::endl; //Let's not work with this client if (WSA_IO_PENDING != WSAGetLastError()) eargs->evpoll->RemoveFromClientList(pClientContext); else goto TEST2; } ret = pClientContext->CurCon->csock->sendData(buf.get(), ssize, WSA_FLAG_OVERLAPPED); pClientContext->CurCon->SendData.resize(ret); Loading @@ -416,36 +379,18 @@ TEST2: dwFlags = 0; WSABUF wbuf; wbuf.buf = new char[BLOCKSIZE]; wbuf.len = BLOCKSIZE; std::shared_ptr<char[]> buf(new char[16384], std::default_delete<char[]>()); //Get the data. TEST3: ret = WSARecv(pClientContext->CurCon->csock->fd(), &wbuf, 1, &dwBytes, &dwFlags, &pClientContext->CurCon->csock->_Overlapped, nullptr); if ((SOCKET_ERROR == ret)) { if (WSA_IO_PENDING != WSAGetLastError()) { eargs->event->DisconnectEvent(pClientContext->CurCon, tid, args); eargs->evpoll->RemoveFromClientList(pClientContext); } else { Sleep(1); goto TEST3; } std::cerr << "Thread " << tid << " : Error occurred while executing WSARecv: " << WSAGetLastError() << std::endl; continue; } ret = pClientContext->CurCon->csock->recvData(buf.get(),16384,WSA_FLAG_OVERLAPPED); std::cout << ret << std::endl; pClientContext->CurCon->RecvData.append(wbuf.buf, ret); pClientContext->CurCon->RecvData.append(buf.get(), ret); std::cout << "Test: " << std::endl;; std::cout.write(wbuf.buf, dwBytes) << std::endl; delete wbuf.buf; std::cout.write(buf.get(), dwBytes) << std::endl; std::cout.write(pClientContext->CurCon->RecvData.data(), pClientContext->CurCon->RecvData.size()) << std::endl; Loading src/socket.h +3 −1 Original line number Diff line number Diff line Loading @@ -58,7 +58,9 @@ namespace netplus { virtual int getMaxconnections()=0; virtual size_t sendData(void *data,unsigned long size)=0; virtual size_t sendData(void* data, unsigned long size,int flags)=0; virtual size_t recvData(void *data,unsigned long size)=0; virtual size_t recvData(void* data, unsigned long size,int flags)=0; virtual void connect(socket *csock)=0; Loading src/windows/tcp.cpp +4 −14 Original line number Diff line number Diff line Loading @@ -165,28 +165,24 @@ void netplus::tcp::bind(){ size_t netplus::tcp::sendData(void* data, unsigned long size){ return sendData(data,size,-1); return sendData(data,size,0); } size_t netplus::tcp::sendData(void* data, unsigned long size,int flags){ NetException exception; if (flags < 0) flags = WSA_FLAG_OVERLAPPED; WSABUF buf; buf.buf = (char*)data; buf.len = size; DWORD dwFlags = 0; SEND: SOCKET rval=::WSASend(_Socket,&buf,1,nullptr,flags,&_Overlapped,nullptr); if(rval == SOCKET_ERROR){ DWORD lerror=GetLastError(); if (lerror == WSA_IO_PENDING) goto SEND; exception[NetException::Error] << "Socket senddata failed on Socket: " << (int) _Socket << " ErrorMsg: " << lerror; throw exception; Loading @@ -196,15 +192,12 @@ SEND: size_t netplus::tcp::recvData(void* data, unsigned long size){ return recvData(data,size,-1); return recvData(data,size,0); } size_t netplus::tcp::recvData(void* data, unsigned long size,int flags){ NetException exception; if (flags < 0) flags = WSA_FLAG_OVERLAPPED; WSABUF buf{0}; buf.buf = (char*)data; Loading @@ -212,13 +205,10 @@ size_t netplus::tcp::recvData(void* data, unsigned long size,int flags){ DWORD dwFlags = 0; RECV: int recvsize=::WSARecv(_Socket, &buf, 1,nullptr,(LPDWORD) &flags, &_Overlapped, nullptr); if(recvsize==SOCKET_ERROR){ DWORD lerror = GetLastError(); if (lerror == WSA_IO_PENDING) goto RECV; exception[NetException::Error] << "Socket recvdata failed on Socket: " << (int)_Socket << " ErrorMsg: " << lerror; Loading Loading
src/event/iocp.cpp +14 −69 Original line number Diff line number Diff line Loading @@ -312,21 +312,13 @@ namespace netplus { ssize = BLOCKSIZE < pClientContext->CurCon->SendData.size() ? BLOCKSIZE : (ULONG)pClientContext->CurCon->SendData.size(); WSABUF wbuf; wbuf.buf = pClientContext->CurCon->SendData.data(); wbuf.len = ssize; //Overlapped send ret = WSASend(pClientContext->CurCon->csock->fd(), &wbuf, 1, &dwBytes, dwFlags, &pClientContext->CurCon->csock->_Overlapped, nullptr); std::shared_ptr<char[]> buf(new char[16384], std::default_delete<char[]>()); if ((SOCKET_ERROR == ret) && (WSA_IO_PENDING != WSAGetLastError())) { //Let's not work with this client eargs->evpoll->RemoveFromClientList(pClientContext); continue; } //Overlapped send ret = pClientContext->CurCon->csock->sendData(buf.get(),ssize, WSA_FLAG_OVERLAPPED); pClientContext->CurCon->SendData.resize(dwBytes); pClientContext->CurCon->SendData.resize(ret); try { eargs->event->ResponseEvent(pClientContext->CurCon, tid, args); Loading @@ -340,27 +332,11 @@ namespace netplus { dwFlags = 0; WSABUF wbuf; wbuf.buf = new char[BLOCKSIZE]; wbuf.len = BLOCKSIZE; std::shared_ptr<char[]> buf(new char[16384], std::default_delete<char[]>()); //Get the data. ret = WSARecv(pClientContext->CurCon->csock->fd(), &wbuf, 1, &dwBytes, &dwFlags, &pClientContext->CurCon->csock->_Overlapped, nullptr); ret = pClientContext->CurCon->csock->recvData(buf.get(), 16384, WSA_FLAG_OVERLAPPED); if ((SOCKET_ERROR == ret)) { std::cerr << "Thread " << tid << " : Error occurred while executing WSARecv()." << std::endl; //Let's not work with this client if (WSA_IO_PENDING != WSAGetLastError()) { eargs->event->DisconnectEvent(pClientContext->CurCon, tid, args); eargs->evpoll->RemoveFromClientList(pClientContext); } continue; } pClientContext->CurCon->RecvData.append(wbuf.buf, ret); delete wbuf.buf; pClientContext->CurCon->RecvData.append(buf.get(), ret); try { eargs->event->RequestEvent(pClientContext->CurCon, tid, args); Loading @@ -378,23 +354,10 @@ namespace netplus { if (!((con*)pClientContext->CurCon)->SendData.empty()) { ssize = BLOCKSIZE < pClientContext->CurCon->SendData.size() ? BLOCKSIZE : (ULONG)pClientContext->CurCon->SendData.size(); WSABUF wbuf; wbuf.buf = pClientContext->CurCon->SendData.data(); wbuf.len = ssize; std::shared_ptr<char[]> buf(new char[16384], std::default_delete<char[]>()); //Overlapped send ret = WSASend(pClientContext->CurCon->csock->fd(), &wbuf, 1, &dwBytes, dwFlags, &pClientContext->CurCon->csock->_Overlapped, NULL); TEST2: if (ret == SOCKET_ERROR) { std::cerr << "Thread " << tid << " <<: Error occurred while executing WSASend()." << std::endl; //Let's not work with this client if (WSA_IO_PENDING != WSAGetLastError()) eargs->evpoll->RemoveFromClientList(pClientContext); else goto TEST2; } ret = pClientContext->CurCon->csock->sendData(buf.get(), ssize, WSA_FLAG_OVERLAPPED); pClientContext->CurCon->SendData.resize(ret); Loading @@ -416,36 +379,18 @@ TEST2: dwFlags = 0; WSABUF wbuf; wbuf.buf = new char[BLOCKSIZE]; wbuf.len = BLOCKSIZE; std::shared_ptr<char[]> buf(new char[16384], std::default_delete<char[]>()); //Get the data. TEST3: ret = WSARecv(pClientContext->CurCon->csock->fd(), &wbuf, 1, &dwBytes, &dwFlags, &pClientContext->CurCon->csock->_Overlapped, nullptr); if ((SOCKET_ERROR == ret)) { if (WSA_IO_PENDING != WSAGetLastError()) { eargs->event->DisconnectEvent(pClientContext->CurCon, tid, args); eargs->evpoll->RemoveFromClientList(pClientContext); } else { Sleep(1); goto TEST3; } std::cerr << "Thread " << tid << " : Error occurred while executing WSARecv: " << WSAGetLastError() << std::endl; continue; } ret = pClientContext->CurCon->csock->recvData(buf.get(),16384,WSA_FLAG_OVERLAPPED); std::cout << ret << std::endl; pClientContext->CurCon->RecvData.append(wbuf.buf, ret); pClientContext->CurCon->RecvData.append(buf.get(), ret); std::cout << "Test: " << std::endl;; std::cout.write(wbuf.buf, dwBytes) << std::endl; delete wbuf.buf; std::cout.write(buf.get(), dwBytes) << std::endl; std::cout.write(pClientContext->CurCon->RecvData.data(), pClientContext->CurCon->RecvData.size()) << std::endl; Loading
src/socket.h +3 −1 Original line number Diff line number Diff line Loading @@ -58,7 +58,9 @@ namespace netplus { virtual int getMaxconnections()=0; virtual size_t sendData(void *data,unsigned long size)=0; virtual size_t sendData(void* data, unsigned long size,int flags)=0; virtual size_t recvData(void *data,unsigned long size)=0; virtual size_t recvData(void* data, unsigned long size,int flags)=0; virtual void connect(socket *csock)=0; Loading
src/windows/tcp.cpp +4 −14 Original line number Diff line number Diff line Loading @@ -165,28 +165,24 @@ void netplus::tcp::bind(){ size_t netplus::tcp::sendData(void* data, unsigned long size){ return sendData(data,size,-1); return sendData(data,size,0); } size_t netplus::tcp::sendData(void* data, unsigned long size,int flags){ NetException exception; if (flags < 0) flags = WSA_FLAG_OVERLAPPED; WSABUF buf; buf.buf = (char*)data; buf.len = size; DWORD dwFlags = 0; SEND: SOCKET rval=::WSASend(_Socket,&buf,1,nullptr,flags,&_Overlapped,nullptr); if(rval == SOCKET_ERROR){ DWORD lerror=GetLastError(); if (lerror == WSA_IO_PENDING) goto SEND; exception[NetException::Error] << "Socket senddata failed on Socket: " << (int) _Socket << " ErrorMsg: " << lerror; throw exception; Loading @@ -196,15 +192,12 @@ SEND: size_t netplus::tcp::recvData(void* data, unsigned long size){ return recvData(data,size,-1); return recvData(data,size,0); } size_t netplus::tcp::recvData(void* data, unsigned long size,int flags){ NetException exception; if (flags < 0) flags = WSA_FLAG_OVERLAPPED; WSABUF buf{0}; buf.buf = (char*)data; Loading @@ -212,13 +205,10 @@ size_t netplus::tcp::recvData(void* data, unsigned long size,int flags){ DWORD dwFlags = 0; RECV: int recvsize=::WSARecv(_Socket, &buf, 1,nullptr,(LPDWORD) &flags, &_Overlapped, nullptr); if(recvsize==SOCKET_ERROR){ DWORD lerror = GetLastError(); if (lerror == WSA_IO_PENDING) goto RECV; exception[NetException::Error] << "Socket recvdata failed on Socket: " << (int)_Socket << " ErrorMsg: " << lerror; Loading