* select.h: New file split from fhandler.h.

(select_record::select_record): Define do-nothing constructor for "new" to
avoid gratuitous zeroing.
(select_info): New base class.
(select_pipe_info): New class with methods for dealing with pipes.
(select_socket_info): New class with methods for dealing with sockets.
(select_serial_info): Dummy class for serial.
(select_mailslot_info): Dummy class for mailslots.
(select_stuff): Define device_specific_* as actual classes rather than void *.
* dtable.h (dtable::select_read): Accommodate return value change to 'bool' and
argument change to "select_stuff".
(dtable::select_write): Ditto.
(dtable::select_except): Ditto.
* dtable.cc (dtable::select_read): Accommodate return value change to 'bool'
and argument change to "select_stuff".
(dtable::select_write): Ditto.
(dtable::select_except): Ditto.
* fhandler.h: Excise select-related classes.
(fhandler_*::select_read): Change argument to select_stuff.
(fhandler_*::select_write): Ditto.
(fhandler_*::select_except): Ditto.
* select.cc (UNIX_FD_ZERO): Use memset rather than bzero.
(select_stuff::test_and_set): Change return type to bool.  Allocate
select_record on entry and let fhandler_*::select_* operate on the start.next
field of select_stuff.
(pipeinf): Delete.
(select_pipe_info::select_pipe_info): New constructor.  Allocates event for
controlling pipe waits.
(select_pipe_info::~select_pipe_info): New destructor.  Destroy event.  Stop
thread.
(select_pipe_info::add_watch_handle): New function.
(thread_pipe): Wait for the hEvent part of any overlapped pipes before peeking.
(start_thread_pipe): Don't allocate device_specific_pipe stuff here.  Assume
that it has been allocated earlier.
(pipe_cleanup): Rely on select_pipe_info destructor to clean up pipe
paraphenalia.
(fhandler_*::select_*): Derive select_record from new select_stuff argument.
(fhandler_pipe::select_*): Ditto.  Allocate pipe-specific field if not already
allocated.
(serialinf): Delete.
(thread_serial): serialinf -> select_serial_info.
(fhandler_base::ready_for_read): Rewrite to accommodate change in argument to
fhandler_*::select_*.
(socketinf): Delete.
(thread_socket): socketinf -> select_socket_info.
(mailslotinf): Delete.
(thread_mailslot): mailslotinf -> select_mailslot_info.
This commit is contained in:
Christopher Faylor
2009-06-30 21:18:44 +00:00
parent 840bb39798
commit b4fa816474
13 changed files with 457 additions and 330 deletions

View File

@@ -25,6 +25,7 @@ details. */
#include "perprocess.h"
#include "path.h"
#include "fhandler.h"
#include "select.h"
#include "dtable.h"
#include "cygheap.h"
#include "tls_pbuf.h"
@@ -359,7 +360,7 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle)
access |= GENERIC_WRITE; /* Should be rdwr for stderr but not sure that's
possible for some versions of handles */
/* FIXME: Workaround Windows 7 64 bit issue. If the parent process of
the process tree closes the original handles to the console window,
the process tree closes the original handles to the console window,
strange problems occur when starting child processes later on if
stdio redirection is used. How to reproduce:
@@ -378,7 +379,7 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle)
Remove the `exec 2>' or remove the cat call and the script will work.
Start bash interactively, then start the script manually, and the
script will work.
This needs further investigation but the workaround not to close
the handles will have a marginal hit of three extra handles per
process at most. */
@@ -654,26 +655,26 @@ done:
return res;
}
select_record *
dtable::select_read (int fd, select_record *s)
bool
dtable::select_read (int fd, select_stuff *ss)
{
if (not_open (fd))
{
set_errno (EBADF);
return NULL;
return false;
}
fhandler_base *fh = fds[fd];
s = fh->select_read (s);
select_record *s = fh->select_read (ss);
s->fd = fd;
if (!s->fh)
s->fh = fh;
s->thread_errno = 0;
debug_printf ("%s fd %d", fh->get_name (), fd);
return s;
return true;
}
select_record *
dtable::select_write (int fd, select_record *s)
bool
dtable::select_write (int fd, select_stuff *ss)
{
if (not_open (fd))
{
@@ -681,16 +682,16 @@ dtable::select_write (int fd, select_record *s)
return NULL;
}
fhandler_base *fh = fds[fd];
s = fh->select_write (s);
select_record *s = fh->select_write (ss);
s->fd = fd;
s->fh = fh;
s->thread_errno = 0;
debug_printf ("%s fd %d", fh->get_name (), fd);
return s;
debug_printf ("%s fd %d", fh->get_name ());
return true;
}
select_record *
dtable::select_except (int fd, select_record *s)
bool
dtable::select_except (int fd, select_stuff *ss)
{
if (not_open (fd))
{
@@ -698,12 +699,12 @@ dtable::select_except (int fd, select_record *s)
return NULL;
}
fhandler_base *fh = fds[fd];
s = fh->select_except (s);
select_record *s = fh->select_except (ss);
s->fd = fd;
s->fh = fh;
s->thread_errno = 0;
debug_printf ("%s fd %d", fh->get_name (), fd);
return s;
return true;
}
void