* 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.
This commit is contained in:
parent
f88cc35383
commit
afb7e7196a
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -527,6 +527,8 @@ perror
|
|||
_perror = perror
|
||||
pipe
|
||||
_pipe
|
||||
poll
|
||||
_poll = poll
|
||||
pow
|
||||
_pow = pow
|
||||
powf
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
#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 */
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue