From b872a635337b0d5b43b7d885e3710409c6f3b54a Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Thu, 19 Dec 2013 07:56:16 -0500 Subject: [PATCH] dnp_ds40: Handle reading in the plane data as smaller chunks. Fixes use when data is piped in. --- backend_dnpds40.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/backend_dnpds40.c b/backend_dnpds40.c index 500de90..cf98fdb 100644 --- a/backend_dnpds40.c +++ b/backend_dnpds40.c @@ -345,6 +345,7 @@ static int dnpds40_read_parse(void *vctx, int data_fd) { /* Read in command header */ while (1) { + int remain; i = read(data_fd, ctx->databuf + ctx->datalen, sizeof(struct dnpds40_cmd)); if (i < 0) @@ -364,13 +365,19 @@ static int dnpds40_read_parse(void *vctx, int data_fd) { memcpy(buf, ctx->databuf + ctx->datalen + 24, 8); j = atoi(buf); - /* Read in data chunk */ - i = read(data_fd, ctx->databuf + ctx->datalen + sizeof(struct dnpds40_cmd), - j); - if (i < 0) - return i; - if (i != j) - return 1; + /* Read in data chunk as quickly as possible */ + remain = j; + while (remain > 0) { + i = read(data_fd, ctx->databuf + ctx->datalen + sizeof(struct dnpds40_cmd), + remain); + if (i < 0) + return i; + if (i == 0) + return 1; + ctx->datalen += i; + remain -= i; + } + ctx->datalen -= j; /* Back it off */ /* Check for some offsets */ if(!memcmp("CNTRL QTY", ctx->databuf + ctx->datalen+2, 9)) { @@ -902,7 +909,7 @@ static int dnpds40_cmdline_arg(void *vctx, int run, char *arg1, char *arg2) /* Exported */ struct dyesub_backend dnpds40_backend = { .name = "DNP DS40/DS80", - .version = "0.19", + .version = "0.20", .uri_prefix = "dnpds40", .cmdline_usage = dnpds40_cmdline, .cmdline_arg = dnpds40_cmdline_arg,