diff options
author | Christopher Faylor <me@cgf.cx> | 2009-06-30 21:18:44 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2009-06-30 21:18:44 +0000 |
commit | b4fa8164748f263f152f8ec26bf361fa2d364737 (patch) | |
tree | cface150f510c4525d88eb186c897f8a81859fb8 /winsup/cygwin/select.h | |
parent | 840bb397986fa6914a67e62e25df97e1dd88dc45 (diff) | |
download | cygnal-b4fa8164748f263f152f8ec26bf361fa2d364737.tar.gz cygnal-b4fa8164748f263f152f8ec26bf361fa2d364737.tar.bz2 cygnal-b4fa8164748f263f152f8ec26bf361fa2d364737.zip |
* 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.
Diffstat (limited to 'winsup/cygwin/select.h')
-rw-r--r-- | winsup/cygwin/select.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/winsup/cygwin/select.h b/winsup/cygwin/select.h new file mode 100644 index 000000000..766f8c679 --- /dev/null +++ b/winsup/cygwin/select.h @@ -0,0 +1,98 @@ +/* select.h + + Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, + 2005, 2006, 2007, 2008, 2009 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. */ + +#ifndef _SELECT_H_ +#define _SELECT_H_ + +struct select_record +{ + int fd; + HANDLE h; + fhandler_base *fh; + int thread_errno; + bool windows_handle; + bool read_ready, write_ready, except_ready; + bool read_selected, write_selected, except_selected; + bool except_on_write; + int (*startup) (select_record *me, class select_stuff *stuff); + int (*peek) (select_record *, bool); + int (*verify) (select_record *me, fd_set *readfds, fd_set *writefds, + fd_set *exceptfds); + void (*cleanup) (select_record *me, class select_stuff *stuff); + struct select_record *next; + void set_select_errno () {__seterrno (); thread_errno = errno;} + int saw_error () {return thread_errno;} + select_record () {} + select_record (int): fd (0), h (NULL), fh (NULL), thread_errno (0), + windows_handle (false), read_ready (false), write_ready (false), + except_ready (false), read_selected (false), write_selected (false), + except_selected (false), except_on_write (false), + startup (NULL), peek (NULL), verify (NULL), cleanup (NULL), + next (NULL) {} +}; + +struct select_info +{ + cygthread *thread; + bool stop_thread; + select_record *start; + select_info () {} +}; + +struct select_pipe_info: public select_info +{ + DWORD n; + HANDLE w4[MAXIMUM_WAIT_OBJECTS]; + select_pipe_info (); + ~select_pipe_info (); + void add_watch_handle (fhandler_pipe *); +}; + +struct select_socket_info: public select_info +{ + int max_w4; + int num_w4; + LONG *ser_num; + HANDLE *w4; +}; + +struct select_serial_info: public select_info +{ +}; + +struct select_mailslot_info: public select_info +{ +}; + +class select_stuff +{ +public: + ~select_stuff (); + bool always_ready, windows_used; + select_record start; + + select_pipe_info *device_specific_pipe; + select_socket_info *device_specific_socket; + select_serial_info *device_specific_serial; + select_mailslot_info *device_specific_mailslot; + + bool test_and_set (int i, fd_set *readfds, fd_set *writefds, + fd_set *exceptfds); + int poll (fd_set *readfds, fd_set *writefds, fd_set *exceptfds); + int wait (fd_set *readfds, fd_set *writefds, fd_set *exceptfds, DWORD ms); + void cleanup (); + select_stuff (): always_ready (0), windows_used (0), start (0), + device_specific_pipe (0), + device_specific_socket (0), + device_specific_serial (0), + device_specific_mailslot (0) {} +}; +#endif /* _SELECT_H_ */ |