From cab982d79020fd235a3c8e362a59508c18506b24 Mon Sep 17 00:00:00 2001 From: corinna Date: Tue, 4 Jul 2000 16:58:48 +0000 Subject: [PATCH] * poll.cc: New file. Implement `poll' system call. * include/poll.h: Ditto. * include/sys/poll.h: Ditto. * Makefile.in: Add poll.o as dependency. * cygwin.din: Add poll and _poll symbols. --- winsup/cygwin/ChangeLog | 8 +++++ winsup/cygwin/Makefile.in | 3 +- winsup/cygwin/cygwin.din | 2 ++ winsup/cygwin/include/poll.h | 1 + winsup/cygwin/include/sys/poll.h | 43 +++++++++++++++++++++++++++ winsup/cygwin/poll.cc | 63 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 winsup/cygwin/include/poll.h create mode 100644 winsup/cygwin/include/sys/poll.h create mode 100644 winsup/cygwin/poll.cc diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index d8429999e8..1aecb10894 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,11 @@ +Mon Jul 4 18:57:00 2000 Corinna Vinschen + + * poll.cc: New file. Implement `poll' system call. + * include/poll.h: Ditto. + * include/sys/poll.h: Ditto. + * Makefile.in: Add poll.o as dependency. + * cygwin.din: Add poll and _poll symbols. + 2000-07-04 Kazuhiro Fujieda * dcrt0.cc (dll_crt0_1): Eliminate SetFileApisToOEM and CharToOem. diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in index 263d0ad288..683dff1f41 100644 --- a/winsup/cygwin/Makefile.in +++ b/winsup/cygwin/Makefile.in @@ -124,7 +124,7 @@ DLL_OFILES:=assert.o dcrt0.o debug.o delqueue.o dir.o dlfcn.o dll_init.o \ fhandler_serial.o fhandler_tape.o fhandler_termios.o fhandler_tty.o \ fhandler_windows.o fhandler_zero.o fork.o glob.o grp.o heap.o hinfo.o \ init.o ioctl.o localtime.o malloc.o mmap.o net.o ntea.o passwd.o \ - path.o pinfo.o pipe.o regexp.o regerror.o regsub.o registry.o \ + path.o pinfo.o pipe.o poll.o regexp.o regerror.o regsub.o registry.o \ resource.o scandir.o security.o select.o shared.o signal.o sigproc.o \ smallprint.o spawn.o strace.o strsep.o sync.o syscalls.o sysconf.o \ syslog.o termios.o times.o tty.o uinfo.o uname.o wait.o window.o \ @@ -330,6 +330,7 @@ passwd.o: $(WINSUP_H) path.o: $(WINSUP_H) pinfo.o: $(WINSUP_H) pipe.o: $(WINSUP_H) +poll.o: $(WINSUP_H) profile.o: profil.h pthread.o: $(WINSUP_H) registry.o: $(WINSUP_H) diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index ed2fdcd916..22c113724b 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -527,6 +527,8 @@ perror _perror = perror pipe _pipe +poll +_poll = poll pow _pow = pow powf diff --git a/winsup/cygwin/include/poll.h b/winsup/cygwin/include/poll.h new file mode 100644 index 0000000000..06fb41ab89 --- /dev/null +++ b/winsup/cygwin/include/poll.h @@ -0,0 +1 @@ +#include diff --git a/winsup/cygwin/include/sys/poll.h b/winsup/cygwin/include/sys/poll.h new file mode 100644 index 0000000000..c33639ebb4 --- /dev/null +++ b/winsup/cygwin/include/sys/poll.h @@ -0,0 +1,43 @@ +/* sys/poll.h + + Copyright 2000 Cygnus Solutions. + + This file is part of Cygwin. + + This software is a copyrighted work licensed under the terms of the + Cygwin license. Please consult the file "CYGWIN_LICENSE" for + details. */ + +#ifndef _SYS_POLL_H +#define _SYS_POLL_H + +#include + +__BEGIN_DECLS + +#define POLLIN 1 /* Set if data to read. */ +#define POLLPRI 2 /* Set if urgent data to read. */ +#define POLLOUT 4 /* Set if writing data wouldn't block. */ +#define POLLERR 8 /* An error occured, not used by Cygwin. */ +#define POLLHUP 16 /* Shutdown or close happened. */ +#define POLLNVAL 32 /* Invalid file descriptor. */ + +#define NPOLLFILE 64 /* Number of canonical fd's in one call to poll(). */ + +/* The following values are defined by XPG4. */ +#define POLLRDNORM POLLIN +#define POLLRDBAND POLLPRI +#define POLLWRNORM POLLOUT +#define POLLWRBAND POLLOUT + +struct pollfd { + int fd; + short events; + short revents; +}; + +extern int poll __P ((struct pollfd *fds, unsigned int nfds, int timeout)); + +__END_DECLS + +#endif /* _SYS_POLL_H */ diff --git a/winsup/cygwin/poll.cc b/winsup/cygwin/poll.cc new file mode 100644 index 0000000000..e806b5ed0c --- /dev/null +++ b/winsup/cygwin/poll.cc @@ -0,0 +1,63 @@ +/* poll.cc. Implements poll(2) via usage of select(2) call. + + Copyright 2000 Cygnus Solutions. + + This file is part of Cygwin. + + This software is a copyrighted work licensed under the terms of the + Cygwin license. Please consult the file "CYGWIN_LICENSE" for + details. */ + +#include +#include "winsup.h" + +extern "C" +int +poll (struct pollfd *fds, unsigned int nfds, int timeout) +{ + int max_fd = 0; + fd_set open_fds, read_fds, write_fds, except_fds; + struct timeval tv = { timeout / 1000, (timeout % 1000) * 1000 }; + + FD_ZERO (&read_fds); + FD_ZERO (&write_fds); + FD_ZERO (&except_fds); + + for (unsigned int i = 0; i < nfds; ++i) + if (!dtable.not_open (fds[i].fd)) + { + FD_SET (fds[i].fd, &open_fds); + if (fds[i].events & POLLIN) + FD_SET (fds[i].fd, &read_fds); + if (fds[i].events & POLLOUT) + FD_SET (fds[i].fd, &write_fds); + if (fds[i].events & POLLPRI) + FD_SET (fds[i].fd, &except_fds); + if (fds[i].fd > max_fd) + max_fd = fds[i].fd; + } + + int ret = cygwin_select (max_fd + 1, &read_fds, &write_fds, &except_fds, + timeout < 0 ? NULL : &tv); + + if (ret >= 0) + for (unsigned int i = 0; i < nfds; ++i) + { + if (!FD_ISSET (fds[i].fd, &open_fds)) + fds[i].revents = POLLNVAL; + else if (dtable.not_open(fds[i].fd)) + fds[i].revents = POLLHUP; + else + { + fds[i].revents = 0; + if (!FD_ISSET (fds[i].fd, &read_fds)) + fds[i].revents |= POLLIN; + if (!FD_ISSET (fds[i].fd, &write_fds)) + fds[i].revents |= POLLOUT; + if (!FD_ISSET (fds[i].fd, &except_fds)) + fds[i].revents |= POLLPRI; + } + } + + return ret; +} -- 2.11.0