From 85e6f449590eeb6e09f7547733adf4c7137470d0 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Wed, 6 Jan 1999 21:20:01 +0000 Subject: Added support for FD's under WIN32. git-svn-id: file:///fltk/svn/fltk/trunk@186 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_win32.cxx | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 87 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx index 2ac90f890..c2cff8897 100644 --- a/src/Fl_win32.cxx +++ b/src/Fl_win32.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_win32.cxx,v 1.20 1999/01/04 19:25:02 mike Exp $" +// "$Id: Fl_win32.cxx,v 1.21 1999/01/06 21:20:01 mike Exp $" // // WIN32-specific code for the Fast Light Tool Kit (FLTK). // @@ -34,35 +34,111 @@ #include #include #include +#include +#include +#include //////////////////////////////////////////////////////////////// // interface to poll/select call: -// fd's are not yet implemented. -// On NT these are probably only used for network stuff, so this may -// talk to a package that Wonko has proposed writing to make the network -// interface system independent. +// fd's are only implemented for sockets. Microsoft Windows does not +// have a unified IO system, so it doesn't support select() on files, +// devices, or pipes... #define POLLIN 1 #define POLLOUT 4 #define POLLERR 8 -void Fl::add_fd(int n, int events, void (*cb)(int, void*), void *v) {} +#define MAXFD 8 +#if !HAVE_POLL +static fd_set fdsets[3]; +static int maxfd; +#endif +static int nfds; +static struct pollfd fds[MAXFD]; +static struct { + void (*cb)(int, void*); + void* arg; +} fd[MAXFD]; + +void Fl::add_fd(int n, int events, void (*cb)(int, void*), void *v) { + int i; + if (nfds < MAXFD) {i = nfds; nfds++;} else {i = MAXFD-1;} + fds[i].fd = n; + fds[i].events = events; +#if !HAVE_POLL + if (events & POLLIN) FD_SET(n, &fdsets[0]); + if (events & POLLOUT) FD_SET(n, &fdsets[1]); + if (events & POLLERR) FD_SET(n, &fdsets[2]); + if (n > maxfd) maxfd = n; +#endif + fd[i].cb = cb; + fd[i].arg = v; +} void Fl::add_fd(int fd, void (*cb)(int, void*), void* v) { Fl::add_fd(fd,POLLIN,cb,v); } -void Fl::remove_fd(int n) {} +void Fl::remove_fd(int n) { + int i,j; + for (i=j=0; i