-# $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
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
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
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
/*--------------------------------*-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>
w.at += BLINK_INTERVAL;
hidden_cursor = !hidden_cursor;
want_refresh = 1;
- flush();
+ flush ();
}
void
}
bool
-rxvt_term::pty_fill (size_t count)
+rxvt_term::pty_fill ()
{
ssize_t n = cmdbuf_endp - cmdbuf_ptr;
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)
{
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);
#endif
}
+ if (XPending (Xdisplay)) process_x_events ();
XFlush (Xdisplay);
+ if (XPending (Xdisplay)) process_x_events ();
}
/* rxvt_cmd_getc() - Return next input character */
// 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);
}
* 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:
/*--------------------------------*-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>
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)
#endif
close(i);
}
+#endif
}
/*----------------------------------------------------------------------*/
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);
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;
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;
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);
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)
iom_valid = true;
+#if IOM_TIME
idle = new time_watcher (this, &io_manager::idle_cb);
idle->start (0);
+#endif
}
io_manager::~io_manager ()
#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 ();
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> {
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;
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
/*--------------------------------*-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>
x_ev.start (Xfd, EVENT_READ);
pty_ev.start (cmd_fd, EVENT_READ);
+ flush ();
+
return true;
}
/*
- * $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 */
uint32_t next_char ();
- bool pty_fill (size_t count);
+ bool pty_fill ();
void process_x_events ();
void *operator new (size_t s);