summaryrefslogtreecommitdiff
path: root/gdb/event-loop.c
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2006-01-14 05:13:21 +0000
committerMark Mitchell <mark@codesourcery.com>2006-01-14 05:13:21 +0000
commit3b6e0bb13a08bd9a8096964b7ece4702da00d6a9 (patch)
tree545706d69446eb60e3b9a8b40a7aba85f0d6da40 /gdb/event-loop.c
parent276faf778ab18c32290d857b0a7afe957043f99c (diff)
downloadgdb-3b6e0bb13a08bd9a8096964b7ece4702da00d6a9.tar.gz
* event-loop.c (gdb_select): Detect file descriptors that have
been closed.
Diffstat (limited to 'gdb/event-loop.c')
-rw-r--r--gdb/event-loop.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/gdb/event-loop.c b/gdb/event-loop.c
index e336b339424..4f859b115c6 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