Commit 3bb28e6a authored by jan.koester's avatar jan.koester
Browse files

build now again

parent ef9c04cb
Loading
Loading
Loading
Loading
+45 −42
Changes for src/event/iocp.cpp: 45 added lines, 42 removed lines.
Original line number Diff line number Diff line
@@ -28,9 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <iostream>
#include <algorithm>
#include <chrono>
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <cstring>

#include <signal.h>
@@ -81,7 +79,7 @@ namespace netplus {
	class poll {
	public:

		poll(HANDLE iocp, std::shared_ptr<eventapi> api, std::shared_ptr <socket> ssock)
		poll(HANDLE iocp, eventapi *api,socket *ssock)
			: g_iocp(iocp), g_eventapi(api), g_serversocket(ssock) {
		}

@@ -101,7 +99,7 @@ namespace netplus {
			client *pClientContext =new client(g_eventapi);

			if (g_serversocket->_Type == TCP)
				pClientContext->CurCon->csock = std::make_shared <tcp>();
				pClientContext->CurCon->csock = new tcp();

			try {
				g_serversocket->accept(lpfnAcceptEx, pClientContext->CurCon->csock);
@@ -115,11 +113,11 @@ namespace netplus {
				throw e;
			}

			g_eventapi->ConnectEvent(pClientContext->CurCon, tid, args);
			g_eventapi->ConnectEvent(*pClientContext->CurCon, tid, args);

			try {
				std::shared_ptr<char[]> buf;	
				size_t recv = pClientContext->CurCon->csock->recvData(buf, 0, 0);
				buffer buf(0);	
				size_t recv = pClientContext->CurCon->csock->recvData(buf, 0);
			} catch (NetException& e) {
				std::cerr << e.what() << std::endl;
				if (e.getErrorType() != NetException::Note)
@@ -129,13 +127,13 @@ namespace netplus {

	private:
		HANDLE           g_iocp;
		std::shared_ptr <socket>             g_serversocket;
		std::shared_ptr <eventapi>  	     g_eventapi;
		socket          *g_serversocket;
		eventapi  	    *g_eventapi;
		friend class	 client;
		friend class     EventWorker;
	};

	event::event(std::shared_ptr<socket>& serversocket, int timeout) : _ServerSocket(serversocket) {
	event::event(socket *serversocket, int timeout) : _ServerSocket(serversocket) {
		if (!serversocket) {
			NetException exp;
			exp[NetException::Critical] << "server socket empty!";
@@ -161,24 +159,28 @@ namespace netplus {
	event::~event() {
	}

	void eventapi::RequestEvent(std::shared_ptr <con> curcon, const int tid, ULONG_PTR args) {
	void eventapi::RequestEvent(con &curcon, const int tid, ULONG_PTR args) {
		//dummy
	};

	void eventapi::ResponseEvent(std::shared_ptr <con> curcon, const int tid, ULONG_PTR args) {
	void eventapi::ResponseEvent(con &curcon, const int tid, ULONG_PTR args) {
		//dummy
	};

	void eventapi::ConnectEvent(std::shared_ptr <con> curcon, const int tid, ULONG_PTR args) {
	void eventapi::ConnectEvent(con &curcon, const int tid, ULONG_PTR args) {
		//dummy
	};

	void eventapi::DisconnectEvent(std::shared_ptr <con> curcon, const int tid, ULONG_PTR args) {
	void eventapi::DisconnectEvent(con &curcon, const int tid, ULONG_PTR args) {
		//dummy
	};

	void eventapi::CreateConnetion(con *curcon) {
		curcon = new con(this);
	void event::CreateConnection(con **curcon) {
		*curcon = new con(this);
	}

	void event::DestroyConnection(con* res) {
		delete static_cast<con*>(res);
	}

	class EventWorkerArgs {
@@ -204,15 +206,15 @@ namespace netplus {

		int         timeout;
		HANDLE      eviocp;
		std::shared_ptr <poll>     evpoll;
		std::shared_ptr <eventapi> event;
		std::shared_ptr <socket>   ssocket;
		poll       *evpoll;
		eventapi   *event;
		socket     *ssocket;
		void* args;
	};

	class EventWorker {
	public:
		EventWorker(int tid, ULONG_PTR args, std::shared_ptr<EventWorkerArgs> eargs) {
		EventWorker(int tid, ULONG_PTR args,EventWorkerArgs *eargs) {
			for (;;) {
				ULONG_PTR   lpContext = 0;
				OVERLAPPED* pOverlapped = nullptr;
@@ -241,23 +243,26 @@ namespace netplus {
					con *curCon = pClientContext->CurCon;
					switch (pClientContext->State) {
						case IO_WRITE_STATE: {
							eargs->event->ResponseEvent(curCon, tid, args);
							eargs->event->ResponseEvent(*curCon, tid, args);
	
							ULONG ssize = curCon->SendData->size() < BLOCKSIZE ? (ULONG)curCon->SendData->size() : BLOCKSIZE;
							ULONG ssize = curCon->SendData.size() < BLOCKSIZE ? (ULONG)curCon->SendData.size() : BLOCKSIZE;
							DWORD ret = 0;
							ret = curCon->csock->sendData(curCon->SendData.data(), ssize, 0);
							curCon->SendData->resize(ret);
							if (curCon->SendData->empty())

							buffer buf(curCon->SendData.data(),ssize);
							ret = curCon->csock->sendData(buf,0);

							curCon->SendData.resize(ret);
							if (curCon->SendData.empty())
								pClientContext->State = IO_READ_STATE;
						}break;
						case IO_READ_STATE: {
							std::shared_ptr<char[]> buf(new char[BLOCKSIZE], std::default_delete<char[]>());
							size_t recv = curCon->csock->recvData(buf, BLOCKSIZE, 0);
							buffer buf(BLOCKSIZE);
							size_t recv = curCon->csock->recvData(buf, 0);

							curCon->RecvData->append(buf.get(), recv);
							std::copy(buf.data.buf,buf.data.buf+buf.size,std::back_inserter(curCon->RecvData));

							eargs->event->RequestEvent(curCon, tid, args);
							if (!curCon->SendData->empty())
							eargs->event->RequestEvent(*curCon, tid, args);
							if (!curCon->SendData.empty())
								pClientContext->State = IO_WRITE_STATE;
						}break;
					}
@@ -287,9 +292,7 @@ namespace netplus {

	void event::runEventloop(ULONG_PTR args) {
		NetException exception;
		std::shared_ptr<EventWorkerArgs> eargs;

		eargs = std::make_shared<EventWorkerArgs>();
		EventWorkerArgs eargs;

		HANDLE iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, nullptr, 0, 0);

@@ -306,20 +309,20 @@ namespace netplus {

		memset(&olOverlap, 0, sizeof(olOverlap));

		std::shared_ptr<poll> evpoll = std::make_shared<poll>(iocp,shared_from_this(), _ServerSocket);
		poll evpoll(iocp,this,_ServerSocket);

		eargs->ssocket = _ServerSocket;
		eargs->event = shared_from_this();
		eargs->evpoll = evpoll;
		eargs->timeout = _Timeout;
		eargs->eviocp = iocp;
		eargs.ssocket = _ServerSocket;
		eargs.event = this;
		eargs.evpoll = &evpoll;
		eargs.timeout = _Timeout;
		eargs.eviocp = iocp;

		std::vector <std::thread> threadpool;

		for (int i = 0; i < threads; i++) {
			try {
				threadpool.push_back(std::thread([eargs, args, i] {
					EventWorker(i, args, eargs);
				threadpool.push_back(std::thread([&eargs, args, i] {
					EventWorker(i, args, &eargs);
					}));
			}
			catch (NetException& e) {
@@ -361,7 +364,7 @@ namespace netplus {
				WSAEnumNetworkEvents(_ServerSocket->fd(), g_hAcceptEvent, &WSAEvents);
				if ((WSAEvents.lNetworkEvents & FD_ACCEPT) && (0 == WSAEvents.iErrorCode[FD_ACCEPT_BIT])) {
					try {
						evpoll->AcceptConnection(lpfnAcceptEx, 0, args);
						evpoll.AcceptConnection(lpfnAcceptEx, 0, args);
					}
					catch (NetException& e) {
						std::cerr << e.what() << std::endl;
+5
Changes for src/posix/udp.cpp: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -218,6 +218,11 @@ size_t netplus::udp::recvData(buffer &data,int flags){
        throw exception;
    }

    WSABUF buf;

    buf.buf = data.data.buf;
    buf.len = data.size;

    int recvsize=::recv(_Socket,
                            data.data.buf,
                            data.size,
+3 −3
Changes for src/socket.h: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ namespace netplus {
            
            virtual void             accept(socket *csock)=0;
#ifdef Windows 
            virtual void             accept(LPFN_ACCEPTEX lpfnAcceptEx, std::shared_ptr<socket> &csock)=0;
            virtual void             accept(LPFN_ACCEPTEX lpfnAcceptEx, socket *csock)=0;
#endif
            virtual void             bind()=0;
            virtual void             listen()=0;
@@ -129,7 +129,7 @@ namespace netplus {
                int sockopts);
            ~tcp();
#ifdef Windows 
            void          accept(LPFN_ACCEPTEX lpfnAcceptEx, std::shared_ptr<socket> &csock);
            void          accept(LPFN_ACCEPTEX lpfnAcceptEx,socket *csock);
#endif
            void          accept(socket *csock);
            void          bind();
@@ -163,7 +163,7 @@ namespace netplus {

            void          accept(socket *csock);
#ifdef Windows 
            void          accept(LPFN_ACCEPTEX lpfnAcceptEx, std::unique_ptr<socket> &csock);
            void          accept(LPFN_ACCEPTEX lpfnAcceptEx,socket *csock);
#endif
            void          bind();
            void          listen();
+18 −8
Changes for src/windows/tcp.cpp: 18 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ int netplus::tcp::getMaxconnections(){
    return _Maxconnections;
}

void netplus::tcp::accept(std::shared_ptr<socket> &csock) {
void netplus::tcp::accept(socket *csock) {
    NetException exception;

    ((struct addrinfo*)(csock->_SocketInfo))->ai_addr = (struct sockaddr*)malloc(((struct addrinfo*)(_SocketInfo))->ai_addrlen);
@@ -152,7 +152,7 @@ void netplus::tcp::accept(std::shared_ptr<socket> &csock) {
    }
}

void netplus::tcp::accept(LPFN_ACCEPTEX lpfnAcceptEx, std::shared_ptr<socket> &csock){
void netplus::tcp::accept(LPFN_ACCEPTEX lpfnAcceptEx,socket *csock){
    NetException exception;
    DWORD dwbytes = 0;
    CHAR AcceptBuffer[2 * (sizeof(SOCKADDR_IN6) + 16)];
@@ -193,11 +193,15 @@ void netplus::tcp::bind(){
}


size_t netplus::tcp::sendData(std::shared_ptr<const char[]> &data,size_t size,int flags){
size_t netplus::tcp::sendData(buffer &data,int flags){
    WSABUF buf{0};

    buf.buf = (char*)data.get();
    buf.len = size;
    if (data.ptr)
        buf.buf = (char*)data.data.ptr;
    else
        buf.buf = data.data.buf;

    buf.len = data.size;

    DWORD dwsend = 0;

@@ -219,13 +223,19 @@ size_t netplus::tcp::sendData(std::shared_ptr<const char[]> &data,size_t size,in
    return (size_t)dwsend;
}

size_t netplus::tcp::recvData(std::shared_ptr<char[]> &data,size_t size,int flags){
size_t netplus::tcp::recvData(buffer &data,int flags){
    NetException exception;

    if (data.ptr) {
        exception[NetException::Error] << "Socket recvdata error buffer with const ptr not supported!";
        throw exception;
    }

    WSABUF buf;

	buf.buf = data.get();
    buf.len = size;
	buf.buf = data.data.buf;
    buf.len = data.size;

    DWORD dwBytes = 0;

    int rval=::WSARecv(_Socket, &buf, 1,&dwBytes,(LPDWORD) &flags, &_Overlapped, nullptr);
+17 −8
Changes for src/windows/udp.cpp: 17 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ int netplus::udp::getMaxconnections() {
    return _Maxconnections;
}

void netplus::udp::accept(std::shared_ptr<socket> &csock) {
void netplus::udp::accept(socket *csock) {
    NetException exception;

    ((struct addrinfo *)(csock->_SocketInfo))->ai_addr=(struct sockaddr*) malloc(((struct addrinfo *)(_SocketInfo))->ai_addrlen);
@@ -148,7 +148,7 @@ void netplus::udp::accept(std::shared_ptr<socket> &csock) {
    }
}

void netplus::udp::accept(LPFN_ACCEPTEX lpfnAcceptEx, std::shared_ptr<socket> &csock) {
void netplus::udp::accept(LPFN_ACCEPTEX lpfnAcceptEx,socket *csock) {
    NetException exception;
    DWORD dwbytes = 0;
    CHAR AcceptBuffer[2 * (sizeof(SOCKADDR_IN6) + 16)];
@@ -188,13 +188,17 @@ void netplus::udp::bind() {
    }
}

size_t netplus::udp::sendData(std::shared_ptr<const char[]> &data,size_t size, int flags) {
size_t netplus::udp::sendData(buffer &data, int flags) {
    NetException exception;

    WSABUF buf;

    buf.buf = (char*)data.get();
    buf.len = size;
    if(data.ptr)
        buf.buf = (char*)data.data.ptr;
    else
		buf.buf = data.data.buf;
    
    buf.len = data.size;

    DWORD dwBytes = 0;
    DWORD dwFlags = 0;
@@ -213,14 +217,19 @@ size_t netplus::udp::sendData(std::shared_ptr<const char[]> &data,size_t size, i
    return (size_t)rval;
}

size_t netplus::udp::recvData(std::shared_ptr<char[]> &data, size_t size, int flags) {
size_t netplus::udp::recvData(buffer &data, int flags) {

    NetException exception;
    
    if (data.ptr) {
        exception[NetException::Error] << "Socket recvdata error buffer with const ptr not supported!";
        throw exception;
    }

    WSABUF buf;

    buf.buf = (char*)data.get();
    buf.len = size;
    buf.buf = data.data.buf;
    buf.len = data.size;

    DWORD dwBytes = 0;
    DWORD dwFlags = 0;