X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/97f65b001294338abed02a7b132d6be6517b3f1d..ae24fcf7280adc70cdc1d3dfab9d93c13b156860:/selbuf.c diff --git a/selbuf.c b/selbuf.c index 0f07dfc..b8b1161 100644 --- a/selbuf.c +++ b/selbuf.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: selbuf.c,v 1.1 1999/05/14 21:01:15 mdw Exp $ + * $Id: selbuf.c,v 1.3 1999/05/22 13:41:00 mdw Exp $ * * Line-buffering select handler * @@ -30,6 +30,12 @@ /*----- Revision history --------------------------------------------------* * * $Log: selbuf.c,v $ + * Revision 1.3 1999/05/22 13:41:00 mdw + * Fix end-of-file detection and error handling. + * + * Revision 1.2 1999/05/17 20:36:50 mdw + * Make the magical constants for the buffer flags uppercase. + * * Revision 1.1 1999/05/14 21:01:15 mdw * Integrated `select' handling bits from the background resolver project. * @@ -64,8 +70,8 @@ void selbuf_enable(selbuf *b) { - if (!(b->b.f & lbuf_enable)) { - b->b.f |= lbuf_enable; + if (!(b->b.f & LBUF_ENABLE)) { + b->b.f |= LBUF_ENABLE; sel_addfile(&b->reader); lbuf_flush(&b->b, 0, 0); } @@ -83,8 +89,8 @@ void selbuf_enable(selbuf *b) void selbuf_disable(selbuf *b) { - if (b->b.f & lbuf_enable) { - b->b.f &= ~lbuf_enable; + if (b->b.f & LBUF_ENABLE) { + b->b.f &= ~LBUF_ENABLE; sel_rmfile(&b->reader); } } @@ -108,23 +114,21 @@ static void selbuf_read(int fd, unsigned mode, void *vp) int n; sz = lbuf_free(&b->b, &p); -again: n = read(fd, p, sz); - if (n <= 0) { - switch (errno) { - case EINTR: - goto again; - case EAGAIN: + if (n == 0) + lbuf_close(&b->b); + else if (n > 0) + lbuf_flush(&b->b, p, n); + else switch (errno) { + case EINTR: + case EAGAIN: #if EAGAIN != EWOULDBLOCK - case EWOULDBLOCK: + case EWOULDBLOCK: #endif - return; - default: - lbuf_close(&b->b); - } + return; + default: + lbuf_close(&b->b); } - else - lbuf_flush(&b->b, p, n); } /* --- @selbuf_init@ --- * @@ -147,7 +151,7 @@ void selbuf_init(selbuf *b, void *p) { lbuf_init(&b->b, func, p); - b->b.f &= ~lbuf_enable; + b->b.f &= ~LBUF_ENABLE; sel_initfile(s, &b->reader, fd, SEL_READ, selbuf_read, b); selbuf_enable(b); }