Commit 2b98950a authored by jan.koester's avatar jan.koester
Browse files

fiex

parent 6a205148
Loading
Loading
Loading
Loading
+1
Changes for src/CMakeLists.txt: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -148,6 +148,7 @@ if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows")
    set(CPACK_GENERATOR WIX)
    set(CPACK_PACKAGE_NAME "libnetplus")
    set(CPACK_PACKAGE_VENDOR "tuxist.de")
    set(CPACK_WIX_UPGRADE_GUID "A4999F8C-2D6A-4F55-AF9F-0EE8F40BE489")
    set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt")
    set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "libnetplus - A C++ Socket and Event Library")
    set(CPACK_PACKAGE_VERSION "1.0.0")
+13 −29
Changes for src/event/iocp.cpp: 13 added lines, 29 removed lines.
Original line number Diff line number Diff line
@@ -88,17 +88,14 @@ namespace netplus {
		bool AssociateWithIOCP(client* pClientContext) {
			const std::lock_guard<std::mutex> lock(g_polllock);
			//Associate the socket with IOCP
			HANDLE htemp = CreateIoCompletionPort((HANDLE)(pClientContext)->CurCon->csock->fd(), g_iocp, (ULONG_PTR)pClientContext, 0);
			g_iocp = CreateIoCompletionPort((HANDLE)(pClientContext)->CurCon->csock->fd(), g_iocp, (ULONG_PTR)pClientContext, 0);

			if (htemp == nullptr) {
			if (g_iocp == nullptr) {
				RemoveFromClientList(pClientContext);
				std::cerr << "AssociateWithIOCP: " << GetLastError() << std::endl;
				return false;
			}

			setsockopt(pClientContext->CurCon->csock->fd(), SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT,
				       (char*)&g_serversocket, sizeof(g_serversocket));

			return true;
		}

@@ -123,7 +120,7 @@ namespace netplus {
			try {
				g_serversocket->accept(lpfnAcceptEx,pClientContext->CurCon->csock);				

				pClientContext->CurCon->csock->setFlag(FIONBIO, 0);
				pClientContext->CurCon->csock->setNonBlock();

				//Store this object
				AddToClientList(pClientContext);
@@ -136,15 +133,17 @@ namespace netplus {
			}
			g_eventapi->ConnectEvent(pClientContext->CurCon, tid, args);

			try {
				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);

			std::cerr.write(buf.get(), recv) << std::endl;

				g_eventapi->RequestEvent(pClientContext->CurCon, tid, args);
			} catch (NetException& e) {
				std::cerr << e.what() << std::endl;
				if (e.getErrorType() != NetException::Note)
					throw e;
			}
			

		}

@@ -191,7 +190,7 @@ namespace netplus {
		}
		_Timeout = timeout;
		_ServerSocket = serversocket;
		_ServerSocket->setFlag(FIONBIO,1);
		_ServerSocket->setNonBlock();
		_ServerSocket->bind();
		_ServerSocket->listen();

@@ -248,10 +247,7 @@ namespace netplus {
					&pOverlapped,
					WSA_INFINITE);

				eargs->mtx->lock();

				if (lpContext == 0) {
					eargs->mtx->unlock();
					continue;
				}

@@ -283,19 +279,8 @@ namespace netplus {

						}
					} else {
						dwFlags = 0;

						std::shared_ptr<char[]> buf(new char[BLOCKSIZE], std::default_delete<char[]>());
						//Get the data.
						ret = pClientContext->CurCon->csock->recvData(buf.get(), BLOCKSIZE, 0);

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

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

							ret = pClientContext->CurCon->csock->sendData(buf.get(), ssize, 0);
						}
						pClientContext->CurCon->csock->sendData(nullptr,0, 0);
					}
				}
				catch (NetException& e) {
@@ -303,7 +288,6 @@ namespace netplus {
					if(e.getErrorType()!=NetException::Note)
			     		eargs->evpoll->RemoveFromClientList(pClientContext);
				}
				eargs->mtx->unlock();
			} // while
		}
	};
@@ -375,7 +359,7 @@ namespace netplus {
			throw exp;
		}

		if (SOCKET_ERROR == WSAEventSelect(_ServerSocket->fd(), g_hAcceptEvent, FD_ACCEPT)) {
		if (SOCKET_ERROR == WSAEventSelect(_ServerSocket->fd(), g_hAcceptEvent, FD_ACCEPT|FD_READ|FD_WRITE)) {
			NetException exp;
			exp[NetException::Error] << "Error occurred while WSAEventSelect().";
			WSACloseEvent(g_hAcceptEvent);
+10 −8
Changes for src/windows/tcp.cpp: 10 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -199,7 +199,9 @@ size_t netplus::tcp::sendData(void* data, unsigned long size,int flags){
    buf.len = size;

    DWORD dwFlags = 0;
    SOCKET rval=::WSASend(_Socket,&buf,1,nullptr,flags,&_Overlapped,nullptr);
    DWORD dwBytes = 0;

    SOCKET rval=::WSASend(_Socket,&buf,1,&dwBytes,flags,&_Overlapped,nullptr);

    if(rval == SOCKET_ERROR){
        DWORD lerror=GetLastError();
@@ -207,14 +209,14 @@ size_t netplus::tcp::sendData(void* data, unsigned long size,int flags){
        int etype = NetException::Error;

        if (lerror == WSA_IO_PENDING) {
            etype = NetException::Note;
            return dwBytes;
        }

        exception[etype] << "Socket senddata failed on Socket: " << (int) _Socket
                                       << " ErrorMsg: " << lerror;
        throw exception;
    }
    return (size_t) rval;
    return (size_t) dwBytes;
}

size_t netplus::tcp::recvData(void* data, unsigned long size,int flags){
@@ -226,18 +228,18 @@ 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();

        int etype = NetException::Error;

        if (lerror == WSA_IO_PENDING) {
            etype = NetException::Note;
            return 0;
        }

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