bool EpollPoller::removeChannel(Channel *channel) { if(!hasChannel(channel)) // 注意 updateChannel 函数中也有一处removeChannel的逻辑 return true; ZL_SOCKET fd = channel->fd(); LOG_INFO("EpollPoller::removeChannel [%d][%0x]", fd, channel); assert(hasChannel(channel) && "the remove socket must be already exist"); assert(getChannel(fd) == channel && "the remove socket must be already exist"); assert(channel->isNoneEvent()); size_t n = channelMap_.erase(fd); ZL_UNUSED(n); assert(n == 1); return update(channel, EPOLL_CTL_DEL); }
void Poller::removeChannel(Channel* chan) { int sockfd = chan->getfd(); ChannelMap::const_iterator it = channels_.find(sockfd); assert(hasChannel(chan)); channels_.erase(sockfd); update(sockfd, EPOLL_CTL_DEL, it->second->events(), chan); };
bool EpollPoller::updateChannel(Channel *channel) { ZL_SOCKET fd = channel->fd(); LOG_INFO("EpollPoller::updateChannel[%d]", fd); if(hasChannel(channel)) //exist, update { assert(getChannel(fd) == channel); if(channel->isNoneEvent()) { LOG_INFO("EpollPoller::updateChannel [%d][%0x] NoneEvent", fd, channel); channelMap_.erase(fd); return update(channel, EPOLL_CTL_DEL); } else { return update(channel, EPOLL_CTL_MOD); } } else //new, add { assert(getChannel(fd) == NULL); channelMap_[fd] = channel; return update(channel, EPOLL_CTL_ADD); } }
int FdEventsKqueuer::modFdEvent(FdEvent *fe) { assert(fe); int fd = fe->fd(); printf("FdEventsKqueuer::updateChannel[%d]\n", fd); if (hasChannel(fe)) //exist, update { assert(getChannel(fd) == fe); if (fe->isNoneEvent()) { printf("FdEventsKqueuer::updateChannel [%d][%p] NoneEvent\n", fd, fe); channelMap_.erase(fd); return update(fe, EV_DELETE); } else { return update(fe, EV_ADD | EV_ENABLE); } } else //new, add { assert(getChannel(fd) == NULL); channelMap_[fd] = fe; return update(fe, EV_ADD); } }
int FdEventsKqueuer::delFdEvent(FdEvent *fe) { assert(fe); if (!hasChannel(fe)) // 注意 updateChannel 函数中也有一处removeChannel的逻辑 return 0; int fd = fe->fd(); printf("FdEventsKqueuer::removeChannel [%d][%p]\n", fd, fe); assert(hasChannel(fe) && "the remove socket must be already exist"); assert(getChannel(fd) == fe && "the remove socket must be already exist"); assert(fe->isNoneEvent()); size_t n = channelMap_.erase(fd); //ZL_UNUSED(n); assert(n == 1); update(fe, EV_DELETE); FdEvent::deleteFdEvent(fe); return 0; }
std::vector<AudioDeviceID> CoreAudioUtilities::audioDeviceList(bool isInput) { OSStatus status = noErr; UInt32 numberOfDevices = 0; UInt32 deviceListSize = 0; AudioDeviceID * deviceList = NULL; std::vector<AudioDeviceID> result; // Getting number of devices status = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &deviceListSize, NULL); if (status) { LOG_ERROR("Can't get property info: kAudioHardwarePropertyDevices"); return result; } numberOfDevices = deviceListSize / sizeof(AudioDeviceID); //// // Getting device list deviceList = (AudioDeviceID *) calloc(sizeof(AudioDeviceID), deviceListSize); status = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &deviceListSize, deviceList); if (status) { LOG_ERROR("Can't get property: kAudioHardwarePropertyDevices"); return result; } //// // Populating the result for (unsigned i = 0 ; i < numberOfDevices ; ++i) { if ((isInput && hasChannel(deviceList[i], true)) || (!isInput && hasChannel(deviceList[i], false))) { result.push_back(deviceList[i]); } } //// return result; }
void EpollPoller::fireActiveChannels(int numEvents, ChannelList& activeChannels) const { assert(static_cast<size_t>(numEvents) <= events_.size()); for (int i = 0; i < numEvents; ++i) { Channel *channel = static_cast<Channel*>(events_[i].data.ptr); assert(hasChannel(channel) && "the channel must be already exist"); //channel->set_revents(events_[i].events); int revents = FDEVENT_NONE; if (events_[i].events & EPOLLIN) revents |= FDEVENT_IN; if (events_[i].events & EPOLLPRI) revents |= FDEVENT_PRI; if (events_[i].events & EPOLLOUT) revents |= FDEVENT_OUT; if (events_[i].events & EPOLLERR) revents |= FDEVENT_ERR; if (events_[i].events & EPOLLHUP) revents |= FDEVENT_HUP; channel->set_revents(revents); activeChannels.push_back(channel); } }
void FdEventsKqueuer::fireActiveChannels(int numEvents, ChannelList& fdevents) const { assert(static_cast<size_t>(numEvents) <= events_.size()); for (int i = 0; i < numEvents; ++i) { //int fd = events_[i].ident; FdEvent *fde = static_cast<FdEvent*>(events_[i].udata); assert(hasChannel(fde) && "the channel must be already exist"); int revents = FDEVENT_NONE; if (events_[i].events & EVFILT_READ) revents |= FDEVENT_IN; if (events_[i].events & EVFILT_WRITE) revents |= FDEVENT_OUT; if (events_[i].flags & EV_EOF) revents |= FDEVENT_HUP; if (events_[i].flags & EV_ERROR) revents |= FDEVENT_ERR; fde->set_revents(revents); fdevents.push_back(fde); } }
bool PollPoller::removeChannel(Channel *channel) { if(!hasChannel(channel)) return true; ZL_SOCKET fd = channel->fd(); int idx = channelIter_[channel]; LOG_INFO("PollPoller::removeChannel [%d][%d][%0x]", fd, idx, channel); assert(getChannel(fd) == channel && "the remove socket must be already exist"); assert(channel->isNoneEvent()); assert(0 <= idx && idx < static_cast<int>(pollfds_.size())); const struct pollfd& pfd = pollfds_[idx]; ZL_UNUSED(pfd); assert(pfd.fd == -channel->fd()-1 && pfd.events == channel->events()); size_t n = channelMap_.erase(fd); ZL_UNUSED(n); assert(n == 1); if ((idx) == static_cast<int>(pollfds_.size()) - 1) // last one { } else { int lastfd = pollfds_.back().fd; iter_swap(pollfds_.begin()+idx, pollfds_.end()-1); if (lastfd < 0) { lastfd = -lastfd-1; } channelIter_[getChannel(lastfd)] = idx; } pollfds_.pop_back(); channelIter_.erase(channel); return true; }
void Poller::updateChannel(Channel* chan) { assert(hasChannel(chan)); int sockfd = chan->getfd(); update(sockfd, EPOLL_CTL_MOD, chan->events(), chan); };
void Poller::addChannel(Channel* chan) { assert(!hasChannel(chan)); int sockfd = chan->getfd(); channels_[sockfd] = chan; update(sockfd, EPOLL_CTL_ADD, chan->events(), chan); };
int FdEventsKqueuer::addFdEvent(FdEvent *fe) { assert(fe); assert(!hasChannel(fe)); return modFdEvent(fe); }