From: volpol Date: Thu, 23 Aug 2018 18:48:25 +0000 (+0200) Subject: Cleanup receive buffer. Report last pump on error X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=552ca428873e0f2d473b691aaaa6e41c8d422aa4;p=bbd.git Cleanup receive buffer. Report last pump on error --- diff --git a/main.c b/main.c index 52924d5..59cdc43 100644 --- a/main.c +++ b/main.c @@ -35,6 +35,8 @@ static void handle_signal(int sig){ //0 - ready, >0 - busy, -1 - err/unknown static volatile int mix_state; +static volatile int last_pump; + static void mix(const char *recipe){ int idx; int vol; @@ -43,7 +45,7 @@ static void mix(const char *recipe){ int sr; s = recipe; - + last_pump = 0; while (!force_quit && s && *s){ fprintf (stderr, "#%s#\n", s); idx = strtoul(s, &n, 10); @@ -56,6 +58,7 @@ static void mix(const char *recipe){ fprintf (stderr, "START PUMP: %d VOL %d\n", idx, vol); if (0 != pump_add(idx)) break; //or continue? + last_pump = idx; mgmt_start(vol); pump_on(idx); while (MGMT_CONTINUE == (sr = mgmt_stop()) && !force_quit) usleep(100); @@ -100,7 +103,7 @@ do { else { total += bread; if ('\n' == buf[total - 1]){ - buf[total - 1] = 0; + memset (buf + total - 1, 0, sizeof buf - total); fprintf (stderr, "%s\n", buf); if (0 == strncmp((char *)buf, "MIX:", 4)) mix((char *)buf + 4); if (0 == strncmp((char *)buf, "QUIT", 4)) res = -1; @@ -163,8 +166,12 @@ int bbd(void){ DPRINT ("PID: %lX\n", dealer); break; case -1: - - write (as, "ERROR\n", 6); + if (!last_pump) + write (as, "ERROR\n", 6); + else { + char buf[256]; + write (as, buf, sprintf (buf, "ERROR, LAST PUMP:%u\n", last_pump)); + } net_close (as); break; default: