日期:2014-05-16 浏览次数:20911 次
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)