diff --git a/Makefile b/Makefile index 7db3749..b6355eb 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,8 @@ endif COLIB_OBJS=co_epoll.o co_routine.o co_hook_sys_call.o coctx_swap.o coctx.o #co_swapcontext.o -PROGS = colib example_poll example_echosvr example_echocli example_thread example_cond example_specific example_copystack example_closure +PROGS = colib example_poll example_echosvr example_echocli example_thread example_cond \ + example_specific example_copystack example_closure example_setenv all:$(PROGS) diff --git a/example_poll.cpp b/example_poll.cpp index eb92f21..0043895 100644 --- a/example_poll.cpp +++ b/example_poll.cpp @@ -135,9 +135,14 @@ static void *poll_routine( void *arg ) int ret = poll( pf,iWaitCnt,1000 ); printf("co %p poll wait %ld ret %d\n", co_self(),iWaitCnt,ret); + int nready = ret; for(int i=0;i<(int)iWaitCnt;i++) { - printf("co %p fire fd %d revents 0x%X POLLOUT 0x%X POLLERR 0x%X POLLHUP 0x%X\n", + if ( nready <= 0 ) + break; + if (pf[i].revents & (POLLOUT | POLLERR | POLLHUP)) + { + printf("co %p fire fd %d revents 0x%X POLLOUT 0x%X POLLERR 0x%X POLLHUP 0x%X\n", co_self(), pf[i].fd, pf[i].revents, @@ -145,13 +150,15 @@ static void *poll_routine( void *arg ) POLLERR, POLLHUP ); - setRaiseFds.insert( pf[i].fd ); + setRaiseFds.insert( pf[i].fd ); + nready--; + } } if( setRaiseFds.size() == v.size()) { break; } - if( ret <= 0 ) + if( ret < 0 ) { break; }