X-Spam-Check-By: sourceware.org Date: Sat, 7 Oct 2006 04:52:33 +0200 From: Peter Ekberg To: cygwin AT cygwin DOT com Subject: How to select on a win32 handle? Message-ID: <20061007025233.GA24180@sellafield.lysator.liu.se> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.12-2006-07-14 Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Hello! I'm finding that I have a need to select on a win32 handle. I found the function cygwin_attach_handle_to_fd which sounded promising, but I do not have any luck when I try to use it. I did look through the sources in winsup, but came to the perhaps misguided conclusion that there needs to be a new fhandler in order to support this. I would not mind to be proved wrong though. :-) I was hoping that the following program would print "tick" with one second intervals, but the fd is selectable all the time. If I uncomment the call to WaitForSingleObject, the output is as I hoped, so I believe the Win32 parts are correct in the sample. I have tried various arguments instead of NULL for cygwin_attach_handle_to_fd, in the hopes of finding a workable fhandler, but to no avail. Is there some other approach to select on Win32 handles? Or should I declare defeat and use get_osfhandle on the fds and WaitFor... the combined set of fds/objects that way instead? Cheers, Peter -------------8<------------ #include #include #include #include int main(void) { HANDLE timer; LARGE_INTEGER due; int fd; fd_set fds; int i; int res = 0; timer = CreateWaitableTimer(NULL, TRUE, NULL); due.QuadPart = -10000000; if (!SetWaitableTimer(timer, &due, 0, NULL, NULL, FALSE)) return -1; fd = cygwin_attach_handle_to_fd(NULL, -1, timer, 1, GENERIC_READ); if (fd < 0) { CloseHandle(timer); return -1; } FD_ZERO(&fds); FD_SET(fd, &fds); for (i = 0; i < 5; ++i) { res = select(fd + 1, &fds, NULL, NULL, NULL); if (res < 0) break; printf("tick\n"); /* WaitForSingleObject(timer, INFINITE); */ if (!SetWaitableTimer(timer, &due, 0, NULL, NULL, FALSE)) { res = -1; break; } } close(fd); return res < 0 ? res : 0; } -------------8<------------ -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/