summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2017-07-21 19:22:34 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2017-07-21 19:22:34 (GMT)
commit3f686a2e5768174553b39697576171f5862433e3 (patch) (side-by-side diff)
treebd0a9ff3ec1c044f89dc61045d0d50ea4420e2bd
parent969dab4c1af666d381124fd481821bc936fc94ed (diff)
downloadruncap-3f686a2e5768174553b39697576171f5862433e3.tar.gz
runcap-3f686a2e5768174553b39697576171f5862433e3.tar.bz2
Speed-up pipe reads
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--runcap.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/runcap.c b/runcap.c
index f2b3d95..f1e9410 100644
--- a/runcap.c
+++ b/runcap.c
@@ -137,15 +137,15 @@ stream_capture_flush(struct stream_capture *cap)
static int
stream_capture_get(struct stream_capture *cap, int *feof)
{
- char c;
int rc;
+ size_t i;
if (cap->sc_level == cap->sc_size) {
if (stream_capture_flush(cap))
return -1;
}
- rc = read(cap->sc_fd, &c, 1);
+ rc = read(cap->sc_fd, cap->sc_base + cap->sc_level, cap->sc_size - cap->sc_level);
if (rc == -1)
return -1;
if (rc == 0) {
@@ -153,17 +153,24 @@ stream_capture_get(struct stream_capture *cap, int *feof)
return 0;
} else
*feof = 0;
- cap->sc_base[cap->sc_level] = c;
- cap->sc_level++;
- cap->sc_leng++;
- if (c == '\n') {
- if (cap->sc_linemon)
- cap->sc_linemon(cap->sc_base + cap->sc_cur,
- cap->sc_level - cap->sc_cur,
- cap->sc_monarg);
- cap->sc_cur = cap->sc_level;
- cap->sc_nlines++;
+
+ i = cap->sc_level;
+
+ cap->sc_level += rc;
+ cap->sc_leng += rc;
+
+ for (; i < cap->sc_level; i++) {
+ if (cap->sc_base[i] == '\n') {
+ if (cap->sc_linemon)
+ cap->sc_linemon(cap->sc_base + cap->sc_cur,
+ i - cap->sc_cur + 1,
+ cap->sc_monarg);
+ cap->sc_cur = i + 1;
+ cap->sc_nlines++;
+ }
}
+
+
return 0;
}

Return to:

Send suggestions and report system problems to the System administrator.