Loading src/eventapi.h +6 −2 Changes for src/eventapi.h: 6 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -42,9 +42,12 @@ namespace netplus { virtual void initEventHandler()=0; virtual const char *getpolltype()=0; /*pollstate*/ virtual int pollState(int pos)=0; /*EventHandler*/ virtual unsigned int waitEventHandler()=0; virtual int ConnectEventHandler(int pos)=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; Loading @@ -71,8 +74,9 @@ namespace netplus { virtual ~poll(); const char *getpolltype(); void initEventHandler(); int pollState(int pos); unsigned int waitEventHandler(); int ConnectEventHandler(int pos); void ConnectEventHandler(int pos); void ReadEventHandler(int pos); void WriteEventHandler(int pos); void CloseEventHandler(int pos); Loading src/linux/event.cpp +18 −12 Changes for src/linux/event.cpp: 18 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -99,6 +99,18 @@ namespace netplus { _Events[i].data.ptr = nullptr; }; int poll::pollState(int pos){ NetException exception; con* ccon = (con*)_Events[pos].data.ptr; if (!ccon) { return EventHandlerStatus::EVCON; } if (ccon->getSendData()) { return EventHandlerStatus::EVOUT; } return EventHandlerStatus::EVIN; } unsigned int poll::waitEventHandler() { int ret = epoll_wait(_pollFD, (struct epoll_event*)_Events, _ServerSocket->getMaxconnections(), -1); if (ret == -1) { Loading @@ -109,11 +121,10 @@ namespace netplus { return ret; }; int poll::ConnectEventHandler(int pos) { void poll::ConnectEventHandler(int pos) { NetException exception; con* ccon = (con*)_Events[pos].data.ptr; con *ccon; try { if (!ccon) { ccon = new con(this); ccon->conlock.lock(); ccon->csock = _ServerSocket->accept(); Loading @@ -130,13 +141,6 @@ namespace netplus { std::cout << "I'am connecting" << std::endl; ConnectEvent(ccon); ccon->conlock.unlock(); return EventHandlerStatus::EVIN; }else{ if (ccon->getSendData()) { return EventHandlerStatus::EVOUT; } return EventHandlerStatus::EVIN; } } catch (NetException& e) { delete ccon->csock; delete ccon; Loading Loading @@ -275,7 +279,10 @@ namespace netplus { try { if(!eventptr->trylockCon(i)) continue; switch (eventptr->ConnectEventHandler(i)) { switch (eventptr->pollState(i)) { case poll::EVCON: eventptr->ConnectEventHandler(i); break; case poll::EVIN: eventptr->ReadEventHandler(i); break; Loading @@ -292,7 +299,6 @@ namespace netplus { } catch (NetException& e) { std::cerr << e.what() << std::endl; eventptr->CloseEventHandler(i); eventptr->unlockCon(i); if (e.getErrorType() == NetException::Critical) { throw e; } Loading Loading
src/eventapi.h +6 −2 Changes for src/eventapi.h: 6 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -42,9 +42,12 @@ namespace netplus { virtual void initEventHandler()=0; virtual const char *getpolltype()=0; /*pollstate*/ virtual int pollState(int pos)=0; /*EventHandler*/ virtual unsigned int waitEventHandler()=0; virtual int ConnectEventHandler(int pos)=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; Loading @@ -71,8 +74,9 @@ namespace netplus { virtual ~poll(); const char *getpolltype(); void initEventHandler(); int pollState(int pos); unsigned int waitEventHandler(); int ConnectEventHandler(int pos); void ConnectEventHandler(int pos); void ReadEventHandler(int pos); void WriteEventHandler(int pos); void CloseEventHandler(int pos); Loading
src/linux/event.cpp +18 −12 Changes for src/linux/event.cpp: 18 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -99,6 +99,18 @@ namespace netplus { _Events[i].data.ptr = nullptr; }; int poll::pollState(int pos){ NetException exception; con* ccon = (con*)_Events[pos].data.ptr; if (!ccon) { return EventHandlerStatus::EVCON; } if (ccon->getSendData()) { return EventHandlerStatus::EVOUT; } return EventHandlerStatus::EVIN; } unsigned int poll::waitEventHandler() { int ret = epoll_wait(_pollFD, (struct epoll_event*)_Events, _ServerSocket->getMaxconnections(), -1); if (ret == -1) { Loading @@ -109,11 +121,10 @@ namespace netplus { return ret; }; int poll::ConnectEventHandler(int pos) { void poll::ConnectEventHandler(int pos) { NetException exception; con* ccon = (con*)_Events[pos].data.ptr; con *ccon; try { if (!ccon) { ccon = new con(this); ccon->conlock.lock(); ccon->csock = _ServerSocket->accept(); Loading @@ -130,13 +141,6 @@ namespace netplus { std::cout << "I'am connecting" << std::endl; ConnectEvent(ccon); ccon->conlock.unlock(); return EventHandlerStatus::EVIN; }else{ if (ccon->getSendData()) { return EventHandlerStatus::EVOUT; } return EventHandlerStatus::EVIN; } } catch (NetException& e) { delete ccon->csock; delete ccon; Loading Loading @@ -275,7 +279,10 @@ namespace netplus { try { if(!eventptr->trylockCon(i)) continue; switch (eventptr->ConnectEventHandler(i)) { switch (eventptr->pollState(i)) { case poll::EVCON: eventptr->ConnectEventHandler(i); break; case poll::EVIN: eventptr->ReadEventHandler(i); break; Loading @@ -292,7 +299,6 @@ namespace netplus { } catch (NetException& e) { std::cerr << e.what() << std::endl; eventptr->CloseEventHandler(i); eventptr->unlockCon(i); if (e.getErrorType() == NetException::Critical) { throw e; } Loading