b4fa816474
(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.
94 lines
2.8 KiB
C++
94 lines
2.8 KiB
C++
/* dtable.h: fd table definition.
|
|
|
|
Copyright 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008 Red Hat, Inc.
|
|
|
|
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. */
|
|
|
|
/* Initial and increment values for cygwin's fd table */
|
|
#define NOFILE_INCR 32
|
|
|
|
#include "thread.h"
|
|
#include "sync.h"
|
|
|
|
class suffix_info;
|
|
|
|
#define BFH_OPTS (PC_NULLEMPTY | PC_FULL | PC_POSIX)
|
|
class dtable
|
|
{
|
|
fhandler_base **fds;
|
|
#ifdef NEWVFORK
|
|
fhandler_base **fds_on_hold;
|
|
#endif
|
|
fhandler_base **archetypes;
|
|
unsigned narchetypes;
|
|
unsigned farchetype;
|
|
static const int initial_archetype_size = 8;
|
|
int first_fd_for_open;
|
|
void lock () {lock_process::locker.acquire ();}
|
|
void unlock () {lock_process::locker.release ();}
|
|
public:
|
|
size_t size;
|
|
|
|
dtable () : archetypes (NULL), narchetypes (0), farchetype (0), first_fd_for_open(3) {}
|
|
void init () {first_fd_for_open = 3;}
|
|
|
|
void move_fd (int, int);
|
|
int vfork_child_dup ();
|
|
void vfork_parent_restore ();
|
|
void vfork_child_fixup ();
|
|
fhandler_base *dup_worker (fhandler_base *oldfh);
|
|
int extend (int howmuch);
|
|
void fixup_after_fork (HANDLE);
|
|
inline int not_open (int fd)
|
|
{
|
|
lock ();
|
|
int res = fd < 0 || fd >= (int) size || fds[fd] == NULL;
|
|
unlock ();
|
|
return res;
|
|
}
|
|
int find_unused_handle (int start);
|
|
int find_unused_handle () { return find_unused_handle (first_fd_for_open);}
|
|
void release (int fd);
|
|
void init_std_file_from_handle (int fd, HANDLE handle);
|
|
int dup2 (int oldfd, int newfd);
|
|
void fixup_after_exec ();
|
|
inline fhandler_base *&operator [](int fd) const { return fds[fd]; }
|
|
bool select_read (int fd, select_stuff *);
|
|
bool select_write (int fd, select_stuff *);
|
|
bool select_except (int fd, select_stuff *);
|
|
operator fhandler_base **() {return fds;}
|
|
void stdio_init ();
|
|
void get_debugger_info ();
|
|
void set_file_pointers_for_exec ();
|
|
#ifdef NEWVFORK
|
|
bool in_vfork_cleanup () {return fds_on_hold == fds;}
|
|
#endif
|
|
fhandler_base *find_archetype (device& dev);
|
|
fhandler_base **add_archetype ();
|
|
void delete_archetype (fhandler_base *);
|
|
friend void dtable_init ();
|
|
friend void __stdcall close_all_files (bool);
|
|
friend class fhandler_disk_file;
|
|
friend class cygheap_fdmanip;
|
|
friend class cygheap_fdget;
|
|
friend class cygheap_fdnew;
|
|
friend class cygheap_fdenum;
|
|
friend class lock_process;
|
|
};
|
|
|
|
fhandler_base *build_fh_dev (const device&, const char * = NULL);
|
|
fhandler_base *build_fh_name (const char *, HANDLE = NULL, unsigned = 0, suffix_info * = NULL);
|
|
fhandler_base *build_fh_name (const UNICODE_STRING *, HANDLE = NULL, unsigned = 0, suffix_info * = NULL);
|
|
fhandler_base *build_fh_pc (path_conv& pc);
|
|
|
|
void dtable_init ();
|
|
void stdio_init ();
|
|
extern dtable fdtab;
|
|
|
|
extern "C" int getfdtabsize ();
|
|
extern "C" void setfdtabsize (int);
|