Hello folks, I want to poll some sockets other machines deliver data to. I have to wait a maximum amount of time until ALL sockets should have received an arbitrary amount of data, to put the incoming data into time slots. So I have to do subsequent poll()s or select()s, each with a timeout of the remaining time from the previous one. With Linux, I can use select() for this: it returns the time remaining. But the manpage stated this is not portable.
I have tried to get the remaining time with setitimer/getitimer, but that doesn't seem to work with Cygwin. Anyway, with Linux, it works well. The code snippet is like below: #include <sys/poll.h> #include <sys/time.h> int subsequent_poll(struct pollfd connections[], unsigned int connection_count, int timeout); { struct itimerval timer; unsigned int i; for(i=0;i<connection_count;i++) { connections[i]->revent=0; connections[i]->event=POLLIN; } timer.it_interval.tv_sec=0; timer.it_interval.tv_usec=0; timer.it_value.tv_sec=timeout / 1000; timer.it_value.tv_usec=(timeout-timer.it_value.tv_sec*1000)*1000; setitimer(ITIMER_REAL,&timer,NULL); poll(connections,connection_count,timeout); getitimer(ITIMER_REAL,&timer); return (timer.it_value.tv_sec * 1000 + timer.it_value.tv_usec / 1000); } The problem is, getimer returns only values which are a multiple of 1000(and, oddly, sometimes a value of -296), so the granularity is only one second. This happens for a value of timeout below or above 1000, all the same. Is there any way to get around this problem, or does select() in Cygwin works like in Linux? That will be portable enough for now. Thanks, Jan Kandziora -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/