From 56ae3a48afe13d364b5f01f89f99f8b0b176991b Mon Sep 17 00:00:00 2001 From: corinna Date: Fri, 9 Apr 2004 12:09:45 +0000 Subject: [PATCH] * 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. --- winsup/cygwin/ChangeLog | 22 ++++++++++++++++++++++ winsup/cygwin/fhandler.h | 37 +++++++++++++++++++++++-------------- winsup/cygwin/fhandler_console.cc | 10 ++++------ winsup/cygwin/fhandler_socket.cc | 4 +--- winsup/cygwin/fhandler_termios.cc | 4 ++-- winsup/cygwin/tty.h | 24 ++++++++++++------------ winsup/cygwin/winsup.h | 10 ---------- 7 files changed, 64 insertions(+), 47 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 35c176da72..ff8dfdccf7 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,27 @@ 2004-04-09 Corinna Vinschen + * 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 + * fhandler.cc (fhandler_base::write): Use bool parameter in calls to set_did_lseek. (fhandler_base::fhandler_base): Accomodate new status and open_status diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 13920559de..b889c84507 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -71,7 +71,6 @@ class fhandler_base friend class dtable; friend void close_all_files (); - protected: struct status_flags { unsigned rbinary : 1; /* binary read mode */ @@ -92,7 +91,7 @@ class fhandler_base unsigned close_on_exec : 1; /* close-on-exec */ unsigned need_fork_fixup : 1; /* Set if need to fixup after fork. */ - public: + public: status_flags () : rbinary (0), rbinset (0), wbinary (0), wbinset (0), no_handle (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; struct _WSAPROTOCOL_INFOA *prot_info_ptr; char *sun_path; - 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; + struct status_flags + { + 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: fhandler_socket (); @@ -365,20 +372,22 @@ class fhandler_socket: public fhandler_base int get_socket () { return (int) get_handle(); } fhandler_socket *is_socket () { return this; } - bool saw_shutdown_read () const {return sock_saw_shut_rd;} - bool saw_shutdown_write () const {return sock_saw_shut_wr;} + bool saw_shutdown_read () const { return status.sock_saw_shut_rd; } + bool saw_shutdown_write () const { return status.sock_saw_shut_wr; } - void set_shutdown_read () { sock_saw_shut_rd = 1;} - void set_shutdown_write () { sock_saw_shut_wr = 1;} + void set_shutdown_read () { status.sock_saw_shut_rd = 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 - { return had_connect_or_listen == connect_pending; } - bool is_connected () const { return had_connect_or_listen == connected; } + { return status.had_connect_or_listen == connect_pending; } + bool is_connected () const + { return status.had_connect_or_listen == connected; } void set_connect_state (connect_state newstate) - { had_connect_or_listen = newstate; } + { status.had_connect_or_listen = newstate; } 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 connect (const struct sockaddr *name, int namelen); diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index afac56c408..66d92f786e 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -154,10 +154,8 @@ set_console_state_for_spawn () if (shared_console_info != NULL) { /* 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); - TTYSETF (RSTCONS); -# undef tc + shared_console_info->tty_min_state.set_rstcons (); } CloseHandle (h); @@ -538,7 +536,7 @@ sig_exit: void fhandler_console::set_input_state () { - if (TTYISSETF (RSTCONS)) + if (tc->needs_rstcons ()) 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); } - TTYCLEARF (RSTCONS); + tc->clear_rstcons (); set_open_status (); 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); } - TTYCLEARF (RSTCONS); + tc->clear_rstcons (); return res; } diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index d322e9d460..4ce4abe7eb 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -124,9 +124,7 @@ get_inet_addr (const struct sockaddr *in, int inlen, fhandler_socket::fhandler_socket () : fhandler_base (), sun_path (NULL), - sock_saw_shut_rd (0), - sock_saw_shut_wr (0), - had_connect_or_listen (unconnected) + status () { set_need_fork_fixup (); prot_info_ptr = (LPWSAPROTOCOL_INFOA) cmalloc (HEAP_BUF, diff --git a/winsup/cygwin/fhandler_termios.cc b/winsup/cygwin/fhandler_termios.cc index ed8d3b27f3..636f7822ff 100644 --- a/winsup/cygwin/fhandler_termios.cc +++ b/winsup/cygwin/fhandler_termios.cc @@ -31,7 +31,7 @@ fhandler_termios::tcinit (tty_min *this_tc, bool force) tc = this_tc; - if (force || !TTYISSETF (INITIALIZED)) + if (force || !tc->is_initialized ()) { tc->ti.c_iflag = BRKINT | ICRNL | IXON; 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->pgid = myself->pgid; - TTYSETF (INITIALIZED); + tc->initialize (); } } diff --git a/winsup/cygwin/tty.h b/winsup/cygwin/tty.h index c5d01526f3..355e21b9a8 100644 --- a/winsup/cygwin/tty.h +++ b/winsup/cygwin/tty.h @@ -30,17 +30,6 @@ details. */ #include -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 #define MIN_CTRL_C_SLOP 50 #endif @@ -48,13 +37,24 @@ enum class tty_min { 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: - DWORD status; pid_t pgid; int output_stopped; int ntty; 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) {} void setntty (int n) {ntty = n;} pid_t getpgid () {return pgid;} diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h index a7e38d7724..3dbb3ce89d 100644 --- a/winsup/cygwin/winsup.h +++ b/winsup/cygwin/winsup.h @@ -131,16 +131,6 @@ extern int cygserver_running; #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" /* Events/mutexes */ -- 2.11.0