Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcvs2svn <>2012-08-10 13:37:38 +0400
committercvs2svn <>2012-08-10 13:37:38 +0400
commit01beb2de8fd634476dd66190ebefae61830630e3 (patch)
tree2dc53d2fa6590c392dc8d62d96f32a4bdd326c46 /winsup/cygwin/select.cc
parentc0956742a74d194b9c18c7a91aa6d6010beb4cd3 (diff)
This commit was manufactured by cvs2svn to create tag 'cygwin-cygwin-1_7_14_2-release
1_7_14_2-release'. Sprout from cygwin-64bit-branch 2012-08-10 09:37:33 UTC cvs2svn 'This commit was manufactured by cvs2svn to create branch 'cygwin-64bit-' Cherrypick from master 2012-04-25 07:34:34 UTC Corinna Vinschen <corinna@vinschen.de> ' * new-features.sgml (ov-new1.7.14): Add mouse reporting mode 1005.': COPYING3 COPYING3.LIB ChangeLog MAINTAINERS compile config.rpath config.sub config/ChangeLog config/mh-darwin config/mh-interix config/mh-ppc-aix config/mt-alphaieee config/mt-sde config/picflag.m4 config/stdint.m4 config/tcl.m4 configure configure.ac include/ChangeLog include/dis-asm.h include/dwarf2.h include/elf/ChangeLog include/elf/avr.h include/elf/common.h include/elf/m68hc11.h include/elf/ppc.h include/elf/s390.h include/elf/sparc.h include/filenames.h include/gdb/ChangeLog include/gdb/callback.h include/gdb/signals.def include/gdb/signals.h include/mach-o/ChangeLog include/mach-o/codesign.h include/mach-o/external.h include/mach-o/loader.h include/mach-o/reloc.h include/mach-o/x86-64.h include/opcode/ChangeLog include/opcode/avr.h include/opcode/m68hc11.h include/opcode/mips.h include/opcode/ppc.h include/opcode/sparc.h include/plugin-api.h ltgcc.m4 ltoptions.m4 ltversion.m4 lt~obsolete.m4 newlib/ChangeLog newlib/doc/Makefile.am newlib/doc/Makefile.in newlib/libc/include/stdio.h newlib/libc/include/string.h newlib/libc/include/sys/signal.h newlib/libc/include/sys/stat.h newlib/libc/include/sys/time.h newlib/libc/include/sys/times.h newlib/libc/include/sys/types.h newlib/libc/include/sys/unistd.h newlib/libc/include/sys/wait.h newlib/libc/locale/lmessages.c newlib/libc/locale/lmonetary.c newlib/libc/locale/nl_langinfo.c newlib/libc/machine/cr16/sys/asm.h newlib/libc/machine/epiphany/Makefile.am newlib/libc/machine/epiphany/Makefile.in newlib/libc/machine/epiphany/aclocal.m4 newlib/libc/machine/epiphany/configure newlib/libc/machine/epiphany/configure.in newlib/libc/machine/epiphany/machine/stdlib.h newlib/libc/machine/epiphany/setjmp.S newlib/libc/machine/rl78/Makefile.am newlib/libc/machine/rl78/Makefile.in newlib/libc/machine/rl78/aclocal.m4 newlib/libc/machine/rl78/configure newlib/libc/machine/rl78/configure.in newlib/libc/machine/rl78/setjmp.S newlib/libc/posix/collate.c newlib/libc/posix/engine.c newlib/libc/posix/glob.c newlib/libc/posix/popen.c newlib/libc/posix/readdir.c newlib/libc/posix/regcomp.c newlib/libc/posix/telldir.c newlib/libc/posix/wordexp.c newlib/libc/reent/mkdirr.c newlib/libc/reent/renamer.c newlib/libc/search/hash.c newlib/libc/search/hash_bigkey.c newlib/libc/search/hash_page.c newlib/libc/search/hcreate_r.c newlib/libc/stdio/asiprintf.c newlib/libc/stdio/asprintf.c newlib/libc/stdio/clearerr.c newlib/libc/stdio/fclose.c newlib/libc/stdio/fdopen.c newlib/libc/stdio/feof.c newlib/libc/stdio/ferror.c newlib/libc/stdio/fflush.c newlib/libc/stdio/fgetc.c newlib/libc/stdio/fgets.c newlib/libc/stdio/fgetwc.c newlib/libc/stdio/fgetws.c newlib/libc/stdio/fileno.c newlib/libc/stdio/findfp.c newlib/libc/stdio/fmemopen.c newlib/libc/stdio/fopen.c newlib/libc/stdio/fopencookie.c newlib/libc/stdio/fpurge.c newlib/libc/stdio/fputc.c newlib/libc/stdio/fputs.c newlib/libc/stdio/fputwc.c newlib/libc/stdio/fputws.c newlib/libc/stdio/fread.c newlib/libc/stdio/freopen.c newlib/libc/stdio/fseek.c newlib/libc/stdio/ftell.c newlib/libc/stdio/funopen.c newlib/libc/stdio/fwide.c newlib/libc/stdio/fwrite.c newlib/libc/stdio/getc.c newlib/libc/stdio/getdelim.c newlib/libc/stdio/gets.c newlib/libc/stdio/local.h newlib/libc/stdio/mktemp.c newlib/libc/stdio/open_memstream.c newlib/libc/stdio/putc.c newlib/libc/stdio/setvbuf.c newlib/libc/stdio/ungetc.c newlib/libc/stdio/ungetwc.c newlib/libc/stdio/vasiprintf.c newlib/libc/stdio/vasprintf.c newlib/libc/stdio/vfprintf.c newlib/libc/stdio/vfscanf.c newlib/libc/stdio/vfwprintf.c newlib/libc/stdio/vfwscanf.c newlib/libc/stdio64/fdopen64.c newlib/libc/stdio64/fopen64.c newlib/libc/stdio64/freopen64.c newlib/libc/stdio64/fseeko64.c newlib/libc/stdio64/ftello64.c newlib/libc/stdlib/mbtowc_r.c newlib/libc/stdlib/mprec.h newlib/libc/stdlib/wctomb_r.c newlib/libc/string/Makefile.am newlib/libc/string/Makefile.in newlib/libc/string/strcasestr.c newlib/libc/sys/epiphany/Makefile.am newlib/libc/sys/epiphany/Makefile.in newlib/libc/sys/epiphany/aclocal.m4 newlib/libc/sys/epiphany/configure newlib/libc/sys/epiphany/configure.in newlib/libc/sys/epiphany/e_printf.c newlib/libc/sys/rtems/crt0.c newlib/libc/sys/rtems/machine/_types.h newlib/libc/sys/sysnecv850/crt0.S newlib/libc/time/strptime.c newlib/libm/common/sf_round.c newlib/libm/math/e_atan2.c newlib/libm/math/e_exp.c newlib/libm/math/e_pow.c newlib/libm/math/e_rem_pio2.c newlib/libm/math/ef_exp.c newlib/libm/math/ef_pow.c newlib/libm/math/er_lgamma.c newlib/libm/math/erf_lgamma.c newlib/testsuite/newlib.stdio/stdio.exp newlib/testsuite/newlib.stdio/swprintf.c newlib/testsuite/newlib.string/strcmp-1.c winsup/ChangeLog winsup/Makefile.common winsup/cygserver/ChangeLog winsup/cygserver/woutsup.h winsup/cygwin/ChangeLog winsup/cygwin/Makefile.in winsup/cygwin/advapi32.cc winsup/cygwin/child_info.h winsup/cygwin/configure.in winsup/cygwin/cygheap.cc winsup/cygwin/cygheap.h winsup/cygwin/cygserver_ipc.h winsup/cygwin/cygthread.cc winsup/cygwin/cygtls.cc winsup/cygwin/cygtls.h winsup/cygwin/cygwin.din winsup/cygwin/cygwin.sc winsup/cygwin/dcrt0.cc winsup/cygwin/devices.cc winsup/cygwin/devices.in winsup/cygwin/dll_init.cc winsup/cygwin/dtable.cc winsup/cygwin/dtable.h winsup/cygwin/environ.cc winsup/cygwin/exceptions.cc winsup/cygwin/external.cc winsup/cygwin/fenv.cc winsup/cygwin/fhandler.cc winsup/cygwin/fhandler.h winsup/cygwin/fhandler_clipboard.cc winsup/cygwin/fhandler_console.cc winsup/cygwin/fhandler_disk_file.cc winsup/cygwin/fhandler_dsp.cc winsup/cygwin/fhandler_fifo.cc winsup/cygwin/fhandler_mem.cc winsup/cygwin/fhandler_procnet.cc winsup/cygwin/fhandler_registry.cc winsup/cygwin/fhandler_serial.cc winsup/cygwin/fhandler_socket.cc winsup/cygwin/fhandler_tape.cc winsup/cygwin/fhandler_termios.cc winsup/cygwin/fhandler_tty.cc winsup/cygwin/fhandler_virtual.cc winsup/cygwin/fhandler_windows.cc winsup/cygwin/flock.cc winsup/cygwin/fork.cc winsup/cygwin/gendef winsup/cygwin/gentls_offsets winsup/cygwin/globals.cc winsup/cygwin/heap.cc winsup/cygwin/hookapi.cc winsup/cygwin/include/cygwin/if.h winsup/cygwin/include/cygwin/in.h winsup/cygwin/include/cygwin/socket.h winsup/cygwin/include/elf.h winsup/cygwin/include/inttypes.h winsup/cygwin/include/mntent.h winsup/cygwin/include/netdb.h winsup/cygwin/include/stdint.h winsup/cygwin/include/sys/elf32.h winsup/cygwin/include/sys/elf64.h winsup/cygwin/include/sys/elf_common.h winsup/cygwin/include/sys/elf_generic.h winsup/cygwin/include/sys/wait.h winsup/cygwin/kernel32.cc winsup/cygwin/lib/_cygwin_crt0_common.cc winsup/cygwin/lib/crt0.h winsup/cygwin/libc/inet_addr.c winsup/cygwin/libc/inet_network.c winsup/cygwin/libc/minires-os-if.c winsup/cygwin/libc/minires.h winsup/cygwin/libc/rcmd.cc winsup/cygwin/miscfuncs.cc winsup/cygwin/miscfuncs.h winsup/cygwin/mkvers.sh winsup/cygwin/mount.cc winsup/cygwin/mount.h winsup/cygwin/net.cc winsup/cygwin/ntdll.h winsup/cygwin/passwd.cc winsup/cygwin/path.cc winsup/cygwin/path.h winsup/cygwin/pinfo.cc winsup/cygwin/pipe.cc winsup/cygwin/poll.cc winsup/cygwin/posix.sgml winsup/cygwin/posix_ipc.cc winsup/cygwin/pseudo-reloc.cc winsup/cygwin/regex/regcomp.c winsup/cygwin/registry.cc winsup/cygwin/release/1.7.10 winsup/cygwin/release/1.7.11 winsup/cygwin/release/1.7.12 winsup/cygwin/release/1.7.13 winsup/cygwin/sched.cc winsup/cygwin/sec_helper.cc winsup/cygwin/security.cc winsup/cygwin/security.h winsup/cygwin/select.cc winsup/cygwin/select.h winsup/cygwin/shared.cc winsup/cygwin/signal.cc winsup/cygwin/sigproc.cc winsup/cygwin/sigproc.h winsup/cygwin/smallprint.cc winsup/cygwin/spawn.cc winsup/cygwin/strace.cc winsup/cygwin/strfuncs.cc winsup/cygwin/syscalls.cc winsup/cygwin/syslog.cc winsup/cygwin/thread.cc winsup/cygwin/thread.h winsup/cygwin/tlsoffsets.h winsup/cygwin/wait.cc winsup/cygwin/winbase.h winsup/cygwin/wincap.cc winsup/cygwin/wincap.h winsup/cygwin/winlean.h winsup/cygwin/winsup.h winsup/doc/ChangeLog winsup/doc/cygwinenv.sgml winsup/doc/faq-programming.xml winsup/doc/faq-using.xml winsup/doc/new-features.sgml winsup/doc/pathnames.sgml winsup/doc/setup-net.sgml winsup/doc/using.sgml winsup/lsaauth/ChangeLog winsup/lsaauth/Makefile.in winsup/lsaauth/cyglsa.c winsup/lsaauth/cyglsa64.dll winsup/lsaauth/make-64bit-version-with-mingw-w64.sh winsup/mingw/ChangeLog winsup/mingw/configure winsup/mingw/configure.in winsup/mingw/include/_mingw.h winsup/mingw/include/excpt.h winsup/mingw/include/inttypes.h winsup/mingw/include/limits.h winsup/mingw/include/process.h winsup/mingw/include/stdint.h winsup/mingw/include/stdio.h winsup/mingw/include/stdlib.h winsup/mingw/include/sys/param.h winsup/mingw/include/wchar.h winsup/mingw/mingwex/Makefile.in winsup/mingw/mingwex/gdtoa/gd_qnan.h winsup/mingw/mingwex/tsearch.c winsup/mingw/profile/Makefile.in winsup/utils/ChangeLog winsup/utils/Makefile.in winsup/utils/bloda.cc winsup/utils/cygcheck.cc winsup/utils/cygpath.cc winsup/utils/dump_setup.cc winsup/utils/dumper.cc winsup/utils/locale.cc winsup/utils/mkpasswd.c winsup/utils/ps.cc winsup/utils/regtool.cc winsup/utils/strace.cc winsup/w32api/ChangeLog winsup/w32api/include/setupapi.h winsup/w32api/include/winbase.h winsup/w32api/include/windows.h winsup/w32api/include/winnt.h winsup/w32api/include/winsock.h winsup/w32api/include/winsock2.h winsup/w32api/include/winuser.h winsup/w32api/include/winver.h winsup/w32api/include/wtsapi32.h winsup/w32api/lib/Makefile.in winsup/w32api/lib/kernel32.def winsup/w32api/lib/wtsapi32.def Cherrypick from master 2012-04-24 14:31:35 UTC Corinna Vinschen <corinna@vinschen.de> '*** empty log message ***': winsup/cygwin/include/cygwin/version.h winsup/cygwin/release/1.7.14 Delete: config/asmcfi.m4 config/math.m4 config/mmap.m4 config/weakref.m4 include/dwarf2.def include/elf/xgate.h include/gdb/gdb-index.h include/leb128.h include/opcode/xgate.h newlib/libc/string/memrchr.c winsup/cygwin/DevNotes winsup/cygwin/cygwait.cc winsup/cygwin/cygwait.h winsup/cygwin/include/machine/elf.h winsup/cygwin/include/sys/elf.h winsup/mingw/mingwex/membarrier.c winsup/w32api/include/sdkddkver.h winsup/w32api/include/shobjidl.h winsup/w32api/lib/shobjidl-uuid.c
Diffstat (limited to 'winsup/cygwin/select.cc')
-rw-r--r--winsup/cygwin/select.cc349
1 files changed, 157 insertions, 192 deletions
diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
index 3122c8203..85753e817 100644
--- a/winsup/cygwin/select.cc
+++ b/winsup/cygwin/select.cc
@@ -21,9 +21,9 @@ details. */
#include <wingdi.h>
#include <winuser.h>
+#include <netdb.h>
#define USE_SYS_TYPES_FD_SET
#include <winsock2.h>
-#include <netdb.h>
#include "cygerrno.h"
#include "security.h"
#include "path.h"
@@ -34,7 +34,6 @@ details. */
#include "pinfo.h"
#include "sigproc.h"
#include "cygtls.h"
-#include "cygwait.h"
/*
* All these defines below should be in sys/types.h
@@ -73,13 +72,7 @@ typedef long fd_mask;
#define UNIX_FD_ZERO(p, n) \
memset ((caddr_t) (p), 0, sizeof_fd_set ((n)))
-#define allocfd_set(n) ({\
- size_t __sfds = sizeof_fd_set (n) + 8; \
- void *__res = alloca (__sfds); \
- memset (__res, 0, __sfds); \
- (fd_set *) __res; \
-})
-
+#define allocfd_set(n) ((fd_set *) memset (alloca (sizeof_fd_set (n)), 0, sizeof_fd_set (n)))
#define copyfd_set(to, from, n) memcpy (to, from, sizeof_fd_set (n));
#define set_handle_or_return_if_not_open(h, s) \
@@ -88,139 +81,91 @@ typedef long fd_mask;
{ \
(s)->thread_errno = EBADF; \
return -1; \
- }
+ } \
-static int select (int, fd_set *, fd_set *, fd_set *, DWORD);
-
-/* The main select code. */
+/* The main select code.
+ */
extern "C" int
cygwin_select (int maxfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *to)
{
+ select_stuff sel;
+ fd_set *dummy_readfds = allocfd_set (maxfds);
+ fd_set *dummy_writefds = allocfd_set (maxfds);
+ fd_set *dummy_exceptfds = allocfd_set (maxfds);
+
select_printf ("select(%d, %p, %p, %p, %p)", maxfds, readfds, writefds, exceptfds, to);
pthread_testcancel ();
- int res;
- if (maxfds < 0)
- {
- set_errno (EINVAL);
- res = -1;
- }
- else
- {
- /* Convert to milliseconds or INFINITE if to == NULL */
- DWORD ms = to ? (to->tv_sec * 1000) + (to->tv_usec / 1000) : INFINITE;
- if (ms == 0 && to->tv_usec)
- ms = 1; /* At least 1 ms granularity */
- if (to)
- select_printf ("to->tv_sec %d, to->tv_usec %d, ms %d", to->tv_sec, to->tv_usec, ms);
- else
- select_printf ("to NULL, ms %x", ms);
+ if (!readfds)
+ readfds = dummy_readfds;
+ if (!writefds)
+ writefds = dummy_writefds;
+ if (!exceptfds)
+ exceptfds = dummy_exceptfds;
- res = select (maxfds, readfds ?: allocfd_set (maxfds),
- writefds ?: allocfd_set (maxfds),
- exceptfds ?: allocfd_set (maxfds), ms);
- }
- syscall_printf ("%R = select(%d, %p, %p, %p, %p)", res, maxfds, readfds,
- writefds, exceptfds, to);
- return res;
-}
+ for (int i = 0; i < maxfds; i++)
+ if (!sel.test_and_set (i, readfds, writefds, exceptfds))
+ {
+ select_printf ("aborting due to test_and_set error");
+ return -1; /* Invalid fd, maybe? */
+ }
-/* This function is arbitrarily split out from cygwin_select to avoid odd
- gcc issues with the use of allocfd_set and improper constructor handling
- for the sel variable. */
-static int
-select (int maxfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
- DWORD ms)
-{
- int res = select_stuff::select_loop;
+ /* Convert to milliseconds or INFINITE if to == NULL */
+ DWORD ms = to ? (to->tv_sec * 1000) + (to->tv_usec / 1000) : INFINITE;
+ if (ms == 0 && to->tv_usec)
+ ms = 1; /* At least 1 ms granularity */
- LONGLONG start_time = gtod.msecs (); /* Record the current time for later use. */
+ if (to)
+ select_printf ("to->tv_sec %d, to->tv_usec %d, ms %d", to->tv_sec, to->tv_usec, ms);
+ else
+ select_printf ("to NULL, ms %x", ms);
- select_stuff sel;
- sel.return_on_signal = 0;
+ select_printf ("sel.always_ready %d", sel.always_ready);
/* Allocate some fd_set structures using the number of fds as a guide. */
fd_set *r = allocfd_set (maxfds);
fd_set *w = allocfd_set (maxfds);
fd_set *e = allocfd_set (maxfds);
- while (res == select_stuff::select_loop)
- {
- /* Build the select record per fd linked list and set state as
- needed. */
- for (int i = 0; i < maxfds; i++)
- if (!sel.test_and_set (i, readfds, writefds, exceptfds))
- {
- select_printf ("aborting due to test_and_set error");
- return -1; /* Invalid fd, maybe? */
- }
- select_printf ("sel.always_ready %d", sel.always_ready);
-
- /* Degenerate case. No fds to wait for. Just wait for time to run out
- or signal to arrive. */
- if (sel.start.next == NULL)
- switch (cygwait (ms))
- {
- case WAIT_SIGNALED:
- select_printf ("signal received");
- if (_my_tls.call_signal_handler ())
- res = select_stuff::select_loop; /* Emulate linux behavior */
- else
- {
- set_sig_errno (EINTR);
- res = select_stuff::select_error;
- }
- break;
- case WAIT_CANCELED:
- sel.destroy ();
- pthread::static_cancel_self ();
- /*NOTREACHED*/
- default:
- res = select_stuff::select_set_zero; /* Set res to zero below. */
- break;
- }
- else if (sel.always_ready || ms == 0)
- res = 0; /* Catch any active fds via
- sel.poll() below */
- else
- res = sel.wait (r, w, e, ms); /* wait for an fd to become
- become active or time out */
- select_printf ("res %d", res);
- if (res >= 0)
+ int res = 0;
+ sel.return_on_signal = &_my_tls == _main_tls;
+ /* Degenerate case. No fds to wait for. Just wait. */
+ if (sel.start.next == NULL)
+ while (!res)
+ switch (cygwait (ms))
{
- copyfd_set (readfds, r, maxfds);
- copyfd_set (writefds, w, maxfds);
- copyfd_set (exceptfds, e, maxfds);
- /* Actually set the bit mask from sel records */
- res = (res == select_stuff::select_set_zero) ? 0 : sel.poll (readfds, writefds, exceptfds);
- }
- /* Always clean up everything here. If we're looping then build it
- all up again. */
- sel.cleanup ();
- sel.destroy ();
- /* Recalculate the time remaining to wait if we are going to be looping. */
- if (res == select_stuff::select_loop && ms != INFINITE)
- {
- select_printf ("recalculating ms");
- LONGLONG now = gtod.msecs ();
- if (now > (start_time + ms))
- {
- select_printf ("timed out after verification");
- res = select_stuff::select_error;
- }
- else
- {
- ms -= (now - start_time);
- start_time = now;
- select_printf ("ms now %u", ms);
- }
+ case WAIT_OBJECT_0:
+ select_printf ("signal received");
+ _my_tls.call_signal_handler ();
+ if (!sel.return_on_signal)
+ continue; /* Emulate linux behavior */
+ set_sig_errno (EINTR);
+ res = -1;
+ break;
+ case WAIT_OBJECT_0 + 1:
+ sel.destroy ();
+ pthread::static_cancel_self ();
+ /*NOTREACHED*/
+ default:
+ res = 1; /* temporary flag. Will be set to zero below. */
+ break;
}
+ else if (sel.always_ready || ms == 0)
+ res = 0;
+ else
+ res = sel.wait (r, w, e, ms);
+ if (res >= 0)
+ {
+ copyfd_set (readfds, r, maxfds);
+ copyfd_set (writefds, w, maxfds);
+ copyfd_set (exceptfds, e, maxfds);
+ res = (res > 0) ? 0 : sel.poll (readfds, writefds, exceptfds);
}
- if (res < -1)
- res = -1;
+ syscall_printf ("%R = select(%d, %p, %p, %p, %p)", res, maxfds, readfds,
+ writefds, exceptfds, to);
return res;
}
@@ -240,11 +185,11 @@ pselect(int maxfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
tv.tv_usec = ts->tv_nsec / 1000;
}
if (set)
- set_signal_mask (_my_tls.sigmask, *set);
+ set_signal_mask (*set, _my_tls.sigmask);
int ret = cygwin_select (maxfds, readfds, writefds, exceptfds,
ts ? &tv : NULL);
if (set)
- set_signal_mask (_my_tls.sigmask, oldset);
+ set_signal_mask (oldset, _my_tls.sigmask);
return ret;
}
@@ -268,7 +213,7 @@ select_stuff::cleanup ()
inline void
select_stuff::destroy ()
{
- select_record *s;
+ select_record *s = &start;
select_record *snext = start.next;
select_printf ("deleting select records");
@@ -277,7 +222,6 @@ select_stuff::destroy ()
snext = s->next;
delete s;
}
- start.next = NULL;
}
select_stuff::~select_stuff ()
@@ -324,19 +268,24 @@ err:
}
/* The heart of select. Waits for an fd to do something interesting. */
-select_stuff::wait_states
+int
select_stuff::wait (fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
DWORD ms)
{
+ int wait_ret;
HANDLE w4[MAXIMUM_WAIT_OBJECTS];
select_record *s = &start;
- DWORD m = 0;
+ int m = 0;
+ int res = 0;
+ bool is_cancelable = false;
- set_signal_arrived here (w4[m++]);
+ w4[m++] = signal_arrived; /* Always wait for the arrival of a signal. */
if ((w4[m] = pthread::get_cancel_event ()) != NULL)
- m++;
+ {
+ ++m;
+ is_cancelable = true;
+ }
- DWORD startfds = m;
/* Loop through the select chain, starting up anything appropriate and
counting the number of active fds. */
while ((s = s->next))
@@ -344,76 +293,73 @@ select_stuff::wait (fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
if (m >= MAXIMUM_WAIT_OBJECTS)
{
set_sig_errno (EINVAL);
- return select_error;
+ return -1;
}
if (!s->startup (s, this))
{
s->set_select_errno ();
- return select_error;
+ return -1;
}
- if (s->h != NULL)
- {
- for (DWORD i = startfds; i < m; i++)
- if (w4[i] == s->h)
- goto next_while;
- w4[m++] = s->h;
- }
-next_while:;
+ if (s->h == NULL)
+ continue;
+ for (int i = 1; i < m; i++)
+ if (w4[i] == s->h)
+ goto next_while;
+ w4[m++] = s->h;
+ next_while:
+ continue;
}
- debug_printf ("m %d, ms %u", m, ms);
+ LONGLONG start_time = gtod.msecs (); /* Record the current time for later use. */
- DWORD wait_ret;
- if (!windows_used)
- wait_ret = WaitForMultipleObjects (m, w4, FALSE, ms);
- else
- /* Using MWMO_INPUTAVAILABLE is the officially supported solution for
- the problem that the call to PeekMessage disarms the queue state
- so that a subsequent MWFMO hangs, even if there are still messages
- in the queue. */
- wait_ret = MsgWaitForMultipleObjectsEx (m, w4, ms,
- QS_ALLINPUT | QS_ALLPOSTMESSAGE,
- MWMO_INPUTAVAILABLE);
- select_printf ("wait_ret %d. verifying", wait_ret);
-
- wait_states res;
- switch (wait_ret)
+ debug_printf ("m %d, ms %u", m, ms);
+ for (;;)
{
- case WAIT_OBJECT_0:
- select_printf ("signal received");
- /* Need to get rid of everything when a signal occurs since we can't
- be assured that a signal handler won't jump out of select entirely. */
- cleanup ();
- destroy ();
- if (_my_tls.call_signal_handler ())
- res = select_loop;
+ if (!windows_used)
+ wait_ret = WaitForMultipleObjects (m, w4, FALSE, ms);
else
+ /* Using MWMO_INPUTAVAILABLE is the officially supported solution for
+ the problem that the call to PeekMessage disarms the queue state
+ so that a subsequent MWFMO hangs, even if there are still messages
+ in the queue. */
+ wait_ret = MsgWaitForMultipleObjectsEx (m, w4, ms,
+ QS_ALLINPUT | QS_ALLPOSTMESSAGE,
+ MWMO_INPUTAVAILABLE);
+
+ switch (wait_ret)
{
+ case WAIT_OBJECT_0:
+ select_printf ("signal received");
+ _my_tls.call_signal_handler ();
+ if (!return_on_signal)
+ continue; /* Emulate linux behavior */
+ cleanup ();
set_sig_errno (EINTR);
- res = select_signalled; /* Cause loop exit in cygwin_select */
- }
- break;
- case WAIT_FAILED:
- system_printf ("WaitForMultipleObjects failed");
- s = &start;
- s->set_select_errno ();
- res = select_error;
- break;
- case WAIT_TIMEOUT:
- select_printf ("timed out");
- res = select_set_zero;
- break;
- case WAIT_OBJECT_0 + 1:
- if (startfds > 1)
- {
+ return -1;
+ case WAIT_OBJECT_0 + 1:
+ if (is_cancelable)
+ {
+ cleanup ();
+ destroy ();
+ pthread::static_cancel_self ();
+ }
+ /* This wasn't a cancel event. It was just a normal object to wait
+ for. */
+ break;
+ case WAIT_FAILED:
cleanup ();
- destroy ();
- pthread::static_cancel_self ();
- /*NOTREACHED*/
+ system_printf ("WaitForMultipleObjects failed");
+ s = &start;
+ s->set_select_errno ();
+ return -1;
+ case WAIT_TIMEOUT:
+ cleanup ();
+ select_printf ("timed out");
+ res = 1;
+ goto out;
}
- /* Fall through. This wasn't a cancel event. It was just a normal object
- to wait for. */
- default:
+
+ select_printf ("woke up. wait_ret %d. verifying", wait_ret);
s = &start;
bool gotone = false;
/* Some types of objects (e.g., consoles) wake up on "inappropriate" events
@@ -423,21 +369,40 @@ next_while:;
while ((s = s->next))
if (s->saw_error ())
{
+ cleanup ();
set_errno (s->saw_error ());
- res = select_error; /* Somebody detected an error */
- goto out;
+ return -1; /* Somebody detected an error */
}
else if ((((wait_ret >= m && s->windows_handle) || s->h == w4[wait_ret]))
&& s->verify (s, readfds, writefds, exceptfds))
gotone = true;
- if (!gotone)
- res = select_loop;
- else
- res = select_ok;
select_printf ("gotone %d", gotone);
- break;
+ if (gotone)
+ {
+ cleanup ();
+ goto out;
+ }
+
+ if (ms == INFINITE)
+ {
+ select_printf ("looping");
+ continue;
+ }
+ select_printf ("recalculating ms");
+
+ LONGLONG now = gtod.msecs ();
+ if (now > (start_time + ms))
+ {
+ cleanup ();
+ select_printf ("timed out after verification");
+ goto out;
+ }
+ ms -= (now - start_time);
+ start_time = now;
+ select_printf ("ms now %u", ms);
}
+
out:
select_printf ("returning %d", res);
return res;
@@ -1323,7 +1288,7 @@ thread_socket (void *arg)
/ MAXIMUM_WAIT_OBJECTS));
bool event = false;
- select_printf ("stuff_start %p, timeout %u", si->start, timeout);
+ select_printf ("stuff_start %p", si->start);
while (!event)
{
for (select_record *s = si->start; (s = s->next); )