* fhandler.h (fhandler_base::status): Declare private.

(fhandler_base::open_status): Ditto.
	(class fhandler_socket): Move status bits into private bitfield struct
	type status_flags.  Change accessor methods appropriately.
	* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
	above status bit changes.
	* tty.h: Remove status bit enumerator.
	(TTYISSETF): Remove.
	(TTYSETF): Remove.
	(TTYCLEARF): Remove.
	(TTYCONDSETF): Remove.
	(tty_min::status): Define as private bitfield struct type status_flags.
	Add appropriate accessor methods.
	* fhandler_console.cc: Use tty_min::status accessor methods throughout.
	* fhandler_termios.cc: Ditto.
	* winsup.h (__ISSETF): Remove.
	(__SETF): Remove.
	(__CLEARF): Remove.
	(__CONDSETF): Remove.
This commit is contained in:
Corinna Vinschen 2004-04-09 12:09:45 +00:00
parent b79f85c28b
commit 7aa88267c1
7 changed files with 64 additions and 47 deletions

View File

@ -1,3 +1,25 @@
2004-04-09 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (fhandler_base::status): Declare private.
(fhandler_base::open_status): Ditto.
(class fhandler_socket): Move status bits into private bitfield struct
type status_flags. Change accessor methods appropriately.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
above status bit changes.
* tty.h: Remove status bit enumerator.
(TTYISSETF): Remove.
(TTYSETF): Remove.
(TTYCLEARF): Remove.
(TTYCONDSETF): Remove.
(tty_min::status): Define as private bitfield struct type status_flags.
Add appropriate accessor methods.
* fhandler_console.cc: Use tty_min::status accessor methods throughout.
* fhandler_termios.cc: Ditto.
* winsup.h (__ISSETF): Remove.
(__SETF): Remove.
(__CLEARF): Remove.
(__CONDSETF): Remove.
2004-04-09 Corinna Vinschen <corinna@vinschen.de> 2004-04-09 Corinna Vinschen <corinna@vinschen.de>
* fhandler.cc (fhandler_base::write): Use bool parameter in calls to * fhandler.cc (fhandler_base::write): Use bool parameter in calls to

View File

@ -71,7 +71,6 @@ class fhandler_base
friend class dtable; friend class dtable;
friend void close_all_files (); friend void close_all_files ();
protected:
struct status_flags struct status_flags
{ {
unsigned rbinary : 1; /* binary read mode */ unsigned rbinary : 1; /* binary read mode */
@ -92,7 +91,7 @@ class fhandler_base
unsigned close_on_exec : 1; /* close-on-exec */ unsigned close_on_exec : 1; /* close-on-exec */
unsigned need_fork_fixup : 1; /* Set if need to fixup after fork. */ unsigned need_fork_fixup : 1; /* Set if need to fixup after fork. */
public: public:
status_flags () : status_flags () :
rbinary (0), rbinset (0), wbinary (0), wbinset (0), no_handle (0), rbinary (0), rbinset (0), wbinary (0), wbinset (0), no_handle (0),
async_io (0), uninterruptible_io (0), append_mode (0), lseeked (0), async_io (0), uninterruptible_io (0), append_mode (0), lseeked (0),
@ -355,9 +354,17 @@ class fhandler_socket: public fhandler_base
HANDLE secret_event; HANDLE secret_event;
struct _WSAPROTOCOL_INFOA *prot_info_ptr; struct _WSAPROTOCOL_INFOA *prot_info_ptr;
char *sun_path; char *sun_path;
unsigned sock_saw_shut_rd : 1; /* Socket saw a SHUT_RD */ struct status_flags
unsigned sock_saw_shut_wr : 1; /* Socket saw a SHUT_WR */ {
unsigned had_connect_or_listen : 2; unsigned sock_saw_shut_rd : 1; /* Socket saw a SHUT_RD */
unsigned sock_saw_shut_wr : 1; /* Socket saw a SHUT_WR */
unsigned had_connect_or_listen : 2;
public:
status_flags () :
sock_saw_shut_rd (0), sock_saw_shut_wr (0),
had_connect_or_listen (unconnected)
{}
} status;
public: public:
fhandler_socket (); fhandler_socket ();
@ -365,20 +372,22 @@ class fhandler_socket: public fhandler_base
int get_socket () { return (int) get_handle(); } int get_socket () { return (int) get_handle(); }
fhandler_socket *is_socket () { return this; } fhandler_socket *is_socket () { return this; }
bool saw_shutdown_read () const {return sock_saw_shut_rd;} bool saw_shutdown_read () const { return status.sock_saw_shut_rd; }
bool saw_shutdown_write () const {return sock_saw_shut_wr;} bool saw_shutdown_write () const { return status.sock_saw_shut_wr; }
void set_shutdown_read () { sock_saw_shut_rd = 1;} void set_shutdown_read () { status.sock_saw_shut_rd = 1;}
void set_shutdown_write () { sock_saw_shut_wr = 1;} void set_shutdown_write () { status.sock_saw_shut_wr = 1;}
bool is_unconnected () const { return had_connect_or_listen == unconnected; } bool is_unconnected () const
{ return status.had_connect_or_listen == unconnected; }
bool is_connect_pending () const bool is_connect_pending () const
{ return had_connect_or_listen == connect_pending; } { return status.had_connect_or_listen == connect_pending; }
bool is_connected () const { return had_connect_or_listen == connected; } bool is_connected () const
{ return status.had_connect_or_listen == connected; }
void set_connect_state (connect_state newstate) void set_connect_state (connect_state newstate)
{ had_connect_or_listen = newstate; } { status.had_connect_or_listen = newstate; }
connect_state get_connect_state () const connect_state get_connect_state () const
{ return (connect_state) had_connect_or_listen; } { return (connect_state) status.had_connect_or_listen; }
int bind (const struct sockaddr *name, int namelen); int bind (const struct sockaddr *name, int namelen);
int connect (const struct sockaddr *name, int namelen); int connect (const struct sockaddr *name, int namelen);

View File

@ -154,10 +154,8 @@ set_console_state_for_spawn ()
if (shared_console_info != NULL) if (shared_console_info != NULL)
{ {
/* ACK. Temporarily define for use in TTYSETF macro */ /* ACK. Temporarily define for use in TTYSETF macro */
# define tc &shared_console_info->tty_min_state
SetConsoleMode (h, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT); SetConsoleMode (h, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT);
TTYSETF (RSTCONS); shared_console_info->tty_min_state.set_rstcons ();
# undef tc
} }
CloseHandle (h); CloseHandle (h);
@ -538,7 +536,7 @@ sig_exit:
void void
fhandler_console::set_input_state () fhandler_console::set_input_state ()
{ {
if (TTYISSETF (RSTCONS)) if (tc->needs_rstcons ())
input_tcsetattr (0, &tc->ti); input_tcsetattr (0, &tc->ti);
} }
@ -660,7 +658,7 @@ fhandler_console::open (int flags, mode_t)
SetConsoleMode (get_io_handle (), ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT | cflags); SetConsoleMode (get_io_handle (), ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT | cflags);
} }
TTYCLEARF (RSTCONS); tc->clear_rstcons ();
set_open_status (); set_open_status ();
cygheap->open_fhs++; cygheap->open_fhs++;
debug_printf ("incremented open_fhs, now %d", cygheap->open_fhs); debug_printf ("incremented open_fhs, now %d", cygheap->open_fhs);
@ -844,7 +842,7 @@ fhandler_console::input_tcsetattr (int, struct termios const *t)
res, t, flags, t->c_lflag, t->c_iflag); res, t, flags, t->c_lflag, t->c_iflag);
} }
TTYCLEARF (RSTCONS); tc->clear_rstcons ();
return res; return res;
} }

View File

@ -124,9 +124,7 @@ get_inet_addr (const struct sockaddr *in, int inlen,
fhandler_socket::fhandler_socket () : fhandler_socket::fhandler_socket () :
fhandler_base (), fhandler_base (),
sun_path (NULL), sun_path (NULL),
sock_saw_shut_rd (0), status ()
sock_saw_shut_wr (0),
had_connect_or_listen (unconnected)
{ {
set_need_fork_fixup (); set_need_fork_fixup ();
prot_info_ptr = (LPWSAPROTOCOL_INFOA) cmalloc (HEAP_BUF, prot_info_ptr = (LPWSAPROTOCOL_INFOA) cmalloc (HEAP_BUF,

View File

@ -31,7 +31,7 @@ fhandler_termios::tcinit (tty_min *this_tc, bool force)
tc = this_tc; tc = this_tc;
if (force || !TTYISSETF (INITIALIZED)) if (force || !tc->is_initialized ())
{ {
tc->ti.c_iflag = BRKINT | ICRNL | IXON; tc->ti.c_iflag = BRKINT | ICRNL | IXON;
tc->ti.c_oflag = OPOST | ONLCR; tc->ti.c_oflag = OPOST | ONLCR;
@ -58,7 +58,7 @@ fhandler_termios::tcinit (tty_min *this_tc, bool force)
tc->ti.c_ispeed = tc->ti.c_ospeed = B38400; tc->ti.c_ispeed = tc->ti.c_ospeed = B38400;
tc->pgid = myself->pgid; tc->pgid = myself->pgid;
TTYSETF (INITIALIZED); tc->initialize ();
} }
} }

View File

@ -30,17 +30,6 @@ details. */
#include <sys/termios.h> #include <sys/termios.h>
enum
{
TTY_INITIALIZED = 1, /* Set if tty is initialized */
TTY_RSTCONS = 2 /* Set if console needs to be set to "non-cooked" */
};
#define TTYISSETF(x) __ISSETF (tc, x, TTY)
#define TTYSETF(x) __SETF (tc, x, TTY)
#define TTYCLEARF(x) __CLEARF (tc, x, TTY)
#define TTYCONDSETF(n, x) __CONDSETF(n, tc, x, TTY)
#ifndef MIN_CTRL_C_SLOP #ifndef MIN_CTRL_C_SLOP
#define MIN_CTRL_C_SLOP 50 #define MIN_CTRL_C_SLOP 50
#endif #endif
@ -48,13 +37,24 @@ enum
class tty_min class tty_min
{ {
pid_t sid; /* Session ID of tty */ pid_t sid; /* Session ID of tty */
struct status_flags
{
unsigned initialized : 1; /* Set if tty is initialized */
unsigned rstcons : 1; /* Set if console needs to be set to "non-cooked" */
} status;
public: public:
DWORD status;
pid_t pgid; pid_t pgid;
int output_stopped; int output_stopped;
int ntty; int ntty;
DWORD last_ctrl_c; // tick count of last ctrl-c DWORD last_ctrl_c; // tick count of last ctrl-c
void initialize () { status.initialized = 1; }
bool is_initialized () { return status.initialized; }
void set_rstcons () { status.rstcons = 1; }
void clear_rstcons () { status.rstcons = 1; }
bool needs_rstcons () { return status.rstcons; }
tty_min (int t = -1, pid_t s = -1) : sid (s), ntty (t) {} tty_min (int t = -1, pid_t s = -1) : sid (s), ntty (t) {}
void setntty (int n) {ntty = n;} void setntty (int n) {ntty = n;}
pid_t getpgid () {return pgid;} pid_t getpgid () {return pgid;}

View File

@ -131,16 +131,6 @@ extern int cygserver_running;
#define TITLESIZE 1024 #define TITLESIZE 1024
/* status bit manipulation */
#define __ISSETF(what, x, prefix) \
((what)->status & prefix##_##x)
#define __SETF(what, x, prefix) \
((what)->status |= prefix##_##x)
#define __CLEARF(what, x, prefix) \
((what)->status &= ~prefix##_##x)
#define __CONDSETF(n, what, x, prefix) \
((n) ? __SETF (what, x, prefix) : __CLEARF (what, x, prefix))
#include "debug.h" #include "debug.h"
/* Events/mutexes */ /* Events/mutexes */