Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Wen Yi committed Aug 25, 2024
2 parents 84ecca7 + 5786151 commit a973821
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
37 changes: 26 additions & 11 deletions src/net/kqueue_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,21 @@ void KqueueEvent::AddEvent(uint64_t id, int fd, int mask) {
}

void KqueueEvent::DelEvent(int fd) {
struct kevent change;
EV_SET(&change, fd, EVENT_READ, EV_DELETE, 0, 0, nullptr);
if (kevent(EvFd(), &change, 1, nullptr, 0, nullptr) == -1) {
ERROR("KqueueEvent Del read Event EvFd:{},fd:{}, kevent error:{}", EvFd(), fd, errno);
if (mode_ & EVENT_MODE_READ) {
struct kevent change;
EV_SET(&change, fd, EVENT_READ, EV_DELETE, 0, 0, nullptr);
if (kevent(EvFd(), &change, 1, nullptr, 0, nullptr) == -1) {
ERROR("KqueueEvent Del read Event EvFd:{},fd:{}, kevent error:{}", EvFd(), fd, errno);
}
}
EV_SET(&change, fd, EVENT_WRITE, EV_DELETE, 0, 0, nullptr);
if (kevent(EvFd(), &change, 1, nullptr, 0, nullptr) == -1) {
ERROR("KqueueEvent Del write Event EvFd:{},fd:{}, kevent error:{}", EvFd(), fd, errno);
if (mode_ & EVENT_MODE_WRITE) {
struct kevent change;
EV_SET(&change, fd, EVENT_WRITE, EV_DELETE, 0, 0, nullptr);
if (kevent(EvFd(), &change, 1, nullptr, 0, nullptr) == -1) {
if (errno != ENOENT) { // If the event does not exist, it will return ENOENT
ERROR("KqueueEvent Del write Event EvFd:{},fd:{}, kevent error:{}", EvFd(), fd, errno);
}
}
}
}

Expand Down Expand Up @@ -191,18 +198,26 @@ void KqueueEvent::DoWrite(const struct kevent &event, const std::shared_ptr<Conn
return;
}
if (ret == 0) {
DelWriteEvent(reinterpret_cast<uint64_t>(event.udata), conn->fd_);
# ifdef HAVE_32BIT
# ifdef HAVE_64BIT
auto connId = reinterpret_cast<uint64_t>(event.udata);
# else
auto _connId = reinterpret_cast<uint64_t *>(event.udata);
uint64_t connId = *_connId;
delete event.udata;
# endif
DelWriteEvent(connId, conn->fd_);
}
}

void KqueueEvent::DoError(const struct kevent &event, std::string &&err) {
onClose_(reinterpret_cast<uint64_t>(event.udata), std::move(err));
# ifdef HAVE_32BIT
# ifdef HAVE_64BIT
auto connId = reinterpret_cast<uint64_t>(event.udata);
# else
auto _connId = reinterpret_cast<uint64_t *>(event.udata);
uint64_t connId = *_connId;
delete event.udata;
# endif
onClose_(connId, std::move(err));
}

} // namespace net
Expand Down
2 changes: 1 addition & 1 deletion src/net/kqueue_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class KqueueEvent : public BaseEvent {
void DoError(const struct kevent &event, std::string &&err);

private:
const int eventsSize = 1020;
const int eventsSize = 1024;
};

} // namespace net
Expand Down

0 comments on commit a973821

Please sign in to comment.