Added support for FD's under WIN32.
git-svn-id: file:///fltk/svn/fltk/trunk@186 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
41d027ebfb
commit
85e6f44959
@ -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 <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <winsock.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// 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<nfds; i++) {
|
||||
if (fds[i].fd == n);
|
||||
else {if (j<i) {fd[j]=fd[i]; fds[j]=fds[i];} j++;}
|
||||
}
|
||||
nfds = j;
|
||||
#if !HAVE_POLL
|
||||
FD_CLR(n, &fdsets[0]);
|
||||
FD_CLR(n, &fdsets[1]);
|
||||
FD_CLR(n, &fdsets[2]);
|
||||
if (n == maxfd) maxfd--;
|
||||
#endif
|
||||
}
|
||||
|
||||
MSG fl_msg;
|
||||
|
||||
int fl_ready() {
|
||||
return PeekMessage(&fl_msg, NULL, 0, 0, PM_NOREMOVE);
|
||||
if (PeekMessage(&fl_msg, NULL, 0, 0, PM_NOREMOVE)) return 1;
|
||||
|
||||
timeval t;
|
||||
t.tv_sec = 0;
|
||||
t.tv_usec = 0;
|
||||
fd_set fdt[3];
|
||||
fdt[0] = fdsets[0];
|
||||
fdt[1] = fdsets[1];
|
||||
fdt[2] = fdsets[2];
|
||||
return ::select(maxfd+1,&fdt[0],&fdt[1],&fdt[2],&t);
|
||||
}
|
||||
|
||||
double fl_wait(int timeout_flag, double time) {
|
||||
int have_message;
|
||||
timeval t;
|
||||
fd_set fdt[3];
|
||||
int n;
|
||||
|
||||
|
||||
// For WIN32 we need to poll for socket input FIRST, since
|
||||
// the event queue is not something we can select() on...
|
||||
|
||||
t.tv_sec = 0;
|
||||
t.tv_usec = 0;
|
||||
|
||||
fdt[0] = fdsets[0];
|
||||
fdt[1] = fdsets[1];
|
||||
fdt[2] = fdsets[2];
|
||||
|
||||
if (::select(maxfd+1,&fdt[0],&fdt[1],&fdt[2],&t)) {
|
||||
// We got something - do the callback!
|
||||
for (int i = 0; i < nfds; i ++) {
|
||||
int f = fds[i].fd;
|
||||
short revents = 0;
|
||||
if (FD_ISSET(f,&fdt[0])) revents |= POLLIN;
|
||||
if (FD_ISSET(f,&fdt[1])) revents |= POLLOUT;
|
||||
if (FD_ISSET(f,&fdt[2])) revents |= POLLERR;
|
||||
if (fds[i].events & revents) fd[i].cb(f, fd[i].arg);
|
||||
}
|
||||
}
|
||||
|
||||
// get the first message by waiting the correct amount of time:
|
||||
if (!timeout_flag) {
|
||||
GetMessage(&fl_msg, NULL, 0, 0);
|
||||
@ -77,11 +153,13 @@ double fl_wait(int timeout_flag, double time) {
|
||||
have_message = PeekMessage(&fl_msg, NULL, 0, 0, PM_REMOVE);
|
||||
}
|
||||
}
|
||||
|
||||
// execute it, them execute any other messages that become ready during it:
|
||||
while (have_message) {
|
||||
DispatchMessage(&fl_msg);
|
||||
have_message = PeekMessage(&fl_msg, NULL, 0, 0, PM_REMOVE);
|
||||
}
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
@ -797,5 +875,5 @@ void Fl_Window::make_current() {
|
||||
}
|
||||
|
||||
//
|
||||
// End of "$Id: Fl_win32.cxx,v 1.20 1999/01/04 19:25:02 mike Exp $".
|
||||
// End of "$Id: Fl_win32.cxx,v 1.21 1999/01/06 21:20:01 mike Exp $".
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user