*** empty log message ***
authorpcg <pcg>
Wed, 26 Nov 2003 10:42:34 +0000 (10:42 +0000)
committerpcg <pcg>
Wed, 26 Nov 2003 10:42:34 +0000 (10:42 +0000)
src/Makefile.in
src/command.C
src/init.C
src/iom.C
src/iom.h
src/main.C
src/rxvt.h

index 660c5eb..07254cc 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: Makefile.in,v 1.3 2003-11-25 11:52:42 pcg Exp $
+# $Id: Makefile.in,v 1.4 2003-11-26 10:42:34 pcg Exp $
 @MCOMMON@
 
 LINT = lint -DNARROWPROTO=1 $(XINC) -chapbxz
@@ -183,7 +183,6 @@ distcopy: .protos $(INTPROS)
 
 defaultfont.h: encoding.h rxvtvec.h
 rxvtlib.h: rxvtcolor.h defaultfont.h
-iom.o:              iom.C              iom.h
 rxvtdaemon.o:       rxvtdaemon.C       rxvtdaemon.h
 rxvtd.o:            rxvtd.C     $(DEPS) rxvtdaemon.h rxvtvec.h
 rxvtc.o:            rxvtc.C     $(DEPS) rxvtdaemon.h rxvtvec.h
@@ -210,6 +209,7 @@ xdefaults.o:        xdefaults.C $(DEPS) xdefaults.intpro      version.h
 xpm.o:              xpm.C       $(DEPS) xpm.intpro
 encoding.o:         encoding.C $(DEPS) encoding.h
 rxvtcolor.o:        rxvtcolor.C        $(DEPS)
+iom.o:              iom.C      $(DEPS) iom.h
 
 command.lo:         command.C   $(DEPS) command.intpro command.h version.h
 defaultfont.lo:     defaultfont.C $(DEPS) defaultfont.intpro defaultfont.h encoding.h
@@ -233,5 +233,6 @@ xdefaults.lo:       xdefaults.C $(DEPS) xdefaults.intpro      version.h
 xpm.lo:             xpm.C       $(DEPS) xpm.intpro
 encoding.lo:        encoding.C $(DEPS) encoding.h
 rxvtcolor.lo:       rxvtcolor.C        $(DEPS)
+iom.lo:             iom.C      $(DEPS) iom.h
 
 
index 0aa8365..9f8edeb 100644 (file)
@@ -1,7 +1,7 @@
 /*--------------------------------*-C-*---------------------------------*
  * File:       command.c
  *----------------------------------------------------------------------*
- * $Id: command.C,v 1.7 2003-11-25 17:34:47 pcg Exp $
+ * $Id: command.C,v 1.8 2003-11-26 10:42:34 pcg Exp $
  *
  * All portions of code are copyright by their respective author/s.
  * Copyright (c) 1992      John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
@@ -709,7 +709,7 @@ rxvt_term::blink_cb (time_watcher &w)
   w.at += BLINK_INTERVAL;
   hidden_cursor = !hidden_cursor;
   want_refresh = 1;
-  flush();
+  flush ();
 }
 
 void
@@ -776,7 +776,7 @@ rxvt_term::next_char ()
 }
 
 bool
-rxvt_term::pty_fill (size_t count)
+rxvt_term::pty_fill ()
 {
   ssize_t n = cmdbuf_endp - cmdbuf_ptr;
 
@@ -784,7 +784,7 @@ rxvt_term::pty_fill (size_t count)
   cmdbuf_ptr = cmdbuf_base;
   cmdbuf_endp = cmdbuf_ptr + n;
  
-  n = read (cmd_fd, cmdbuf_endp, count);
+  n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n);
 
   if (n > 0)
     {
@@ -794,15 +794,18 @@ rxvt_term::pty_fill (size_t count)
   else if (n < 0 && errno == EAGAIN)
     return false;
 
-  rxvt_clean_exit();
-  exit(EXIT_FAILURE);  /* bad order of events? */
+  rxvt_clean_exit ();
+  exit (EXIT_FAILURE); /* bad order of events? */
 }
 
 void
 rxvt_term::pty_cb (io_watcher &w, short revents)
 {
-  while (pty_fill (BUFSIZ - (cmdbuf_endp - cmdbuf_ptr)))
+  // loop, but don't allow a single term to monopolize us
+  // the number of loops is fully arbitrary, and thus wrong
+  for (int i = 7; i-- && pty_fill (); )
     {
+      //TODO:
       /* once we know the shell is running, send the screen size.  Again! */
       //ch = rxvt_cmd_getc(aR);        /* wait for something */
       //rxvt_tt_winsize(cmd_fd, TermWin.ncol, TermWin.nrow, cmd_pid);
@@ -923,7 +926,9 @@ rxvt_term::flush ()
 #endif
     }
 
+  if (XPending (Xdisplay)) process_x_events ();
   XFlush (Xdisplay);
+  if (XPending (Xdisplay)) process_x_events ();
 }
 
 /* rxvt_cmd_getc() - Return next input character */
@@ -944,7 +949,7 @@ rxvt_cmd_getc(pR)
       // incomplete sequences should occur rarely, still, a better solution
       // would be preferred. either setjmp/longjmp or better design.
       fcntl (R->cmd_fd, F_SETFL, 0);
-      R->pty_fill (1);
+      R->pty_fill ();
       fcntl (R->cmd_fd, F_SETFL, O_NONBLOCK);
     }
 
@@ -1291,17 +1296,18 @@ rxvt_process_x_event(pR_ XEvent *ev)
      * which ought to make things real slow!
      */
     case VisibilityNotify:
-       switch (ev->xvisibility.state) {
-       case VisibilityUnobscured:
-           R->refresh_type = FAST_REFRESH;
-           break;
-       case VisibilityPartiallyObscured:
-           R->refresh_type = SLOW_REFRESH;
-           break;
-       default:
-           R->refresh_type = NO_REFRESH;
-           break;
-       }
+       switch (ev->xvisibility.state)
+          {
+            case VisibilityUnobscured:
+              R->refresh_type = FAST_REFRESH;
+              break;
+            case VisibilityPartiallyObscured:
+              R->refresh_type = SLOW_REFRESH;
+              break;
+            default:
+              R->refresh_type = NO_REFRESH;
+              break;
+          }
        break;
 
     case FocusIn:
index 520730d..5df0f07 100644 (file)
@@ -1,7 +1,7 @@
 /*--------------------------------*-C-*---------------------------------*
  * File:        init.c
  *----------------------------------------------------------------------*
- * $Id: init.C,v 1.6 2003-11-25 17:11:33 pcg Exp $
+ * $Id: init.C,v 1.7 2003-11-26 10:42:34 pcg Exp $
  *
  * All portions of code are copyright by their respective author/s.
  * Copyright (c) 1992      John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
@@ -475,6 +475,7 @@ rxvt_init_secondary(pR)
         close(i);
     }
     dup2(STDERR_FILENO, STDOUT_FILENO);
+#if 0 // schmorp sayz closing filies is murder
     for (i = STDERR_FILENO + 1; i < R->num_fds; i++) {
 #ifdef __sgi                    /* Alex Coventry says we need 4 & 7 too */
         if (i == 4 || i == 7)
@@ -482,6 +483,7 @@ rxvt_init_secondary(pR)
 #endif
         close(i);
     }
+#endif
 }
 
 /*----------------------------------------------------------------------*/
index 7f09395..3b2e86a 100644 (file)
--- a/src/iom.C
+++ b/src/iom.C
@@ -30,6 +30,39 @@ tstamp NOW;
 bool iom_valid;
 io_manager iom;
 
+template<class watcher>
+void io_manager::reg (watcher *w, simplevec<watcher *> &queue)
+{
+  if (find (queue.begin (), queue.end (), w) == queue.end ())
+    queue.push_back (w);
+}
+
+template<class watcher>
+void io_manager::unreg (watcher *w, simplevec<watcher *> &queue)
+{
+  queue.erase (find (queue.begin (), queue.end (), w));
+}
+
+#if IOM_IO
+io_watcher::~io_watcher ()
+{
+  if (iom_valid)
+    iom.unreg (this);
+}
+
+void io_manager::reg (io_watcher *w)
+{
+  reg (w, iow);
+}
+
+void io_manager::unreg (io_watcher *w)
+{
+  unreg (w, iow);
+}
+
+#endif
+
+#if IOM_TIME
 void time_watcher::trigger ()
 {
   call (*this);
@@ -45,34 +78,36 @@ time_watcher::~time_watcher ()
   at = TSTAMP_CANCEL;
 }
 
-io_watcher::~io_watcher ()
+void io_manager::reg (time_watcher *w)
 {
-  if (iom_valid)
-    iom.unreg (this);
+  reg (w, tw);
 }
 
-void io_manager::reg (io_watcher *w)
+void io_manager::unreg (time_watcher *w)
 {
-  if (find (iow.begin (), iow.end (), w) == iow.end ())
-    iow.push_back (w);
+  unreg (w, tw);
 }
+#endif
 
-void io_manager::unreg (io_watcher *w)
+#if IOM_CHECK
+check_watcher::~check_watcher ()
 {
-  iow.erase (find (iow.begin (), iow.end (), w));
+  if (iom_valid)
+    iom.unreg (this);
 }
 
-void io_manager::reg (time_watcher *w)
+void io_manager::reg (check_watcher *w)
 {
-  if (find (tw.begin (), tw.end (), w) == tw.end ())
-    tw.push_back (w);
+  reg (w, cw);
 }
 
-void io_manager::unreg (time_watcher *w)
+void io_manager::unreg (check_watcher *w)
 {
-  tw.erase (find (tw.begin (), tw.end (), w));
+  unreg (w, cw);
 }
+#endif
 
+#if IOM_TIME
 inline void set_now (void)
 {
   struct timeval tv;
@@ -80,21 +115,30 @@ inline void set_now (void)
   gettimeofday (&tv, 0);
 
   NOW = (tstamp)tv.tv_sec + (tstamp)tv.tv_usec / 1000000;
+#endif
 }
 
 void io_manager::loop ()
 {
+#if IOM_TIME
   set_now ();
+#endif
 
   for (;;)
     {
+#if IOM_CHECK
+      for (int i = 0; i < cw.size (); ++i)
+        cw[i]->call (*cw[i]);
+#endif
+
+#if IOM_TIME
       time_watcher *w;
 
       for (;;)
         {
           w = tw[0];
 
-          for (time_watcher **i = tw.begin (); i != tw.end (); ++i)
+          for (time_watcher **i = tw.begin (); i < tw.end (); ++i)
             if ((*i)->at < w->at)
               w = *i;
 
@@ -108,11 +152,13 @@ void io_manager::loop ()
             unreg (w);
         }
 
-      struct timeval to;
       double diff = w->at - NOW;
+      struct timeval to;
       to.tv_sec  = (int)diff;
       to.tv_usec = (int)((diff - to.tv_sec) * 1000000);
+#endif
 
+#if IOM_IO
       fd_set rfd, wfd;
 
       FD_ZERO (&rfd);
@@ -128,22 +174,31 @@ void io_manager::loop ()
           if ((*w)->fd > fds) fds = (*w)->fd;
         }
 
+# if IOM_TIME
       fds = select (fds + 1, &rfd, &wfd, 0, &to);
-
       set_now ();
+# else
+      fds = select (fds + 1, &rfd, &wfd, 0, 0);
+# endif
 
       if (fds > 0)
-        for (io_watcher **w = iow.begin (); w < iow.end (); ++w)
+        for (int i = 0; i < iow.size (); ++i)
           {
-            short revents = (*w)->events;
+            io_watcher *w = iow[i];
 
-            if (!FD_ISSET ((*w)->fd, &rfd)) revents &= ~EVENT_READ;
-            if (!FD_ISSET ((*w)->fd, &wfd)) revents &= ~EVENT_WRITE;
+            short revents = w->events;
+
+            if (!FD_ISSET (w->fd, &rfd)) revents &= ~EVENT_READ;
+            if (!FD_ISSET (w->fd, &wfd)) revents &= ~EVENT_WRITE;
 
             if (revents)
-              (*w)->call (**w, revents);
+              w->call (*w, revents);
           }
     }
+#elif IOM_TIME
+      select (0, 0, 0, 0, &to);
+      set_now ();
+#endif
 }
 
 void io_manager::idle_cb (time_watcher &w)
@@ -157,8 +212,10 @@ io_manager::io_manager ()
 
   iom_valid = true;
 
+#if IOM_TIME
   idle = new time_watcher (this, &io_manager::idle_cb);
   idle->start (0);
+#endif
 }
 
 io_manager::~io_manager ()
index ce41c2f..ec381a8 100644 (file)
--- a/src/iom.h
+++ b/src/iom.h
 #include "rxvtvec.h"
 #include "callback.h"
 
-typedef double tstamp;
+#define IOM_IO 1
+#define IOM_TIME 1
+#undef IOM_CHECK
 
-extern tstamp NOW;
+#if IOM_IO
+  typedef double tstamp;
+  extern tstamp NOW;
 
-struct io_watcher;
-struct time_watcher;
+  struct io_watcher;
+#endif
+#if IOM_TIME
+  struct time_watcher;
+#endif
+#if IOM_CHECK
+  struct check_watcher;
+#endif
 
 class io_manager {
-  simplevec<io_watcher *> iow;
-  simplevec<time_watcher *> tw; // actually a heap
+#if IOM_IO
+  simplevec<io_watcher *>    iow;
+#endif
+#if IOM_CHECK
+  simplevec<check_watcher *> cw;
+#endif
+#if IOM_TIME
+  simplevec<time_watcher *>  tw;
 
   void idle_cb (time_watcher &w); time_watcher *idle;
+#endif
+
+  template<class watcher>
+  void reg (watcher *w, simplevec<watcher *> &queue);
+
+  template<class watcher>
+  void unreg (watcher *w, simplevec<watcher *> &queue);
+
 public:
   // register a watcher
-  void reg (io_watcher *w);
-  void unreg (io_watcher *w);
-  void reg (time_watcher *w);
-  void unreg (time_watcher *w);
+#if IOM_IO
+  void reg (io_watcher   *w);  void unreg (io_watcher   *w);
+#endif
+#if IOM_TIME
+  void reg (time_watcher *w);  void unreg (time_watcher *w);
+#endif
+#if IOM_CHECK
+  void reg (check_watcher *w); void unreg (check_watcher *w);
+#endif
   
   void loop ();
 
@@ -52,6 +81,7 @@ public:
 
 extern io_manager iom; // a singleton, together with it's construction/destruction problems.
 
+#if IOM_IO
 enum { EVENT_READ = 1, EVENT_WRITE = 2 };
 
 struct io_watcher : callback2<void, io_watcher &, short> {
@@ -71,8 +101,10 @@ struct io_watcher : callback2<void, io_watcher &, short> {
   void start (int fd_, short events_) { set (fd_, events_); iom.reg (this); }
   void stop () { iom.unreg (this); }
 };
+#endif
 
-#define TSTAMP_CANCEL -1.
+#if IOM_TIME
+enum { TSTAMP_CANCEL = -1 };
 
 struct time_watcher : callback1<void, time_watcher &> {
   tstamp at;
@@ -98,6 +130,22 @@ struct time_watcher : callback1<void, time_watcher &> {
       at = when;
     }
 };
+#endif
+
+#if IOM_CHECK
+// run before checking for new events
+struct check_watcher : callback1<void, check_watcher &> {
+  template<class O1, class O2>
+  check_watcher (O1 *object, void (O2::*method)(check_watcher &))
+    : callback1<void, check_watcher &>(object,method)
+    { }
+
+  ~check_watcher ();
+
+  void start () { iom.reg (this); }
+  void stop () { iom.unreg (this); }
+};
+#endif
 
 #endif
 
index c4e110e..ed0e6f6 100644 (file)
@@ -1,7 +1,7 @@
 /*--------------------------------*-C-*---------------------------------*
  * File:        main.c
  *----------------------------------------------------------------------*
- * $Id: main.C,v 1.6 2003-11-25 17:11:33 pcg Exp $
+ * $Id: main.C,v 1.7 2003-11-26 10:42:34 pcg Exp $
  *
  * All portions of code are copyright by their respective author/s.
  * Copyright (c) 1992      John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
@@ -164,6 +164,8 @@ rxvt_term::init (int argc, const char *const *argv)
   x_ev.start (Xfd, EVENT_READ);
   pty_ev.start (cmd_fd, EVENT_READ);
 
+  flush ();
+
   return true;
 }
 
index 0768bcb..9900f16 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rxvt.h,v 1.6 2003-11-25 17:11:33 pcg Exp $
+ * $Id: rxvt.h,v 1.7 2003-11-26 10:42:34 pcg Exp $
  */
 
 #ifndef _RXVT_H_                /* include once only */
@@ -1138,7 +1138,7 @@ struct rxvt_term : rxvt_vars {
 
   uint32_t next_char ();
 
-  bool pty_fill (size_t count);
+  bool pty_fill ();
   void process_x_events ();
 
   void *operator new (size_t s);