summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin')
-rw-r--r--winsup/cygwin/ChangeLog8
-rw-r--r--winsup/cygwin/Makefile.in3
-rw-r--r--winsup/cygwin/cygwin.din2
-rw-r--r--winsup/cygwin/include/poll.h1
-rw-r--r--winsup/cygwin/include/sys/poll.h43
-rw-r--r--winsup/cygwin/poll.cc63
6 files changed, 119 insertions, 1 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index d8429999e..1aecb1089 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,11 @@
+Mon Jul 4 18:57:00 2000 Corinna Vinschen <corinna@vinschen.de>
+
+ * 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 <fujieda@jaist.ac.jp>
* dcrt0.cc (dll_crt0_1): Eliminate SetFileApisToOEM and CharToOem.
diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in
index 263d0ad28..683dff1f4 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 ed2fdcd91..22c113724 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 000000000..06fb41ab8
--- /dev/null
+++ b/winsup/cygwin/include/poll.h
@@ -0,0 +1 @@
+#include <sys/poll.h>
diff --git a/winsup/cygwin/include/sys/poll.h b/winsup/cygwin/include/sys/poll.h
new file mode 100644
index 000000000..c33639ebb
--- /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 <sys/cdefs.h>
+
+__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 000000000..e806b5ed0
--- /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 <sys/poll.h>
+#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;
+}