日期:2014-05-16  浏览次数:20911 次

请问epoll_wait返回的poll_events中的变量为什么为0
使用epoll_ctl(epollHandle, EPOLL_CTL_ADD, g_hWatchSocket, &ev)设置了g_hWatchSocket对应的ev,
但是在epoll_wait之后, poll_events[i].data.fd;的值为0,

此时使用recvfrom(g_hWatchSocket, (s8 *)pBuf, dwBufLen, 0 , NULL, NULL);还是可以收到包的

C/C++ code

    u32  dwBufLen = 2048;
    u8  *pBuf     = new u8[dwBufLen+1];  
        

    g_hWatchSocket = socket(AF_INET, SOCK_DGRAM, 0);
        
    SOCKADDR_IN addr;
    memset(&addr, 0, sizeof(SOCKADDR_IN));
    addr.sin_family      = AF_INET; 
    addr.sin_addr.s_addr = 0;
    addr.sin_port        = htons(2500);
        
    bind(g_hWatchSocket, (sockaddr *)&addr, sizeof(SOCKADDR_IN)))

    SetNonBlocking(g_hWatchSocket);

    struct epoll_event ev, poll_events[100];

    ev.data.fd  = g_hWatchSocket;
    ev.events   = EPOLLIN|EPOLLET;
    
    int epollHandle = epoll_create(100);
    int ret = epoll_ctl(epollHandle, EPOLL_CTL_ADD, g_hWatchSocket, &ev);
    
    
    while(1)
    {
        nEventNum = epoll_wait(epollHandle, poll_events, 100, 800);

        for(int i=0; i < nEventNum; i++)
        {
                       [color=#FF0000]为什么这里得到的sockfd是0呢????[/color]
             sockfd = poll_events[i].data.fd;

    

                //重新设置g_hWatchSocket的监控类型
                ev.data.fd  = g_hWatchSocket;
                ev.events   = EPOLLIN | EPOLLET;
                epoll_ctl(epollHandle, EPOLL_CTL_MOD, g_hWatchSocket, &ev);


            }
        }//for(int i=0;i<nEventNum;i++)
    }//while(1)



------解决方案--------------------
0 也是一个合法的文件描述符啊