| 110 | bool KqueueEventPoll::good() const { return kqfd_ != -1; } |
| 111 | |
| 112 | void KqueueEventPoll::poll(const struct timeval& tv) |
| 113 | { |
| 114 | struct timespec timeout = {tv.tv_sec, tv.tv_usec * 1000}; |
| 115 | int res; |
| 116 | while ((res = kevent(kqfd_, kqEvents_.get(), 0, kqEvents_.get(), |
| 117 | kqEventsSize_, &timeout)) == -1 && |
| 118 | errno == EINTR) |
| 119 | ; |
| 120 | if (res > 0) { |
| 121 | for (int i = 0; i < res; ++i) { |
| 122 | KSocketEntry* p = reinterpret_cast<KSocketEntry*>(kqEvents_[i].udata); |
| 123 | int events = 0; |
| 124 | int filter = kqEvents_[i].filter; |
| 125 | if (filter == EVFILT_READ) { |
| 126 | events = KqueueEventPoll::IEV_READ; |
| 127 | } |
| 128 | else if (filter == EVFILT_WRITE) { |
| 129 | events = KqueueEventPoll::IEV_WRITE; |
| 130 | } |
| 131 | p->processEvents(events); |
| 132 | } |
| 133 | } |
| 134 | else if (res == -1) { |
| 135 | int errNum = errno; |
| 136 | A2_LOG_INFO(fmt("kevent error: %s", util::safeStrerror(errNum).c_str())); |
| 137 | } |
| 138 | #ifdef ENABLE_ASYNC_DNS |
| 139 | // It turns out that we have to call ares_process_fd before ares's |
| 140 | // own timeout and ares may create new sockets or closes socket in |
| 141 | // their API. So we call ares_process_fd for all ares_channel and |
| 142 | // re-register their sockets. |
| 143 | for (auto& r : nameResolverEntries_) { |
| 144 | auto& ent = r.second; |
| 145 | ent.processTimeout(); |
| 146 | ent.removeSocketEvents(this); |
| 147 | ent.addSocketEvents(this); |
| 148 | } |
| 149 | #endif // ENABLE_ASYNC_DNS |
| 150 | |
| 151 | // TODO timeout of name resolver is determined in Command(AbstractCommand, |
| 152 | // DHTEntryPoint...Command) |
| 153 | } |
| 154 | |
| 155 | namespace { |
| 156 | int translateEvents(EventPoll::EventType events) |
nothing calls this directly
no test coverage detected