summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2006-01-14 05:14:26 +0000
committerMark Mitchell <mark@codesourcery.com>2006-01-14 05:14:26 +0000
commit25473b5709b82b605d0c6645398ae182d84bd9f2 (patch)
treef19887837b2ffd9234d86b735436f78ad57d8434
parent3c327477b6d90c10f896bd3b54d59f405e1579b6 (diff)
downloadgdb-25473b5709b82b605d0c6645398ae182d84bd9f2.tar.gz
Backport:
2006-01-13 Mark Mitchell <mark@codesourcery.com> * event-loop.c (gdb_select): Detect file descriptors that have been closed.
-rw-r--r--ChangeLog.csl7
-rw-r--r--gdb/event-loop.c37
2 files changed, 32 insertions, 12 deletions
diff --git a/ChangeLog.csl b/ChangeLog.csl
index 35f626b6085..81f2f2bc7eb 100644
--- a/ChangeLog.csl
+++ b/ChangeLog.csl
@@ -1,3 +1,10 @@
+2006-01-13 Mark Mitchell <mark@codesourcery.com>
+
+ Backport:
+ 2006-01-13 Mark Mitchell <mark@codesourcery.com>
+ * event-loop.c (gdb_select): Detect file descriptors that have
+ been closed.
+
2005-11-16 Mark Mitchell <mark@codesourcery.com>
* gdb/remote-sim.c (gdbsim_wait): Don't use target_signal_to_host
diff --git a/gdb/event-loop.c b/gdb/event-loop.c
index 2f3d5359b79..df38034fd4c 100644
--- a/gdb/event-loop.c
+++ b/gdb/event-loop.c
@@ -749,22 +749,39 @@ gdb_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
int fd;
int num_ready;
+ num_ready = 0;
num_handles = 0;
for (fd = 0; fd < n; ++fd)
{
- /* EXCEPTFDS is silently ignored. GDB always sets GDB_EXCEPTION
- when calling add_file_handler, but there is no natural analog
- under Windows. */
/* There is no support yet for WRITEFDS. At present, this isn't
used by GDB -- but we do not want to silently ignore WRITEFDS
if something starts using it. */
gdb_assert (!FD_ISSET (fd, writefds));
- if (FD_ISSET (fd, readfds))
+ if (!FD_ISSET (fd, readfds)
+ && !FD_ISSET (fd, exceptfds))
+ continue;
+ h = (HANDLE) _get_osfhandle (fd);
+ if (h == INVALID_HANDLE_VALUE)
{
- gdb_assert (num_handles < MAXIMUM_WAIT_OBJECTS);
- handles[num_handles++] = (HANDLE) _get_osfhandle (fd);
+ /* If the underlying handle is INVALID_HANDLE_VALUE, then
+ this descriptor is no more. */
+ if (FD_ISSET (fd, exceptfds))
+ ++num_ready;
+ continue;
}
+ /* The only exceptional condition we recognize is a closed file
+ descriptor. Since we have already checked for that
+ condition, clear the exceptional bit for this descriptor. */
+ FD_CLR (fd, exceptfds);
+ if (FD_ISSET (fd, readfds))
+ {
+ gdb_assert (num_handles < MAXIMUM_WAIT_OBJECTS);
+ handles[num_handles++] = h;
+ }
}
+ /* If we don't need to wait for any handles, we are done. */
+ if (!num_handles)
+ return num_ready;
event = WaitForMultipleObjects (num_handles,
handles,
FALSE,
@@ -779,10 +796,10 @@ gdb_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
if (event == WAIT_FAILED)
return -1;
if (event == WAIT_TIMEOUT)
- return 0;
+ return num_ready;
/* Run through the READFDS, clearing bits corresponding to descriptors
for which input is unavailable. */
- num_ready = num_handles;
+ num_ready += num_handles;
h = handles[event - WAIT_OBJECT_0];
for (fd = 0; fd < n; ++fd)
{
@@ -798,10 +815,6 @@ gdb_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
--num_ready;
}
}
- /* We never report any descriptors available for writing or with
- exceptional conditions. */
- FD_ZERO (writefds);
- FD_ZERO (exceptfds);
return num_ready;
#else