Skip to content

Commit

Permalink
Add resetable handle
Browse files Browse the repository at this point in the history
Signed-off-by: Coldwings <coldwings@me.com>
  • Loading branch information
Coldwings committed Dec 13, 2023
1 parent 2da30ad commit 3109478
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions io/epoll-ng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ limitations under the License.

#include <vector>

#include "reset_handle.h"

namespace photon {
#ifndef EPOLLRDHUP
#define EPOLLRDHUP 0
#endif

class EventEngineEPollNG : public MasterEventEngine,
public CascadingEventEngine {
public CascadingEventEngine,
public ResetHandle {
public:
static int if_close_fd(int& fd) {
if (fd < 0) return 0;
Expand All @@ -41,8 +44,8 @@ class EventEngineEPollNG : public MasterEventEngine,
}

struct Poller {
int epfd = -1;
epoll_event events[16];
int epfd = -1;
int remains = 0;

int init() {
Expand Down Expand Up @@ -163,10 +166,18 @@ class EventEngineEPollNG : public MasterEventEngine,
if_close_fd(evfd);
return -1;
}
virtual ~EventEngineEPollNG() override {
int fini() {
LOG_INFO("Finish event engine: epoll-ng");
for (int i = 3; i >= 0; i--) poller(i).fini();
if_close_fd(evfd);
return 0;
}
int reset() override {
fini();
return init();
}
virtual ~EventEngineEPollNG() override {
fini();
}

virtual int add_interest(Event e) override {
Expand Down Expand Up @@ -255,7 +266,7 @@ class EventEngineEPollNG : public MasterEventEngine,
0, [&](epoll_data_t data) __INLINE__ { *ptr++ = data.ptr; },
[&]()
__INLINE__ { // make sure each fd receives all possible events
return (end - ptr) >= 3;
return end > ptr;
});
if (ptr == data) {
return 0;
Expand Down

0 comments on commit 3109478

Please sign in to comment.