Exemplo n.º 1
0
int SocketUtil::getRecvBuffer(ZL_SOCKET fd)
{
    socklen_t buff_szie = sizeof(socklen_t);
    int optname = 0;
    int ret = ZL_GETSOCKOPT(fd, SOL_SOCKET, SO_RCVBUF, &optname, &buff_szie);
    ZL_UNUSED(ret);
    assert(ret != -1);
    return optname > 0 ? optname : 0;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
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);
}