X-Git-Url: https://git.distorted.org.uk/~mdw/fwd/blobdiff_plain/e5398e091780133b1049bd87a75fbc299ed51749..00e3c0f1bbe99682debd4e34d3d3bd950f8c30cb:/chan.c diff --git a/chan.c b/chan.c index 855c769..ffec633 100644 --- a/chan.c +++ b/chan.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: chan.c,v 1.2 1999/07/26 23:27:52 mdw Exp $ + * $Id: chan.c,v 1.5 2000/07/19 17:55:43 mdw Exp $ * * Channel management * @@ -29,6 +29,17 @@ /*----- Revision history --------------------------------------------------* * * $Log: chan.c,v $ + * Revision 1.5 2000/07/19 17:55:43 mdw + * (writechan): Pointless tweak: when the buffer is empty, reset the start + * pointer to the beginning. This saves doing slightly trickier + * @writev(2)@ calls when loading is light. + * + * Revision 1.4 1999/08/31 17:42:49 mdw + * Use `sel_force' to avoid a `select' call between reads and writes. + * + * Revision 1.3 1999/07/27 18:30:53 mdw + * Various minor portability fixes. + * * Revision 1.2 1999/07/26 23:27:52 mdw * Minor modifications for new design. * @@ -51,10 +62,6 @@ #include #include -#include -#include -#include - #include #include #include @@ -117,8 +124,11 @@ static void writechan(int fd, unsigned mode, void *vp) /* --- Close the output end if necessary --- */ - if (c->len == 0 && (c->f & CHANF_CLOSE)) - c->func(c->p); + if (c->len == 0) { + c->base = 0; + if (c->f & CHANF_CLOSE) + c->func(c->p); + } return; /* --- Force a close if an error occurred --- */ @@ -168,8 +178,10 @@ static void readchan(int fd, unsigned mode, void *vp) } else if (r == 0) goto close; - else if (c->len == 0 && (c->f & CHANF_READY)) + else if (c->len == 0 && (c->f & CHANF_READY)) { sel_addfile(&c->w); + sel_force(&c->w); + } c->len += r; if (c->len == CHAN_BUFSZ) sel_rmfile(&c->r); @@ -179,8 +191,10 @@ static void readchan(int fd, unsigned mode, void *vp) close: c->f |= CHANF_CLOSE; - if (!c->len && (c->f & CHANF_READY)) + if (!c->len && (c->f & CHANF_READY)) { sel_addfile(&c->w); + sel_force(&c->w); + } sel_rmfile(&c->r); } @@ -217,8 +231,10 @@ void chan_dest(chan *c, int fd) if (c->f & CHANF_READY) return; sel_initfile(sel, &c->w, fd, SEL_WRITE, writechan, c); - if (c->len || (c->f & CHANF_CLOSE)) + if (c->len || (c->f & CHANF_CLOSE)) { sel_addfile(&c->w); + sel_force(&c->w); + } c->f |= CHANF_READY; }