// File: guoxuanhan[P]NetServer/poller.cpp
// Function: Poller::poll(std::vector<Channel*, std::allocator<Channel*>>&)
void Poller::poll(ChannelList& activechannellist)
{
    int timeout = TIMEOUT;
    int nfds = epoll_wait(pollfd_, &*eventlist_.begin(), (int)eventlist_.capacity(), timeout);
    if(nfds == -1)
    {
        perror("epoll wait error!");
    }
    //std::cout<< "event num: " << nfds << std::endl;
    for(int i = 0; i < nfds; i++)
    {
        int events = eventlist_[i].events;
        Channel* pchannel = (Channel*)eventlist_[i].data.ptr;
        int fd = pchannel->GetFd();

        std::map<int, Channel*>::const_iterator iter;
        {
            std::lock_guard<std::mutex> lock(mutex_);
            iter = channelmap_.find(fd);
        }
        if(iter != channelmap_.end())
        {
            pchannel->SetEvents(events);
            activechannellist.push_back(pchannel);
        } else
        {
            std::cout<< "not find channel!" << std::endl;
        }
    }
    if(nfds == (int)eventlist_.capacity())
    {
        std::cout<< "resize:" << nfds << std::endl;
        eventlist_.resize(nfds * 2);
    }
}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movq 0xa0(%rsp), %rdi
movq %rdi, 0x18(%rsp)
movl $0x3e8, 0x94(%rsp) # imm = 0x3E8
movl (%rdi), %eax
movl %eax, 0x24(%rsp)
addq $0x8, %rdi
callq 0x18a90
movq %rax, 0x88(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x18ac0
movq 0x18(%rsp), %rdi
movq %rax, 0x28(%rsp)
addq $0x8, %rdi
callq 0x18ad0
movl 0x24(%rsp), %edi
movq 0x28(%rsp), %rsi
movl %eax, %edx
movl 0x94(%rsp), %ecx
callq 0x51e0
movl %eax, 0x90(%rsp)
cmpl $-0x1, 0x90(%rsp)
jne 0x1843a
leaq 0x10ad9(%rip), %rdi     # 0x28f0e
callq 0x5320
movl $0x0, 0x84(%rsp)
movl 0x84(%rsp), %eax
cmpl 0x90(%rsp), %eax
jge 0x185bd
movq 0x18(%rsp), %rdi
addq $0x8, %rdi
movq %rdi, 0x8(%rsp)
movslq 0x84(%rsp), %rsi
callq 0x18af0
movq 0x8(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x80(%rsp)
movslq 0x84(%rsp), %rsi
callq 0x18af0
movq 0x4(%rax), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rdi
callq 0x5c90
movl %eax, 0x74(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x18b10
movq 0x18(%rsp), %rsi
addq $0x50, %rsi
leaq 0x60(%rsp), %rdi
callq 0x8c20
movq 0x18(%rsp), %rdi
addq $0x20, %rdi
leaq 0x74(%rsp), %rsi
callq 0x18b30
movq %rax, 0x10(%rsp)
jmp 0x184dd
movq 0x10(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x18b60
movq 0x58(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x8cc0
movq 0x18(%rsp), %rdi
addq $0x20, %rdi
callq 0x18ba0
movq %rax, 0x30(%rsp)
leaq 0x38(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x18b60
leaq 0x68(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x18b80
testb $0x1, %al
jne 0x18541
jmp 0x18583
movq 0x78(%rsp), %rdi
movl 0x80(%rsp), %esi
callq 0x5ca0
movq 0x98(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x18bd0
jmp 0x185a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x8cc0
jmp 0x18634
movq 0x22a26(%rip), %rdi     # 0x3afb0
leaq 0x1098f(%rip), %rsi     # 0x28f20
callq 0x53a0
movq %rax, %rdi
movq 0x229e0(%rip), %rsi     # 0x3af80
callq 0x53f0
jmp 0x185a7
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x18445
movq 0x18(%rsp), %rdi
movl 0x90(%rsp), %eax
movl %eax, 0x4(%rsp)
addq $0x8, %rdi
callq 0x18ad0
movq %rax, %rcx
movl 0x4(%rsp), %eax
cmpl %ecx, %eax
jne 0x1862c
movq 0x229c8(%rip), %rdi     # 0x3afb0
leaq 0x10943(%rip), %rsi     # 0x28f32
callq 0x53a0
movq %rax, %rdi
movl 0x90(%rsp), %esi
callq 0x5650
movq %rax, %rdi
movq 0x22973(%rip), %rsi     # 0x3af80
callq 0x53f0
movq 0x18(%rsp), %rdi
addq $0x8, %rdi
movl 0x90(%rsp), %eax
shll %eax
movslq %eax, %rsi
callq 0x18c40
addq $0xa8, %rsp
retq
movq 0x48(%rsp), %rdi
callq 0x5660
nop