fix:descriptor remove failed on MacOS

This commit is contained in:
Livox-SDK
2021-04-20 12:18:48 +08:00
parent 94a0c7674a
commit b08ee601c7
@@ -83,22 +83,27 @@ bool MultipleIOKqueue::PollSetAdd(PollFd poll_fd) {
bool MultipleIOKqueue::PollSetRemove(PollFd poll_fd) {
int fd = poll_fd.fd;
bool result = true;
if (descriptors_.find(fd) != descriptors_.end()) {
if (descriptors_[fd].event & READBLE_EVENT) {
EV_SET(&kevent_, fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
if (kevent(kqueue_fd_, &kevent_, 1, nullptr, 0, nullptr) == -1) {
return false;
do {
if (descriptors_[fd].event & READBLE_EVENT) {
EV_SET(&kevent_, fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
if (kevent(kqueue_fd_, &kevent_, 1, nullptr, 0, nullptr) == -1) {
result = false;
break;
}
}
}
if (descriptors_[fd].event & WRITABLE_EVENT) {
EV_SET(&kevent_, fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
if (kevent(kqueue_fd_, &kevent_, 1, nullptr, 0, nullptr) == -1) {
return false;
if (descriptors_[fd].event & WRITABLE_EVENT) {
EV_SET(&kevent_, fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
if (kevent(kqueue_fd_, &kevent_, 1, nullptr, 0, nullptr) == -1) {
result = false;
break;
}
}
}
} while(0);
descriptors_.erase(fd);
}
return true;
return result;
}
void MultipleIOKqueue::Poll(int time_out) {