当前位置: 技术问答>linux和unix
请问epoll_wait返回的poll_events中的变量为什么为0
来源: 互联网 发布时间:2017-02-09
本文导语: 使用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);还是可以收到包的 ...
使用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);还是可以收到包的
但是在epoll_wait之后, poll_events[i].data.fd;的值为0,
此时使用recvfrom(g_hWatchSocket, (s8 *)pBuf, dwBufLen, 0 , NULL, NULL);还是可以收到包的
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