delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1998/02/17/09:05:36

From: ian AT cygnus DOT com (Ian Lance Taylor)
Subject: Re: tty.cc fix.
17 Feb 1998 09:05:36 -0800 :
Message-ID: <199802171644.LAA25421.cygnus.cygwin32.developers@subrogation.cygnus.com>
References: <01BD3B8C DOT 312265C0 AT gater DOT krystalbank DOT msk DOT ru>
Reply-To: cygwin32-developers AT cygnus DOT com
To: sos AT prospect DOT com DOT ru
Cc: cygwin32-developers AT cygnus DOT com

   From: Sergey Okhapkin <sos AT prospect DOT com DOT ru>
   Date: Tue, 17 Feb 1998 10:09:51 +0300

   Ian Lance Taylor wrote:
   > I guess I don't understand this.  I thought it was already safe for
   > the master to open and close the tty slave, particularly with the
   > patch I checked in a few days ago.  Can you give an example of a
   > program which fails without this patch?

   Rxvt-2.20 terminal emulator, Xemacs.

Sorry, I was not clear.  What I meant was a small program, like the
one I sent.  Tracking down and building rxvt or xemacs would be far
more work than I care to put into cygwin32.  (I only got involved
because Geoff asked me to see what was involved in getting expect to
work, so that the dejagnu testsuite harness will run on cygwin32.)

   > I've appended one simple pty testing program I use.  It works on Unix,
   > and needs to continue to work on cygwin32.  When it works, it should
   > print the output of stty.

   Your program hangs in parent's read with this patch. I know the difference 
   now - both rxvt and Xemacs sets pty master handle to non-blocking.

My program doesn't hang, at least not for me.  I test every change to
the pty handling using it and using the expect testsuite.  Where does
it hang for you, and why?

The appended patch ought to make the pty master handle non blocking
reads better.

Ian

Index: tty.cc
===================================================================
RCS file: /cvs/cvsfiles/devo/winsup/tty.cc,v
retrieving revision 1.6.8.1.4.12
diff -u -r1.6.8.1.4.12 tty.cc
--- tty.cc	1998/02/16 20:45:06	1.6.8.1.4.12
+++ tty.cc	1998/02/17 16:41:38
@@ -1593,11 +1593,10 @@
 int
 fhandler_pty_master::read (void *ptr, size_t len)
 {
-  int n;
+  DWORD n;
   char *cptr = (char *) ptr;
 
-  if (PeekNamedPipe (get_handle (), NULL, 0, NULL, (unsigned *) &n, NULL)
-      == FALSE)
+  if (! PeekNamedPipe (get_handle (), NULL, 0, NULL, &n, NULL))
     {
       if (GetLastError () == ERROR_BROKEN_PIPE)
 	{
@@ -1605,6 +1604,12 @@
 	  return 0;
 	}
       __seterrno ();
+      return -1;
+    }
+  if (n == 0
+      && (get_flags () & (O_NONBLOCK | O_NDELAY)) != 0)
+    {
+      set_errno (EAGAIN);
       return -1;
     }
   if (pktmode)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019