chiark
/
gitweb
/
~mdw
/
mLib
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use `libtool' to generate a shared library.
[mLib]
/
selbuf.c
diff --git
a/selbuf.c
b/selbuf.c
index 0f07dfc056dc99934301323bd433c59ee7050ce2..b8b11611c69c7ec8e6e7452fd20cbe1ce5a67b0a 100644
(file)
--- a/
selbuf.c
+++ b/
selbuf.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-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
*
*
* Line-buffering select handler
*
@@
-30,6
+30,12
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: selbuf.c,v $
/*----- 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.
*
* 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)
{
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);
}
sel_addfile(&b->reader);
lbuf_flush(&b->b, 0, 0);
}
@@
-83,8
+89,8
@@
void selbuf_enable(selbuf *b)
void selbuf_disable(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);
}
}
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);
int n;
sz = lbuf_free(&b->b, &p);
-again:
n = read(fd, p, sz);
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
#if EAGAIN != EWOULDBLOCK
-
case EWOULDBLOCK:
+ case EWOULDBLOCK:
#endif
#endif
- return;
- default:
- lbuf_close(&b->b);
- }
+ return;
+ default:
+ lbuf_close(&b->b);
}
}
- else
- lbuf_flush(&b->b, p, n);
}
/* --- @selbuf_init@ --- *
}
/* --- @selbuf_init@ --- *
@@
-147,7
+151,7
@@
void selbuf_init(selbuf *b,
void *p)
{
lbuf_init(&b->b, func, p);
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);
}
sel_initfile(s, &b->reader, fd, SEL_READ, selbuf_read, b);
selbuf_enable(b);
}