Add code to periodically transmit something to the X server, so that
authorChris Hanson <org/chris-hanson/cph>
Tue, 18 Aug 1992 03:25:27 +0000 (03:25 +0000)
committerChris Hanson <org/chris-hanson/cph>
Tue, 18 Aug 1992 03:25:27 +0000 (03:25 +0000)
if the connection dies an error will be signalled to Scheme.

v7/src/microcode/x11.h
v7/src/microcode/x11base.c

index 5e3f719fac85fed3df059b18f0c1579b0957f8ab..3107791fc2ed9c34e04479be8bd2d7d7258d1131 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/x11.h,v 1.13 1992/02/11 18:57:46 cph Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/x11.h,v 1.14 1992/08/18 03:25:26 cph Exp $
 
 Copyright (c) 1989-92 Massachusetts Institute of Technology
 
@@ -43,6 +43,7 @@ struct xdisplay
 {
   unsigned int allocation_index;
   Display * display;
+  unsigned int server_ping_timer;
   Atom wm_protocols;
   Atom wm_delete_window;
   Atom wm_take_focus;
@@ -52,6 +53,7 @@ struct xdisplay
 
 #define XD_ALLOCATION_INDEX(xd) ((xd) -> allocation_index)
 #define XD_DISPLAY(xd) ((xd) -> display)
+#define XD_SERVER_PING_TIMER(xd) ((xd) -> server_ping_timer)
 #define XD_WM_PROTOCOLS(xd) ((xd) -> wm_protocols)
 #define XD_WM_DELETE_WINDOW(xd) ((xd) -> wm_delete_window)
 #define XD_WM_TAKE_FOCUS(xd) ((xd) -> wm_take_focus)
index 95a2346fbefebea58d42b6066310732c66de5aa6..837dcc966c72f4e426c0d5b41f7c34a6472b55b2 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/x11base.c,v 1.40 1992/05/21 22:13:20 cph Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/x11base.c,v 1.41 1992/08/18 03:25:27 cph Exp $
 
 Copyright (c) 1989-92 Massachusetts Institute of Technology
 
@@ -1059,6 +1059,22 @@ DEFUN (update_input_mask, (xw), struct xwindow * xw)
   }
 }
 
+static void
+DEFUN (ping_server, (xd), struct xdisplay * xd)
+{
+  /* Periodically ping the server connection to see if it has
+     died.  If it has died, this will force an error to be signalled
+     to Scheme; we expect Scheme to handle the error in some
+     reasonable way.  */
+  (XD_SERVER_PING_TIMER (xd)) += 1;
+  if ((XD_SERVER_PING_TIMER (xd)) >= 100)
+    {
+      (XD_SERVER_PING_TIMER (xd)) = 0;
+      XNoOp (XD_DISPLAY (xd));
+      XFlush (XD_DISPLAY (xd));
+    }
+}
+
 /* The use of `XD_CACHED_EVENT' prevents an event from being lost due
    to garbage collection.  First `XD_CACHED_EVENT' is set to hold the
    current event, then the allocations are performed.  If one of them
@@ -1082,33 +1098,43 @@ DEFUN (xd_process_events, (xd, non_block_p, use_select_p),
       events_queued = (XEventsQueued (display, QueuedAlready));
       goto restart;
     }
-  events_queued =
-    (use_select_p ? (XEventsQueued (display, QueuedAlready))
-     : non_block_p ? (XEventsQueued (display, QueuedAfterReading))
-     : 0);
+  if (use_select_p)
+    events_queued = (XEventsQueued (display, QueuedAlready));
+  else if (non_block_p)
+    {
+      ping_server (xd);
+      events_queued = (XEventsQueued (display, QueuedAfterReading));
+    }
+  else
+    events_queued = 0;
   while (1)
     {
       XEvent event;
       if (events_queued > 0)
        events_queued -= 1;
-      else if (use_select_p)
-       switch (UX_select_input ((ConnectionNumber (display)),
-                                (!non_block_p)))
-         {
-         case select_input_none:
+      else
+       {
+         if (use_select_p)
+           switch (UX_select_input ((ConnectionNumber (display)),
+                                    (!non_block_p)))
+             {
+             case select_input_none:
+               return (SHARP_F);
+             case select_input_other:
+               return (LONG_TO_FIXNUM (-2));
+             case select_input_process_status:
+               return (LONG_TO_FIXNUM (-3));
+             case select_input_interrupt:
+               return (LONG_TO_FIXNUM (-4));
+             case select_input_argument:
+               ping_server (xd);
+               events_queued = (XEventsQueued (display, QueuedAfterReading));
+               continue;
+             }
+         else if (non_block_p)
            return (SHARP_F);
-         case select_input_other:
-           return (LONG_TO_FIXNUM (-2));
-         case select_input_process_status:
-           return (LONG_TO_FIXNUM (-3));
-         case select_input_interrupt:
-           return (LONG_TO_FIXNUM (-4));
-         case select_input_argument:
-           events_queued = (XEventsQueued (display, QueuedAfterReading));
-           continue;
-         }
-      else if (non_block_p)
-       return (SHARP_F);
+         ping_server (xd);
+       }
       XNextEvent (display, (&event));
       if ((event . type) == KeymapNotify)
        continue;
@@ -1166,6 +1192,7 @@ DEFINE_PRIMITIVE ("X-OPEN-DISPLAY", Prim_x_open_display, 1, 1, 0)
       }
     (XD_ALLOCATION_INDEX (xd)) =
       (allocate_table_index ((&x_display_table), xd));
+    (XD_SERVER_PING_TIMER (xd)) = 0;
     (XD_WM_PROTOCOLS (xd)) =
       (XInternAtom ((XD_DISPLAY (xd)), "WM_PROTOCOLS", False));
     (XD_WM_DELETE_WINDOW (xd)) =