Loading src/event/epoll.cpp +17 −17 Changes for src/event/epoll.cpp: 17 added lines, 17 removed lines. Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace netplus { class pollapi { public: pollapi(std::shared_ptr<eventapi> evcon,int timeout) : evconnection(evcon){ pollapi(eventapi *evcon,int timeout) : evconnection(evcon){ }; virtual ~pollapi(){ Loading @@ -80,12 +80,12 @@ namespace netplus { virtual void WriteEventHandler(int pos,const int tid,ULONG_PTR args)=0; virtual void CloseEventHandler(int pos,const int tid,ULONG_PTR args)=0; protected: std::shared_ptr<eventapi> evconnection; eventapi *evconnection; }; class poll : public pollapi{ public: poll(std::shared_ptr<socket> serversocket,std::shared_ptr<eventapi> evcon,int pollfd,int timeout) : poll(socket *serversocket,eventapi *evcon,int pollfd,int timeout) : pollapi(evcon,timeout), _ServerSocket (serversocket){ NetException exception; Loading Loading @@ -160,7 +160,7 @@ namespace netplus { con *ccon=nullptr; evconnection->CreateConnection(reinterpret_cast<void**>(&ccon)); evconnection->CreateConnection(&ccon); if(_ServerSocket->_Type==sockettype::TCP){ ccon->csock=new tcp(-1); Loading Loading @@ -194,7 +194,7 @@ namespace netplus { throw exception; } evconnection ->ConnectEvent(ccon,tid,args); evconnection ->ConnectEvent(*ccon,tid,args); }; void ReadEventHandler(int pos,const int tid,ULONG_PTR args) { Loading @@ -212,7 +212,7 @@ namespace netplus { rcon->state=EVIN; } evconnection->RequestEvent(rcon,tid,args); evconnection->RequestEvent(*rcon,tid,args); if(!rcon->SendData.empty()){ rcon->state=EVOUT; Loading @@ -236,7 +236,7 @@ namespace netplus { con *wcon = reinterpret_cast<con*>(_Events[pos].data.ptr); try{ evconnection->ResponseEvent(wcon,tid,args); evconnection->ResponseEvent(*wcon,tid,args); if(wcon->SendData.empty()){ wcon->state=EVIN; Loading Loading @@ -278,7 +278,7 @@ namespace netplus { except[NetException::Error] << "CloseEventHandler: can't close socket to epoll: " << errstr; throw except; } evconnection->DisconnectEvent(ccon,tid,args); evconnection->DisconnectEvent(*ccon,tid,args); delete ccon->csock; delete reinterpret_cast<con*>(_Events[pos].data.ptr); _Events[pos].data.ptr=nullptr; Loading Loading @@ -316,8 +316,8 @@ namespace netplus { int pollfd; int timeout; std::shared_ptr<eventapi> event; std::shared_ptr<socket> ssocket; eventapi *event; socket *ssocket; void *args; }; Loading Loading @@ -364,23 +364,23 @@ namespace netplus { } }; void eventapi::RequestEvent(con *curcon,const int tid,ULONG_PTR args){ void eventapi::RequestEvent(con &curcon,const int tid,ULONG_PTR args){ //dummy }; void eventapi::ResponseEvent(con *curcon,const int tid,ULONG_PTR args){ void eventapi::ResponseEvent(con &curcon,const int tid,ULONG_PTR args){ //dummy }; void eventapi::ConnectEvent(con *curcon,const int tid,ULONG_PTR args){ void eventapi::ConnectEvent(con &curcon,const int tid,ULONG_PTR args){ //dummy }; void eventapi::DisconnectEvent(con *curcon,const int tid,ULONG_PTR args){ void eventapi::DisconnectEvent(con &curcon,const int tid,ULONG_PTR args){ //dummy }; 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!"; Loading @@ -403,7 +403,7 @@ namespace netplus { raise(SIGINT); } void event::CreateConnection(void **res){ void event::CreateConnection(con **res){ *res=new con(this); } Loading Loading @@ -437,7 +437,7 @@ MAINWORKERLOOP: eargs.ssocket=_ServerSocket; eargs.pollfd=_pollFD; eargs.timeout=_Timeout; eargs.event=std::shared_ptr<event>(this); eargs.event=this; std::vector <std::thread> threadpool; Loading src/eventapi.h +8 −9 Changes for src/eventapi.h: 8 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -41,21 +41,19 @@ namespace netplus { class eventapi { public: /*HTTP API Events*/ virtual void RequestEvent(con *curcon,const int tid,ULONG_PTR args)=0; virtual void ResponseEvent(con *curcon,const int tid, ULONG_PTR args)=0; virtual void ConnectEvent(con *curcon,const int tid, ULONG_PTR args)=0; virtual void DisconnectEvent(con *curcon,const int tid, ULONG_PTR args)=0; virtual void RequestEvent(con &curcon,const int tid,ULONG_PTR args)=0; virtual void ResponseEvent(con &curcon,const int tid, ULONG_PTR args)=0; virtual void ConnectEvent(con &curcon,const int tid, ULONG_PTR args)=0; virtual void DisconnectEvent(con &curcon,const int tid, ULONG_PTR args)=0; /*memory allocation*/ virtual void CreateConnection(void **res)=0; virtual void CreateConnection(con **res)=0; protected: eventapi(){}; }; class event :public eventapi, public std::enable_shared_from_this<event> { public: event(std::shared_ptr<socket>& serversocket, int timeout=-1); void CreateConnection(void **res); event(socket *serversocket, int timeout=-1); void runEventloop(ULONG_PTR args=0); Loading @@ -66,9 +64,10 @@ namespace netplus { int threads; protected: void CreateConnection(con **res); event(const event &src); private: std::shared_ptr<socket> &_ServerSocket; socket *_ServerSocket; int _Timeout; int _pollFD; friend class EventWorker; Loading Loading
src/event/epoll.cpp +17 −17 Changes for src/event/epoll.cpp: 17 added lines, 17 removed lines. Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace netplus { class pollapi { public: pollapi(std::shared_ptr<eventapi> evcon,int timeout) : evconnection(evcon){ pollapi(eventapi *evcon,int timeout) : evconnection(evcon){ }; virtual ~pollapi(){ Loading @@ -80,12 +80,12 @@ namespace netplus { virtual void WriteEventHandler(int pos,const int tid,ULONG_PTR args)=0; virtual void CloseEventHandler(int pos,const int tid,ULONG_PTR args)=0; protected: std::shared_ptr<eventapi> evconnection; eventapi *evconnection; }; class poll : public pollapi{ public: poll(std::shared_ptr<socket> serversocket,std::shared_ptr<eventapi> evcon,int pollfd,int timeout) : poll(socket *serversocket,eventapi *evcon,int pollfd,int timeout) : pollapi(evcon,timeout), _ServerSocket (serversocket){ NetException exception; Loading Loading @@ -160,7 +160,7 @@ namespace netplus { con *ccon=nullptr; evconnection->CreateConnection(reinterpret_cast<void**>(&ccon)); evconnection->CreateConnection(&ccon); if(_ServerSocket->_Type==sockettype::TCP){ ccon->csock=new tcp(-1); Loading Loading @@ -194,7 +194,7 @@ namespace netplus { throw exception; } evconnection ->ConnectEvent(ccon,tid,args); evconnection ->ConnectEvent(*ccon,tid,args); }; void ReadEventHandler(int pos,const int tid,ULONG_PTR args) { Loading @@ -212,7 +212,7 @@ namespace netplus { rcon->state=EVIN; } evconnection->RequestEvent(rcon,tid,args); evconnection->RequestEvent(*rcon,tid,args); if(!rcon->SendData.empty()){ rcon->state=EVOUT; Loading @@ -236,7 +236,7 @@ namespace netplus { con *wcon = reinterpret_cast<con*>(_Events[pos].data.ptr); try{ evconnection->ResponseEvent(wcon,tid,args); evconnection->ResponseEvent(*wcon,tid,args); if(wcon->SendData.empty()){ wcon->state=EVIN; Loading Loading @@ -278,7 +278,7 @@ namespace netplus { except[NetException::Error] << "CloseEventHandler: can't close socket to epoll: " << errstr; throw except; } evconnection->DisconnectEvent(ccon,tid,args); evconnection->DisconnectEvent(*ccon,tid,args); delete ccon->csock; delete reinterpret_cast<con*>(_Events[pos].data.ptr); _Events[pos].data.ptr=nullptr; Loading Loading @@ -316,8 +316,8 @@ namespace netplus { int pollfd; int timeout; std::shared_ptr<eventapi> event; std::shared_ptr<socket> ssocket; eventapi *event; socket *ssocket; void *args; }; Loading Loading @@ -364,23 +364,23 @@ namespace netplus { } }; void eventapi::RequestEvent(con *curcon,const int tid,ULONG_PTR args){ void eventapi::RequestEvent(con &curcon,const int tid,ULONG_PTR args){ //dummy }; void eventapi::ResponseEvent(con *curcon,const int tid,ULONG_PTR args){ void eventapi::ResponseEvent(con &curcon,const int tid,ULONG_PTR args){ //dummy }; void eventapi::ConnectEvent(con *curcon,const int tid,ULONG_PTR args){ void eventapi::ConnectEvent(con &curcon,const int tid,ULONG_PTR args){ //dummy }; void eventapi::DisconnectEvent(con *curcon,const int tid,ULONG_PTR args){ void eventapi::DisconnectEvent(con &curcon,const int tid,ULONG_PTR args){ //dummy }; 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!"; Loading @@ -403,7 +403,7 @@ namespace netplus { raise(SIGINT); } void event::CreateConnection(void **res){ void event::CreateConnection(con **res){ *res=new con(this); } Loading Loading @@ -437,7 +437,7 @@ MAINWORKERLOOP: eargs.ssocket=_ServerSocket; eargs.pollfd=_pollFD; eargs.timeout=_Timeout; eargs.event=std::shared_ptr<event>(this); eargs.event=this; std::vector <std::thread> threadpool; Loading
src/eventapi.h +8 −9 Changes for src/eventapi.h: 8 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -41,21 +41,19 @@ namespace netplus { class eventapi { public: /*HTTP API Events*/ virtual void RequestEvent(con *curcon,const int tid,ULONG_PTR args)=0; virtual void ResponseEvent(con *curcon,const int tid, ULONG_PTR args)=0; virtual void ConnectEvent(con *curcon,const int tid, ULONG_PTR args)=0; virtual void DisconnectEvent(con *curcon,const int tid, ULONG_PTR args)=0; virtual void RequestEvent(con &curcon,const int tid,ULONG_PTR args)=0; virtual void ResponseEvent(con &curcon,const int tid, ULONG_PTR args)=0; virtual void ConnectEvent(con &curcon,const int tid, ULONG_PTR args)=0; virtual void DisconnectEvent(con &curcon,const int tid, ULONG_PTR args)=0; /*memory allocation*/ virtual void CreateConnection(void **res)=0; virtual void CreateConnection(con **res)=0; protected: eventapi(){}; }; class event :public eventapi, public std::enable_shared_from_this<event> { public: event(std::shared_ptr<socket>& serversocket, int timeout=-1); void CreateConnection(void **res); event(socket *serversocket, int timeout=-1); void runEventloop(ULONG_PTR args=0); Loading @@ -66,9 +64,10 @@ namespace netplus { int threads; protected: void CreateConnection(con **res); event(const event &src); private: std::shared_ptr<socket> &_ServerSocket; socket *_ServerSocket; int _Timeout; int _pollFD; friend class EventWorker; Loading