2009-07-01 05:18:44 +08:00
|
|
|
/* select.h
|
|
|
|
|
|
|
|
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_
|
|
|
|
|
2020-03-24 04:06:00 +08:00
|
|
|
struct fh_select_data_serial
|
|
|
|
{
|
|
|
|
DWORD event;
|
|
|
|
OVERLAPPED ov;
|
|
|
|
|
|
|
|
fh_select_data_serial () : event (0) { memset (&ov, 0, sizeof ov); }
|
|
|
|
};
|
|
|
|
|
2009-07-01 05:18:44 +08:00
|
|
|
struct select_record
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
HANDLE h;
|
|
|
|
fhandler_base *fh;
|
2019-01-15 00:03:39 +08:00
|
|
|
_cygtls *tls;
|
2009-07-01 05:18:44 +08:00
|
|
|
int thread_errno;
|
|
|
|
bool windows_handle;
|
|
|
|
bool read_ready, write_ready, except_ready;
|
|
|
|
bool read_selected, write_selected, except_selected;
|
|
|
|
bool except_on_write;
|
2012-12-23 03:35:41 +08:00
|
|
|
int (*startup) (select_record *, class select_stuff *);
|
2009-07-01 05:18:44 +08:00
|
|
|
int (*peek) (select_record *, bool);
|
2012-12-23 03:35:41 +08:00
|
|
|
int (*verify) (select_record *, fd_set *, fd_set *, fd_set *);
|
|
|
|
void (*cleanup) (select_record *, class select_stuff *);
|
2009-07-01 05:18:44 +08:00
|
|
|
struct select_record *next;
|
2020-03-24 04:06:00 +08:00
|
|
|
/* If an fhandler type needs per-fhandler, per-select data, this union
|
|
|
|
is the place to add it. First candidate: fhandler_serial. */
|
|
|
|
union
|
|
|
|
{
|
|
|
|
fh_select_data_serial *fh_data_serial;
|
|
|
|
void *fh_data_union; /* type-agnostic placeholder for constructor */
|
|
|
|
};
|
2009-07-01 05:18:44 +08:00
|
|
|
void set_select_errno () {__seterrno (); thread_errno = errno;}
|
|
|
|
int saw_error () {return thread_errno;}
|
2012-12-20 06:07:14 +08:00
|
|
|
select_record (int): next (NULL) {}
|
2019-01-15 00:03:39 +08:00
|
|
|
select_record () :
|
|
|
|
fd (0), h (NULL), fh (NULL), tls (&_my_tls), thread_errno (0),
|
2009-07-01 05:18:44 +08:00
|
|
|
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),
|
2020-03-24 04:06:00 +08:00
|
|
|
next (NULL), fh_data_union (NULL) {}
|
2012-12-23 03:35:41 +08:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
void dump_select_record ();
|
|
|
|
#endif
|
2009-07-01 05:18:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct select_info
|
|
|
|
{
|
|
|
|
cygthread *thread;
|
|
|
|
bool stop_thread;
|
2020-01-06 22:38:34 +08:00
|
|
|
HANDLE bye;
|
2009-07-01 05:18:44 +08:00
|
|
|
select_record *start;
|
2012-12-23 03:35:41 +08:00
|
|
|
select_info (): thread (NULL), stop_thread (0), start (NULL) {}
|
2009-07-01 05:18:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct select_pipe_info: public select_info
|
|
|
|
{
|
2012-12-23 03:35:41 +08:00
|
|
|
select_pipe_info (): select_info () {}
|
2009-07-01 05:18:44 +08:00
|
|
|
};
|
|
|
|
|
2019-03-23 03:30:41 +08:00
|
|
|
struct select_fifo_info: public select_info
|
|
|
|
{
|
|
|
|
select_fifo_info (): select_info () {}
|
|
|
|
};
|
|
|
|
|
2009-07-01 05:18:44 +08:00
|
|
|
struct select_socket_info: public select_info
|
|
|
|
{
|
|
|
|
int num_w4;
|
|
|
|
LONG *ser_num;
|
|
|
|
HANDLE *w4;
|
2013-03-31 20:37:45 +08:00
|
|
|
select_socket_info (): select_info (), num_w4 (0), ser_num (0), w4 (NULL) {}
|
2009-07-01 05:18:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class select_stuff
|
|
|
|
{
|
|
|
|
public:
|
2012-06-03 10:59:20 +08:00
|
|
|
enum wait_states
|
|
|
|
{
|
|
|
|
select_signalled = -3,
|
|
|
|
select_error = -1,
|
|
|
|
select_ok = 0,
|
|
|
|
select_set_zero = 1
|
|
|
|
};
|
|
|
|
|
2009-07-01 05:18:44 +08:00
|
|
|
~select_stuff ();
|
2012-01-22 14:45:08 +08:00
|
|
|
bool return_on_signal;
|
2009-07-01 05:18:44 +08:00
|
|
|
bool always_ready, windows_used;
|
|
|
|
select_record start;
|
|
|
|
|
2020-03-24 04:06:00 +08:00
|
|
|
/* If an fhandler type needs a singleton per-select datastructure for all
|
|
|
|
its objects in the descriptor lists, here's the place to be. This is
|
|
|
|
mainly used to maintain a single thread for all fhandlers of a single
|
|
|
|
type in the descriptor lists. */
|
2009-07-01 05:18:44 +08:00
|
|
|
select_pipe_info *device_specific_pipe;
|
2019-09-05 12:22:54 +08:00
|
|
|
select_pipe_info *device_specific_ptys;
|
2019-03-23 03:30:41 +08:00
|
|
|
select_fifo_info *device_specific_fifo;
|
2009-07-01 05:18:44 +08:00
|
|
|
select_socket_info *device_specific_socket;
|
|
|
|
|
2012-12-23 03:35:41 +08:00
|
|
|
bool test_and_set (int, fd_set *, fd_set *, fd_set *);
|
|
|
|
int poll (fd_set *, fd_set *, fd_set *);
|
2016-05-19 07:14:16 +08:00
|
|
|
wait_states wait (fd_set *, fd_set *, fd_set *, LONGLONG);
|
2009-07-01 05:18:44 +08:00
|
|
|
void cleanup ();
|
2011-05-03 23:58:52 +08:00
|
|
|
void destroy ();
|
2012-06-03 10:59:20 +08:00
|
|
|
|
2012-01-22 14:45:08 +08:00
|
|
|
select_stuff (): return_on_signal (false), always_ready (false),
|
2019-01-15 00:19:37 +08:00
|
|
|
windows_used (false), start (),
|
2012-06-28 05:42:11 +08:00
|
|
|
device_specific_pipe (NULL),
|
2019-09-05 12:22:54 +08:00
|
|
|
device_specific_ptys (NULL),
|
2019-03-23 03:30:41 +08:00
|
|
|
device_specific_fifo (NULL),
|
2020-03-19 04:14:06 +08:00
|
|
|
device_specific_socket (NULL)
|
2019-08-16 22:36:06 +08:00
|
|
|
{}
|
2009-07-01 05:18:44 +08:00
|
|
|
};
|
2015-11-19 05:13:31 +08:00
|
|
|
|
|
|
|
extern "C" int cygwin_select (int , fd_set *, fd_set *, fd_set *,
|
|
|
|
struct timeval *to);
|
|
|
|
|
2009-07-01 05:18:44 +08:00
|
|
|
#endif /* _SELECT_H_ */
|