From 7cdef05710e4cc37feaa9a651e56f7d9e325734e Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Fri, 27 Jun 2014 09:27:43 +0100 Subject: [PATCH] Fix issue with OK being split across multiple reads --- client/maxadmin.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/client/maxadmin.c b/client/maxadmin.c index 79161110b..5710cc35a 100644 --- a/client/maxadmin.c +++ b/client/maxadmin.c @@ -25,6 +25,8 @@ * Date Who Description * 13/06/14 Mark Riddoch Initial implementation * 15/06/14 Mark Riddoch Addition of source command + * 26/06/14 Mark Riddoch Fix issue with final OK split across + * multiple reads * * @endverbatim */ @@ -440,7 +442,9 @@ char buf[20]; /** * Send a comamnd using the MaxScaled protocol, display the return data - * on standard output + * on standard output. + * + * Input terminates with a lien containing jsut the text OK * * @param so The socket connect to MaxScale * @param cmd The command to send @@ -450,19 +454,38 @@ static int sendCommand(int so, char *cmd) { char buf[80]; -int i; +int i, j, newline = 0; write(so, cmd, strlen(cmd)); while (1) { if ((i = read(so, buf, 80)) == -1) return 0; - if (i > 1 && buf[i-1] == 'K' && buf[i-2] == 'O') + for (j = 0; j < i; j++) { - write(1, buf, i - 2); - return 1; + if (newline == 1 && buf[j] == 'O') + newline = 2; + else if (newline == 2 && buf[j] == 'K' && j == i - 1) + { + return 1; + } + else if (newline == 2) + { + putchar('O'); + putchar(buf[j]); + newline = 0; + } + else if (buf[j] == '\n' || buf[j] == '\r') + { + putchar(buf[j]); + newline = 1; + } + else + { + putchar(buf[j]); + newline = 0; + } } - write(1, buf, i); } return 1; }