From 40c411c6de4565f188a4dec90ced47b62a54df7e Mon Sep 17 00:00:00 2001 From: qinhan <35907137+overtalk@users.noreply.github.com> Date: Fri, 15 May 2020 15:21:53 +0800 Subject: [PATCH 1/2] optimize unregister pollerEvent in macos platform --- include/brynet/net/TcpConnection.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/brynet/net/TcpConnection.hpp b/include/brynet/net/TcpConnection.hpp index c59b7606..98f278e3 100644 --- a/include/brynet/net/TcpConnection.hpp +++ b/include/brynet/net/TcpConnection.hpp @@ -929,14 +929,14 @@ namespace brynet { namespace net { ev.data.ptr = (Channel*)(this); epoll_ctl(mEventLoop->getEpollHandle(), EPOLL_CTL_MOD, mSocket->getFD(), &ev); #elif defined BRYNET_PLATFORM_DARWIN - struct kevent ev[2]; - memset(&ev, 0, sizeof(ev)); - int n = 0; - EV_SET(&ev[n++], mSocket->getFD(), EVFILT_READ, EV_ENABLE, 0, 0, (Channel*)(this)); - EV_SET(&ev[n++], mSocket->getFD(), EVFILT_WRITE, EV_ENABLE, 0, 0, (Channel*)(this)); - - struct timespec now = { 0, 0 }; - kevent(mEventLoop->getKqueueHandle(), ev, n, NULL, 0, &now); +// struct kevent ev[2]; +// memset(&ev, 0, sizeof(ev)); +// int n = 0; +// EV_SET(&ev[n++], mSocket->getFD(), EVFILT_READ, EV_ENABLE, 0, 0, (Channel*)(this)); +// EV_SET(&ev[n++], mSocket->getFD(), EVFILT_WRITE, EV_ENABLE, 0, 0, (Channel*)(this)); + +// struct timespec now = { 0, 0 }; +// kevent(mEventLoop->getKqueueHandle(), ev, n, NULL, 0, &now); #endif } void unregisterPollerEvent() From 4a86f359c52a3b8547a6b3b94fcbd8f1a5299ccc Mon Sep 17 00:00:00 2001 From: qinhan <35907137+overtalk@users.noreply.github.com> Date: Fri, 15 May 2020 15:26:13 +0800 Subject: [PATCH 2/2] fix bug --- include/brynet/net/TcpConnection.hpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/include/brynet/net/TcpConnection.hpp b/include/brynet/net/TcpConnection.hpp index 98f278e3..fa21556b 100644 --- a/include/brynet/net/TcpConnection.hpp +++ b/include/brynet/net/TcpConnection.hpp @@ -929,14 +929,14 @@ namespace brynet { namespace net { ev.data.ptr = (Channel*)(this); epoll_ctl(mEventLoop->getEpollHandle(), EPOLL_CTL_MOD, mSocket->getFD(), &ev); #elif defined BRYNET_PLATFORM_DARWIN -// struct kevent ev[2]; -// memset(&ev, 0, sizeof(ev)); -// int n = 0; -// EV_SET(&ev[n++], mSocket->getFD(), EVFILT_READ, EV_ENABLE, 0, 0, (Channel*)(this)); -// EV_SET(&ev[n++], mSocket->getFD(), EVFILT_WRITE, EV_ENABLE, 0, 0, (Channel*)(this)); + struct kevent ev[2]; + memset(&ev, 0, sizeof(ev)); + int n = 0; + EV_SET(&ev[n++], mSocket->getFD(), EVFILT_READ, EV_ENABLE, 0, 0, (Channel*)(this)); + EV_SET(&ev[n++], mSocket->getFD(), EVFILT_WRITE, EV_ENABLE, 0, 0, (Channel*)(this)); -// struct timespec now = { 0, 0 }; -// kevent(mEventLoop->getKqueueHandle(), ev, n, NULL, 0, &now); + struct timespec now = { 0, 0 }; + kevent(mEventLoop->getKqueueHandle(), ev, n, NULL, 0, &now); #endif } void unregisterPollerEvent() @@ -945,14 +945,14 @@ namespace brynet { namespace net { struct epoll_event ev = { 0, { nullptr } }; epoll_ctl(mEventLoop->getEpollHandle(), EPOLL_CTL_DEL, mSocket->getFD(), &ev); #elif defined BRYNET_PLATFORM_DARWIN - struct kevent ev[2]; - memset(&ev, 0, sizeof(ev)); - int n = 0; - EV_SET(&ev[n++], mSocket->getFD(), EVFILT_READ, EV_DELETE, 0, 0, NULL); - EV_SET(&ev[n++], mSocket->getFD(), EVFILT_WRITE, EV_DELETE, 0, 0, NULL); +// struct kevent ev[2]; +// memset(&ev, 0, sizeof(ev)); +// int n = 0; +// EV_SET(&ev[n++], mSocket->getFD(), EVFILT_READ, EV_DELETE, 0, 0, NULL); +// EV_SET(&ev[n++], mSocket->getFD(), EVFILT_WRITE, EV_DELETE, 0, 0, NULL); - struct timespec now = { 0, 0 }; - kevent(mEventLoop->getKqueueHandle(), ev, n, NULL, 0, &now); +// struct timespec now = { 0, 0 }; +// kevent(mEventLoop->getKqueueHandle(), ev, n, NULL, 0, &now); #endif } #endif