This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
more robust tty_list::allocate_tty
- From: "Chris January" <ccj00 at doc dot ic dot ac dot uk>
- To: <cygwin at cygwin dot com>
- Date: Fri, 30 Aug 2002 15:40:10 -0000
- Subject: more robust tty_list::allocate_tty
- Reply-to: chris at atomice dot net
This was destined for the cygwin-patches@cygwin.com, but I can't post to
that list because I'm not subscribed from this address (and the webmail
interface I'm using doesn't allow you to change the From: header address).
Please treat as if posted to cygwin-patches. Thanks.
> > This small patch makes tty_list::allocate_tty more robust. On Windows
2000
> > and Windows XP it calls the new API function GetConsoleWindow. On other
> > platforms I've added a loop round FindWindow for cases where the system
is
> > heavily loaded and the console title doesn't change in time. (I've
> submitted
> > a patch for the latter change before).
> >
> > Chris
> >
> > ---
> >
> > 2002-08-30 Christopher January <chris@atomice.net>
> >
> > * tty.cc (tty_list::allocate_tty): Use GetConsoleWindow on Windows
> > 2000 / XP. Call FindWindow in a loop.
> > * wincap.cc: Set flag has_get_console_window appropriately.
> > * wincap.h: Add flag has_get_console_window.
> >
> > 2002-08-30 Christopher January <chris@atomice.net>
> > * wincon.h: Add declaration for GetConsoleWindow.
> >
> > ---
> >
> > Index: cygwin/tty.cc
> > ===================================================================
> > RCS file: /cvs/src/src/winsup/cygwin/tty.cc,v
> > retrieving revision 1.40
> > diff -u -p -r1.40 tty.cc
> > --- cygwin/tty.cc 2 Aug 2002 02:10:24 -0000 1.40
> > +++ cygwin/tty.cc 30 Aug 2002 15:26:21 -0000
> > @@ -196,6 +196,8 @@ tty_list::allocate_tty (int with_console
> >
> > if (!with_console)
> > console = NULL;
> > + else if (wincap.has_get_console_window())
> > + console = GetConsoleWindow ();
> > else
> > {
> > char *oldtitle = new char [TITLESIZE];
> > @@ -218,8 +220,11 @@ tty_list::allocate_tty (int with_console
> >
> > __small_sprintf (buf, "cygwin.find.console.%d", myself->pid);
> > SetConsoleTitle (buf);
> > - Sleep (40);
> > - console = FindWindow (NULL, buf);
> > + for (int times = 0; times < 25 && console == NULL; times++)
> > + {
> > + Sleep (40);
> > + console = FindWindow (NULL, buf);
> > + }
> > SetConsoleTitle (oldtitle);
> > Sleep (40);
> > ReleaseMutex (title_mutex);
> > Index: cygwin/wincap.cc
> > ===================================================================
> > RCS file: /cvs/src/src/winsup/cygwin/wincap.cc,v
> > retrieving revision 1.16
> > diff -u -p -r1.16 wincap.cc
> > --- cygwin/wincap.cc 24 Jul 2002 11:01:37 -0000 1.16
> > +++ cygwin/wincap.cc 30 Aug 2002 15:26:23 -0000
> > @@ -47,6 +47,7 @@ static NO_COPY wincaps wincap_unknown =
> > has_64bit_file_access:false,
> > has_process_io_counters:false,
> > supports_reading_modem_output_lines:false,
> > + has_get_console_window:false,
> > };
> >
> > static NO_COPY wincaps wincap_95 = {
> > @@ -85,6 +86,7 @@ static NO_COPY wincaps wincap_95 = {
> > has_64bit_file_access:false,
> > has_process_io_counters:false,
> > supports_reading_modem_output_lines:false,
> > + has_get_console_window:false,
> > };
> >
> > static NO_COPY wincaps wincap_95osr2 = {
> > @@ -123,6 +125,7 @@ static NO_COPY wincaps wincap_95osr2 = {
> > has_64bit_file_access:false,
> > has_process_io_counters:false,
> > supports_reading_modem_output_lines:false,
> > + has_get_console_window:false,
> > };
> >
> > static NO_COPY wincaps wincap_98 = {
> > @@ -161,6 +164,7 @@ static NO_COPY wincaps wincap_98 = {
> > has_64bit_file_access:false,
> > has_process_io_counters:false,
> > supports_reading_modem_output_lines:false,
> > + has_get_console_window:false,
> > };
> >
> > static NO_COPY wincaps wincap_98se = {
> > @@ -199,6 +203,7 @@ static NO_COPY wincaps wincap_98se = {
> > has_64bit_file_access:false,
> > has_process_io_counters:false,
> > supports_reading_modem_output_lines:false,
> > + has_get_console_window:false,
> > };
> >
> > static NO_COPY wincaps wincap_me = {
> > @@ -237,6 +242,7 @@ static NO_COPY wincaps wincap_me = {
> > has_64bit_file_access:false,
> > has_process_io_counters:false,
> > supports_reading_modem_output_lines:false,
> > + has_get_console_window:false,
> > };
> >
> > static NO_COPY wincaps wincap_nt3 = {
> > @@ -275,6 +281,7 @@ static NO_COPY wincaps wincap_nt3 = {
> > has_64bit_file_access:true,
> > has_process_io_counters:false,
> > supports_reading_modem_output_lines:true,
> > + has_get_console_window:false,
> > };
> >
> > static NO_COPY wincaps wincap_nt4 = {
> > @@ -313,6 +320,7 @@ static NO_COPY wincaps wincap_nt4 = {
> > has_64bit_file_access:true,
> > has_process_io_counters:false,
> > supports_reading_modem_output_lines:true,
> > + has_get_console_window:false,
> > };
> >
> > static NO_COPY wincaps wincap_nt4sp4 = {
> > @@ -351,6 +359,7 @@ static NO_COPY wincaps wincap_nt4sp4 = {
> > has_64bit_file_access:true,
> > has_process_io_counters:false,
> > supports_reading_modem_output_lines:true,
> > + has_get_console_window:false,
> > };
> >
> > static NO_COPY wincaps wincap_2000 = {
> > @@ -389,6 +398,7 @@ static NO_COPY wincaps wincap_2000 = {
> > has_64bit_file_access:true,
> > has_process_io_counters:true,
> > supports_reading_modem_output_lines:true,
> > + has_get_console_window:true,
> > };
> >
> > static NO_COPY wincaps wincap_xp = {
> > @@ -427,6 +437,7 @@ static NO_COPY wincaps wincap_xp = {
> > has_64bit_file_access:true,
> > has_process_io_counters:true,
> > supports_reading_modem_output_lines:true,
> > + has_get_console_window:true,
> > };
> >
> > wincapc wincap;
> > Index: cygwin/wincap.h
> > ===================================================================
> > RCS file: /cvs/src/src/winsup/cygwin/wincap.h,v
> > retrieving revision 1.13
> > diff -u -p -r1.13 wincap.h
> > --- cygwin/wincap.h 24 Jul 2002 11:01:37 -0000 1.13
> > +++ cygwin/wincap.h 30 Aug 2002 15:26:23 -0000
> > @@ -48,6 +48,7 @@ struct wincaps
> > unsigned has_64bit_file_access : 1;
> > unsigned has_process_io_counters : 1;
> > unsigned supports_reading_modem_output_lines : 1;
> > + unsigned has_get_console_window
> > : 1;
> > };
> >
> > class wincapc
> > @@ -100,6 +101,7 @@ public:
> > bool IMPLEMENT (has_64bit_file_access)
> > bool IMPLEMENT (has_process_io_counters)
> > bool IMPLEMENT (supports_reading_modem_output_lines)
> > + bool IMPLEMENT (has_get_console_window)
> >
> > #undef IMPLEMENT
> > };
> > Index: w32api/include/wincon.h
> > ===================================================================
> > RCS file: /cvs/src/src/winsup/w32api/include/wincon.h,v
> > retrieving revision 1.3
> > diff -u -p -r1.3 wincon.h
> > --- w32api/include/wincon.h 19 Jun 2002 01:15:45 -0000 1.3
> > +++ w32api/include/wincon.h 30 Aug 2002 15:26:30 -0000
> > @@ -90,7 +90,7 @@ typedef struct _KEY_EVENT_RECORD {
> > CHAR AsciiChar;
> > } uChar;
> > DWORD dwControlKeyState;
> > -}
> > +}
> > #ifdef __GNUC__
> > /* gcc's alignment is not what win32 expects */
> > PACKED
> > @@ -146,6 +146,7 @@ BOOL WINAPI ReadConsoleOutputCharacterA(
> > BOOL WINAPI ReadConsoleOutputCharacterW
(HANDLE,LPWSTR,DWORD,COORD,PDWORD);
> > BOOL WINAPI ReadConsoleOutputA
(HANDLE,PCHAR_INFO,COORD,COORD,PSMALL_RECT);
> > BOOL WINAPI ReadConsoleOutputW
(HANDLE,PCHAR_INFO,COORD,COORD,PSMALL_RECT);
> > +HWND WINAPI GetConsoleWindow(void);
> > BOOL WINAPI ScrollConsoleScreenBufferA(HANDLE,const SMALL_RECT*,const
> > SMALL_RECT*,COORD,const CHAR_INFO*);
> > BOOL WINAPI ScrollConsoleScreenBufferW(HANDLE,const SMALL_RECT*,const
> > SMALL_RECT*,COORD,const CHAR_INFO*);
> > BOOL WINAPI SetConsoleActiveScreenBuffer(HANDLE);
> >
> >
>
>
--