Loading src/eventapi.h +5 −5 Changes for src/eventapi.h: 5 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -41,10 +41,10 @@ namespace netplus { class eventapi { public: /*HTTP API Events*/ virtual void RequestEvent(con *curcon); virtual void ResponseEvent(con *curcon); virtual void ConnectEvent(con *curcon); virtual void DisconnectEvent(con *curcon); virtual void RequestEvent(con *curcon,const int tid,void *args); virtual void ResponseEvent(con *curcon,const int tid,void *args); virtual void ConnectEvent(con *curcon,const int tid,void *args); virtual void DisconnectEvent(con *curcon,const int tid,void *args); /*memory allocation*/ virtual void CreateConnetion(con **curon)=0; Loading @@ -54,7 +54,7 @@ namespace netplus { class event : public eventapi{ public: event(socket *serversocket,int timeout = 60); void runEventloop(); void runEventloop(void *args=nullptr); static void *WorkerThread(void *wrkevent); virtual ~event(); Loading src/linux/event.cpp +28 −37 Changes for src/linux/event.cpp: 28 added lines, 37 removed lines. Original line number Diff line number Diff line Loading @@ -72,10 +72,10 @@ namespace netplus { /*EventHandler*/ virtual int waitEventHandler()=0; virtual void ConnectEventHandler(int pos)=0; virtual void ReadEventHandler(int pos)=0; virtual void WriteEventHandler(int pos)=0; virtual void CloseEventHandler(int pos)=0; virtual void ConnectEventHandler(int pos,const int tid,void *args)=0; virtual void ReadEventHandler(int pos,const int tid,void *args)=0; virtual void WriteEventHandler(int pos,const int tid,void *args)=0; virtual void CloseEventHandler(int pos,const int tid,void *args)=0; protected: eventapi *_evtapi; Loading Loading @@ -154,7 +154,7 @@ namespace netplus { return evn; }; void ConnectEventHandler(int pos) { void ConnectEventHandler(int pos,const int tid,void *args) { NetException exception; con *ccon=(con*)_Events[pos].data.ptr; if(!ccon){ Loading @@ -168,16 +168,7 @@ namespace netplus { } } try{ _ServerSocket->accept(ccon->csock); }catch(NetException &e){ if(e.getErrorType()== NetException::Note){ ccon->state=EVCON; setpollEvents(ccon,EPOLLIN | EPOLLET | EPOLLONESHOT); return; } throw e; } ccon->csock->setnonblocking(); Loading Loading @@ -205,11 +196,11 @@ namespace netplus { } throw exception; } _evtapi->ConnectEvent(ccon); _evtapi->ConnectEvent(ccon,tid,args); }; void ReadEventHandler(int pos) { void ReadEventHandler(int pos,const int tid,void *args) { con *rcon = (con*)_Events[pos].data.ptr; if(!rcon) Loading @@ -225,7 +216,7 @@ namespace netplus { rcon->state=EVIN; } _evtapi->RequestEvent(rcon); _evtapi->RequestEvent(rcon,tid,args); if(!rcon->SendData.empty()){ rcon->state=EVOUT; Loading @@ -245,11 +236,11 @@ namespace netplus { } }; void WriteEventHandler(int pos) { void WriteEventHandler(int pos,const int tid,void *args) { con *wcon = (con*)_Events[pos].data.ptr; try{ _evtapi->ResponseEvent(wcon); _evtapi->ResponseEvent(wcon,tid,args); if(wcon->SendData.empty()){ wcon->state=EVIN; Loading Loading @@ -282,7 +273,7 @@ namespace netplus { }; void CloseEventHandler(int pos) { void CloseEventHandler(int pos,const int tid,void *args) { con *ccon = (con*)_Events[pos].data.ptr; if(!ccon) Loading @@ -299,7 +290,7 @@ namespace netplus { } delete ccon->csock; _evtapi->DisconnectEvent(ccon); _evtapi->DisconnectEvent(ccon,tid,args); _evtapi->deleteConnetion(ccon); Loading Loading @@ -330,6 +321,7 @@ namespace netplus { pollfd=eargs.pollfd; ssocket=eargs.ssocket; timeout=eargs.timeout; args=eargs.args; } int pollfd; Loading @@ -337,14 +329,13 @@ namespace netplus { eventapi *event; socket *ssocket; void *args; }; class EventWorker { public: EventWorker(void* args) { EventWorkerArgs *wargs=(EventWorkerArgs*)args; poll pollptr(wargs->ssocket,wargs->event,wargs->pollfd,wargs->timeout); EventWorker(int tid,EventWorkerArgs* args) { poll pollptr(args->ssocket,args->event,args->pollfd,args->timeout); EVENTLOOP: try { Loading @@ -353,18 +344,18 @@ EVENTLOOP: try{ switch (pollptr.pollState(i)) { case pollapi::EventHandlerStatus::EVCON: pollptr.ConnectEventHandler(i); pollptr.ConnectEventHandler(i,tid,args); break; case pollapi::EventHandlerStatus::EVIN: pollptr.ReadEventHandler(i); pollptr.ReadEventHandler(i,tid,args); break; case pollapi::EventHandlerStatus::EVOUT: pollptr.WriteEventHandler(i); pollptr.WriteEventHandler(i,tid,args); break; default: NetException e; e[NetException::Error] << "EventWorker: Request type not kwon!"; pollptr.CloseEventHandler(i); pollptr.CloseEventHandler(i,tid,args); throw e; } }catch(NetException& e){ Loading @@ -375,7 +366,7 @@ EVENTLOOP: break; default: std::cerr << e.what() << std::endl; pollptr.CloseEventHandler(i); pollptr.CloseEventHandler(i,tid,args); break; } } Loading @@ -392,19 +383,19 @@ EVENTLOOP: } }; void eventapi::RequestEvent(con *curcon){ void eventapi::RequestEvent(con *curcon,const int tid,void *args){ //dummy }; void eventapi::ResponseEvent(con *curcon){ void eventapi::ResponseEvent(con *curcon,const int tid,void *args){ //dummy }; void eventapi::ConnectEvent(con *curcon){ void eventapi::ConnectEvent(con *curcon,const int tid,void *args){ //dummy }; void eventapi::DisconnectEvent(con *curcon){ void eventapi::DisconnectEvent(con *curcon,const int tid,void *args){ //dummy }; Loading Loading @@ -432,7 +423,7 @@ EVENTLOOP: event::~event() { } void event::runEventloop() { void event::runEventloop(void *args) { NetException exception; size_t thrs = sysconf(_SC_NPROCESSORS_ONLN); Loading Loading @@ -468,8 +459,8 @@ EVENTLOOP: for (size_t i = 0; i < thrs; i++) { try { threadpool[i] = new std::thread([&eargs]{ EventWorker *evt = new EventWorker((void*)&eargs); threadpool[i] = new std::thread([&eargs,i]{ EventWorker *evt = new EventWorker(i,&eargs); delete evt; }); } catch (NetException& e) { Loading Loading
src/eventapi.h +5 −5 Changes for src/eventapi.h: 5 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -41,10 +41,10 @@ namespace netplus { class eventapi { public: /*HTTP API Events*/ virtual void RequestEvent(con *curcon); virtual void ResponseEvent(con *curcon); virtual void ConnectEvent(con *curcon); virtual void DisconnectEvent(con *curcon); virtual void RequestEvent(con *curcon,const int tid,void *args); virtual void ResponseEvent(con *curcon,const int tid,void *args); virtual void ConnectEvent(con *curcon,const int tid,void *args); virtual void DisconnectEvent(con *curcon,const int tid,void *args); /*memory allocation*/ virtual void CreateConnetion(con **curon)=0; Loading @@ -54,7 +54,7 @@ namespace netplus { class event : public eventapi{ public: event(socket *serversocket,int timeout = 60); void runEventloop(); void runEventloop(void *args=nullptr); static void *WorkerThread(void *wrkevent); virtual ~event(); Loading
src/linux/event.cpp +28 −37 Changes for src/linux/event.cpp: 28 added lines, 37 removed lines. Original line number Diff line number Diff line Loading @@ -72,10 +72,10 @@ namespace netplus { /*EventHandler*/ virtual int waitEventHandler()=0; virtual void ConnectEventHandler(int pos)=0; virtual void ReadEventHandler(int pos)=0; virtual void WriteEventHandler(int pos)=0; virtual void CloseEventHandler(int pos)=0; virtual void ConnectEventHandler(int pos,const int tid,void *args)=0; virtual void ReadEventHandler(int pos,const int tid,void *args)=0; virtual void WriteEventHandler(int pos,const int tid,void *args)=0; virtual void CloseEventHandler(int pos,const int tid,void *args)=0; protected: eventapi *_evtapi; Loading Loading @@ -154,7 +154,7 @@ namespace netplus { return evn; }; void ConnectEventHandler(int pos) { void ConnectEventHandler(int pos,const int tid,void *args) { NetException exception; con *ccon=(con*)_Events[pos].data.ptr; if(!ccon){ Loading @@ -168,16 +168,7 @@ namespace netplus { } } try{ _ServerSocket->accept(ccon->csock); }catch(NetException &e){ if(e.getErrorType()== NetException::Note){ ccon->state=EVCON; setpollEvents(ccon,EPOLLIN | EPOLLET | EPOLLONESHOT); return; } throw e; } ccon->csock->setnonblocking(); Loading Loading @@ -205,11 +196,11 @@ namespace netplus { } throw exception; } _evtapi->ConnectEvent(ccon); _evtapi->ConnectEvent(ccon,tid,args); }; void ReadEventHandler(int pos) { void ReadEventHandler(int pos,const int tid,void *args) { con *rcon = (con*)_Events[pos].data.ptr; if(!rcon) Loading @@ -225,7 +216,7 @@ namespace netplus { rcon->state=EVIN; } _evtapi->RequestEvent(rcon); _evtapi->RequestEvent(rcon,tid,args); if(!rcon->SendData.empty()){ rcon->state=EVOUT; Loading @@ -245,11 +236,11 @@ namespace netplus { } }; void WriteEventHandler(int pos) { void WriteEventHandler(int pos,const int tid,void *args) { con *wcon = (con*)_Events[pos].data.ptr; try{ _evtapi->ResponseEvent(wcon); _evtapi->ResponseEvent(wcon,tid,args); if(wcon->SendData.empty()){ wcon->state=EVIN; Loading Loading @@ -282,7 +273,7 @@ namespace netplus { }; void CloseEventHandler(int pos) { void CloseEventHandler(int pos,const int tid,void *args) { con *ccon = (con*)_Events[pos].data.ptr; if(!ccon) Loading @@ -299,7 +290,7 @@ namespace netplus { } delete ccon->csock; _evtapi->DisconnectEvent(ccon); _evtapi->DisconnectEvent(ccon,tid,args); _evtapi->deleteConnetion(ccon); Loading Loading @@ -330,6 +321,7 @@ namespace netplus { pollfd=eargs.pollfd; ssocket=eargs.ssocket; timeout=eargs.timeout; args=eargs.args; } int pollfd; Loading @@ -337,14 +329,13 @@ namespace netplus { eventapi *event; socket *ssocket; void *args; }; class EventWorker { public: EventWorker(void* args) { EventWorkerArgs *wargs=(EventWorkerArgs*)args; poll pollptr(wargs->ssocket,wargs->event,wargs->pollfd,wargs->timeout); EventWorker(int tid,EventWorkerArgs* args) { poll pollptr(args->ssocket,args->event,args->pollfd,args->timeout); EVENTLOOP: try { Loading @@ -353,18 +344,18 @@ EVENTLOOP: try{ switch (pollptr.pollState(i)) { case pollapi::EventHandlerStatus::EVCON: pollptr.ConnectEventHandler(i); pollptr.ConnectEventHandler(i,tid,args); break; case pollapi::EventHandlerStatus::EVIN: pollptr.ReadEventHandler(i); pollptr.ReadEventHandler(i,tid,args); break; case pollapi::EventHandlerStatus::EVOUT: pollptr.WriteEventHandler(i); pollptr.WriteEventHandler(i,tid,args); break; default: NetException e; e[NetException::Error] << "EventWorker: Request type not kwon!"; pollptr.CloseEventHandler(i); pollptr.CloseEventHandler(i,tid,args); throw e; } }catch(NetException& e){ Loading @@ -375,7 +366,7 @@ EVENTLOOP: break; default: std::cerr << e.what() << std::endl; pollptr.CloseEventHandler(i); pollptr.CloseEventHandler(i,tid,args); break; } } Loading @@ -392,19 +383,19 @@ EVENTLOOP: } }; void eventapi::RequestEvent(con *curcon){ void eventapi::RequestEvent(con *curcon,const int tid,void *args){ //dummy }; void eventapi::ResponseEvent(con *curcon){ void eventapi::ResponseEvent(con *curcon,const int tid,void *args){ //dummy }; void eventapi::ConnectEvent(con *curcon){ void eventapi::ConnectEvent(con *curcon,const int tid,void *args){ //dummy }; void eventapi::DisconnectEvent(con *curcon){ void eventapi::DisconnectEvent(con *curcon,const int tid,void *args){ //dummy }; Loading Loading @@ -432,7 +423,7 @@ EVENTLOOP: event::~event() { } void event::runEventloop() { void event::runEventloop(void *args) { NetException exception; size_t thrs = sysconf(_SC_NPROCESSORS_ONLN); Loading Loading @@ -468,8 +459,8 @@ EVENTLOOP: for (size_t i = 0; i < thrs; i++) { try { threadpool[i] = new std::thread([&eargs]{ EventWorker *evt = new EventWorker((void*)&eargs); threadpool[i] = new std::thread([&eargs,i]{ EventWorker *evt = new EventWorker(i,&eargs); delete evt; }); } catch (NetException& e) { Loading