Loading src/event/epoll.cpp +24 −18 Changes for src/event/epoll.cpp: 24 added lines, 18 removed lines. Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <stdlib.h> #include <stdint.h> #include <mutex> #include <map> #include <cstring> #include <errno.h> Loading @@ -57,10 +58,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define BLOCKSIZE 16384 namespace netplus { class poll; bool RUNNING=true; std::vector<poll*> POLLS; std::mutex CLOSE_HANDLER_MUTEX; std::vector<socket*> SSOCKETS; std::map<int,con*> CONNECTIONS; std::mutex POLL_HANDLER_MUTEX; class pollapi { public: Loading Loading @@ -100,23 +103,16 @@ namespace netplus { _Timeout(timeout) { SSOCKETS.emplace_back(_ServerSocket); for (int i = 0; i <_ServerSocket->getMaxconnections(); ++i){ _Events[i].events=-1; _Events[i].data.fd=-1; _Events[i].data.ptr=nullptr; } POLLS.push_back(this); }; virtual ~poll() { for (int i = 0; i <_ServerSocket->getMaxconnections(); ++i){ CloseEventHandler(i,0,0); } for(auto poll = POLLS.begin(); poll!=POLLS.end(); ++poll){ if(*poll==this) POLLS.erase(poll); }; }; /*basic functions*/ Loading Loading @@ -206,8 +202,12 @@ namespace netplus { } evconnection ->ConnectEvent(*ccon,tid,args); { std::lock_guard<std::mutex> clock(ccon->event_mutex),global_lock(POLL_HANDLER_MUTEX); CONNECTIONS.emplace(ccon->csock->fd(),ccon.get()); ccon.release(); } }; void ReadEventHandler(int pos,const int tid,ULONG_PTR args) { Loading Loading @@ -296,7 +296,7 @@ namespace netplus { }; void CloseEventHandler(int pos,const int tid,ULONG_PTR args) { std::lock_guard<std::mutex> global_lock(CLOSE_HANDLER_MUTEX); std::lock_guard<std::mutex> global_lock(POLL_HANDLER_MUTEX); if (!_Events[pos].data.ptr) { return; Loading Loading @@ -324,6 +324,8 @@ namespace netplus { } } _Events[pos].data.ptr = nullptr; CONNECTIONS.erase(ccon->csock->fd()); } delete ccon; Loading Loading @@ -459,12 +461,16 @@ namespace netplus { } void signalHandler(int signum) { std::lock_guard<std::mutex> lock(POLL_HANDLER_MUTEX); switch(signum){ case SIGINT: for(poll *polli : POLLS){ polli->_ServerSocket->close(); for(int i = 0; i< polli->_ServerSocket->getMaxconnections(); ++i){ polli->setpollEvents(i,EPOLLHUP | EPOLLONESHOT); for(auto ssock : SSOCKETS){ ssock->close(); } for(auto ccon : CONNECTIONS){ { std::lock_guard<std::mutex> clock(ccon.second->event_mutex); ccon.second->csock->close(); } } RUNNING=false; Loading Loading
src/event/epoll.cpp +24 −18 Changes for src/event/epoll.cpp: 24 added lines, 18 removed lines. Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <stdlib.h> #include <stdint.h> #include <mutex> #include <map> #include <cstring> #include <errno.h> Loading @@ -57,10 +58,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define BLOCKSIZE 16384 namespace netplus { class poll; bool RUNNING=true; std::vector<poll*> POLLS; std::mutex CLOSE_HANDLER_MUTEX; std::vector<socket*> SSOCKETS; std::map<int,con*> CONNECTIONS; std::mutex POLL_HANDLER_MUTEX; class pollapi { public: Loading Loading @@ -100,23 +103,16 @@ namespace netplus { _Timeout(timeout) { SSOCKETS.emplace_back(_ServerSocket); for (int i = 0; i <_ServerSocket->getMaxconnections(); ++i){ _Events[i].events=-1; _Events[i].data.fd=-1; _Events[i].data.ptr=nullptr; } POLLS.push_back(this); }; virtual ~poll() { for (int i = 0; i <_ServerSocket->getMaxconnections(); ++i){ CloseEventHandler(i,0,0); } for(auto poll = POLLS.begin(); poll!=POLLS.end(); ++poll){ if(*poll==this) POLLS.erase(poll); }; }; /*basic functions*/ Loading Loading @@ -206,8 +202,12 @@ namespace netplus { } evconnection ->ConnectEvent(*ccon,tid,args); { std::lock_guard<std::mutex> clock(ccon->event_mutex),global_lock(POLL_HANDLER_MUTEX); CONNECTIONS.emplace(ccon->csock->fd(),ccon.get()); ccon.release(); } }; void ReadEventHandler(int pos,const int tid,ULONG_PTR args) { Loading Loading @@ -296,7 +296,7 @@ namespace netplus { }; void CloseEventHandler(int pos,const int tid,ULONG_PTR args) { std::lock_guard<std::mutex> global_lock(CLOSE_HANDLER_MUTEX); std::lock_guard<std::mutex> global_lock(POLL_HANDLER_MUTEX); if (!_Events[pos].data.ptr) { return; Loading Loading @@ -324,6 +324,8 @@ namespace netplus { } } _Events[pos].data.ptr = nullptr; CONNECTIONS.erase(ccon->csock->fd()); } delete ccon; Loading Loading @@ -459,12 +461,16 @@ namespace netplus { } void signalHandler(int signum) { std::lock_guard<std::mutex> lock(POLL_HANDLER_MUTEX); switch(signum){ case SIGINT: for(poll *polli : POLLS){ polli->_ServerSocket->close(); for(int i = 0; i< polli->_ServerSocket->getMaxconnections(); ++i){ polli->setpollEvents(i,EPOLLHUP | EPOLLONESHOT); for(auto ssock : SSOCKETS){ ssock->close(); } for(auto ccon : CONNECTIONS){ { std::lock_guard<std::mutex> clock(ccon.second->event_mutex); ccon.second->csock->close(); } } RUNNING=false; Loading