Commit 98c4edae authored by jan.koester's avatar jan.koester
Browse files

test

parent 1e1a429d
Loading
Loading
Loading
Loading
+30 −65
Original line number Diff line number Diff line
@@ -147,31 +147,16 @@ namespace netplus {

				pClientContext->OpCode = OP_WRITE;

				//Get data.
				DWORD dwFlags = 0;
				DWORD dwBytes = 0;

				WSABUF wbuf;
				wbuf.buf = new char[BLOCKSIZE];
				wbuf.len = BLOCKSIZE;

				int nBytesRecv = WSARecv(pClientContext->CurCon->csock->fd(), &wbuf, 1,
					&dwBytes, &dwFlags,&pClientContext->CurCon->csock->_Overlapped, nullptr);

				if (SOCKET_ERROR == nBytesRecv) {
					if (WSA_IO_PENDING != WSAGetLastError()) {
						NetException e;
						e[NetException::Error] << "AcceptConnection Failed on: " << (int)pClientContext->CurCon->csock->fd()
							<< "Error: " << WSAGetLastError();
						RemoveFromClientList(pClientContext);
						delete wbuf.buf;
						throw e;
					}
				} else {
					std::cout << nBytesRecv << std::endl;
					pClientContext->CurCon->RecvData.append(wbuf.buf, nBytesRecv);
					delete wbuf.buf;
				std::shared_ptr<char[]> buf(new char[BLOCKSIZE], std::default_delete<char[]>());

				int nBytesRecv = 0;

				try {
					nBytesRecv = pClientContext->CurCon->csock->recvData(buf.get(), BLOCKSIZE, WSA_FLAG_OVERLAPPED);
				} catch (...) {

				}
				pClientContext->CurCon->RecvData.append(buf.get(), nBytesRecv);
			}
		}

@@ -218,8 +203,8 @@ namespace netplus {
		}
		_Timeout = timeout;
		_ServerSocket = serversocket;
		_ServerSocket->setFlag(WSA_FLAG_OVERLAPPED);
		_ServerSocket->setFlag(1);
		_ServerSocket->setFlag(WSA_FLAG_OVERLAPPED,1);
		_ServerSocket->setFlag(FIONBIO,1);
		_ServerSocket->bind();
		_ServerSocket->listen();

@@ -350,11 +335,20 @@ namespace netplus {
					break;

				case poll::OP_WRITE:
					//Send the message back to the client.                    
					dwFlags = 0;
					try {

						std::cout.write(pClientContext->CurCon->RecvData.data(),pClientContext->CurCon->RecvData.size())<<std::endl;

						eargs->event->RequestEvent(pClientContext->CurCon, tid, args);

						if(!((con*)pClientContext->CurCon)->SendData.empty()) {
							

							dwFlags = 0;

							ssize = BLOCKSIZE < pClientContext->CurCon->SendData.size() ? BLOCKSIZE : (ULONG)pClientContext->CurCon->SendData.size();


							std::shared_ptr<char[]> buf(new char[16384], std::default_delete<char[]>());

							//Overlapped send
@@ -368,40 +362,11 @@ namespace netplus {
							catch (NetException& e) {
								std::cerr << e.what() << std::endl;
							}
						if (pClientContext->CurCon->SendData.empty()) {
							pClientContext->OpCode = poll::OP_READ;
						}
						break;
					}
					else if (!((con*)pClientContext->CurCon)->RecvData.empty()) {
						eargs->event->RequestEvent(pClientContext->CurCon, tid, args);
					} else {
						pClientContext->OpCode = poll::OP_WRITE;

						dwFlags = 0;

						std::shared_ptr<char[]> buf(new char[16384], std::default_delete<char[]>());

						//Get the data.
TEST3:
						ret = pClientContext->CurCon->csock->recvData(buf.get(),16384,WSA_FLAG_OVERLAPPED);

						std::cout << ret << std::endl;

						pClientContext->CurCon->RecvData.append(buf.get(), ret);

						std::cout << "Test: " << std::endl;;
						std::cout.write(buf.get(), dwBytes) << std::endl;

						std::cout.write(pClientContext->CurCon->RecvData.data(), pClientContext->CurCon->RecvData.size()) << std::endl;

						try {
							eargs->event->RequestEvent(pClientContext->CurCon, tid, args);
						}
						catch (NetException& e) {
					} catch (NetException& e) {
						std::cerr << e.what() << std::endl;
					}
					}
					pClientContext->OpCode = poll::OP_READ;
				default:
					eargs->evpoll->RemoveFromClientList(pClientContext);
					break;
+13 −5
Original line number Diff line number Diff line
@@ -66,13 +66,21 @@ netplus::socket::~socket(){
    free((void*)_SocketInfo);
}

void netplus::socket::setFlag(int flag){
void netplus::socket::setFlag(int flag,int value){
    int sockopts=fcntl(_Socket, F_GETFL, 0);
    if (value == 1) {
        if (fcntl(_Socket, F_SETFL, sockopts | flag) < 0) {
            NetException exception;
            exception[NetException::Error] << "Could not set ClientSocket nonblocking!";
            throw exception;
        }
    }else{
        if (fcntl(_Socket, F_SETFL, sockopts & flag) < 0) {
            NetException exception;
            exception[NetException::Error] << "Could not set ClientSocket nonblocking!";
            throw exception;
        }
    }
}

void netplus::socket::setTimeout(int sec){
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ namespace netplus {
            socket();
            virtual                 ~socket();
            
            void                     setFlag(int flag);
            void                     setFlag(int flag,int value);

            void                     setTimeout(int sec);
            
+2 −2
Original line number Diff line number Diff line
@@ -73,8 +73,8 @@ netplus::socket::~socket(){
}


void netplus::socket::setFlag(int flag) {
    u_long mode = flag;
void netplus::socket::setFlag(int flag,int value) {
    u_long mode = value;
    if (ioctlsocket(_Socket, FIONBIO, &mode) < 0) {
        NetException exception;
        exception[NetException::Error] << "Could not set ClientSocket nonblocking!";
+1 −0
Original line number Diff line number Diff line
@@ -179,6 +179,7 @@ size_t netplus::tcp::sendData(void* data, unsigned long size,int flags){
    if(rval == SOCKET_ERROR){
        DWORD lerror=GetLastError();


        exception[NetException::Error] << "Socket senddata failed on Socket: " << (int) _Socket
                                       << " ErrorMsg: " << lerror;
        throw exception;