🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #99859

Re: y-or-n-p uninterruptability

#99859
From: Piet van Oostrum
Date: Mon, 23 Apr 1990 15:25
125 lines
4484 bytes
In article <3071@ruuinf.cs.ruu.nl>, piet@cs (Piet van Oostrum) writes:
 `
 `The problem is that on HP/UX FIONREAD and SIGIO do not work on sockets.
 `They only work on terminals. This also causes the problem of ^G not
 `interrupting long commands.

This means if you run emacs under X11.

 `
 `Here is a patch that solves the first problem, not the second. I am trying
 `a patch for the second problem next week (unless someone sends me a
 `solution before that).
 `
Here is the promised patch. If you install that, together with the prvious
one, ^G will now correctly interrupt under all circumstances. An additional
effect is that your emacs window will be properly repainted during a long
command. The way I did it was to have a one second interval timer running
while emacs is not reading input. This timer causes the input queue to be
emptied and ^G characters to be trapped. This is only done while reading
from a socket. If emacs is reading from a terminal, the normal interrupt
processing will handle the ^G's.

I don't know if some bizarre problem might pop up. I have been running all
day with the new code, reading news, mail, editing, grep etc. without any
surprises. 

Here is the patch:

*** keyboard.c.~3~	Fri Apr 20 20:28:53 1990
--- keyboard.c	Mon Apr 23 11:57:21 1990
***************
*** 719,724 ****
--- 719,772 ----
    errno = old_errno;
  }
  
+ #ifdef HPUX
+ /* tells if an alarm is outstanding for emptying the socket */
+ int socket_alarm;
+ 
+ static void
+ empty_socket_interrupt()
+ {
+   int nread;
+   char buf[256 * BUFFER_SIZE_FACTOR];
+   register int i;
+   int old_errno = errno;
+ 
+   if (waiting_for_input) return;
+ 
+   fcntl (fileno (stdin), F_SETFL, O_NDELAY);
+ 
+   /* Read what is waiting.  */
+ 
+     nread = (*read_socket_hook) (0, buf, sizeof buf);
+ 
+ #ifdef EBADSLT
+   if (nread == -1 && (errno == EAGAIN || errno == EBADSLT))
+ #else
+   if (nread == -1 && errno == EAGAIN)
+ #endif
+     nread = 0;
+ 
+   fcntl (fileno (stdin), F_SETFL, 0);
+ 
+   /* Scan the chars for C-g and store them in kbd_buffer.  */
+   kbd_ptr = kbd_buffer;
+   for (i = 0; i < nread; i++)
+     {
+       kbd_buffer_store_char (buf[i]);
+       /* Don't look at input that follows a C-g too closely.
+ 	 This reduces lossage due to autorepeat on C-g.  */
+       if (buf[i] == Ctl ('G'))
+ 	break;
+     }
+   errno = old_errno;
+ 
+   /* reestablish interrupt */
+   signal (SIGALRM, empty_socket_interrupt);
+   alarm (1);
+ }
+ 
+ #endif /* HPUX */
+ 
  /* read a character from the keyboard; call the redisplay if needed */
  /* commandflag 0 means do not do auto-saving, but do do redisplay.
     -1 means do not do redisplay, but do do autosaving.
***************
*** 733,738 ****
--- 781,793 ----
    Lisp_Object tem;
    extern request_echo ();
  
+ #ifdef HPUX
+   if (socket_alarm) {
+       alarm (0);
+       socket_alarm = 0;
+   }      
+ #endif
+ 
    if ((c = unread_command_char) >= 0)
      {
        unread_command_char = -1;
***************
*** 868,873 ****
--- 923,936 ----
  	  c = get_char (0);
  	}
      }
+ 
+ #ifdef HPUX
+   if (read_socket_hook) {
+       socket_alarm = 1;
+       signal (SIGALRM, empty_socket_interrupt);
+       alarm (1);
+   }      
+ #endif
  
    return c;
  }
-- 
Piet* van Oostrum, Dept of Computer Science, Utrecht University,
Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands.
Telephone: +31-30-531806   Uucp:   uunet!mcsun!ruuinf!piet
Telefax:   +31-30-513791   Internet:  piet@cs.ruu.nl   (*`Pete')
Technical Details
Message-ID: <3083@ruuinf.cs.ruu.nl>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!hp4nl!ruuinf!piet
References: <9004191448.AA05516@mururoa.imag.fr> <3071@ruuinf.cs.ruu.nl>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 114b0c,5e5f32750e03276b,start
X-Google-Attributes: gid114b0c,public
X-Google-Thread: fb2f1,4d6d9c470b07dc13
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1990-04-23 23:04:47 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!hp4nl!ruuinf!piet
From: piet@cs.ruu.nl (Piet van Oostrum)
Newsgroups: gnu.emacs.bug,comp.sys.hp
Subject: Re: y-or-n-p uninterruptability
Message-ID: <3083@ruuinf.cs.ruu.nl>
Date: 23 Apr 90 15:25:45 GMT
References: <9004191448.AA05516@mururoa.imag.fr> <3071@ruuinf.cs.ruu.nl>
Sender: news@ruuinf.cs.ruu.nl
Reply-To: piet@cs.ruu.nl (Piet van Oostrum)
Followup-To: gnu.emacs.bug
Distribution: gnu
Organization: Dept of Computer Science, Utrecht University, The Netherlands
Lines: 125
Posted: Mon Apr 23 16:25:45 1990
In-reply-to: piet@cs.ruu.nl (Piet van Oostrum)