BUGFIX test-client flush stdout, receive chunked json
diff --git a/src/test-client.c b/src/test-client.c
index 8e91a52..08c42a5 100644
--- a/src/test-client.c
+++ b/src/test-client.c
@@ -94,6 +94,7 @@
 void readmultiline(char **output, size_t *size, const char *prompt)
 {
     printf(prompt);
+    fflush(stdout);
     if (getdelim (output, size, 'D' - 0x40, stdin) == -1) {
         if (errno) {
             err(errno, "Cannot read input.");
@@ -121,6 +122,7 @@
 void readline(char **output, size_t *size, const char *prompt)
 {
     printf(prompt);
+    fflush(stdout);
     if (getline (output, size, stdin) == -1) {
         if (errno) {
             err(errno, "Cannot read input.");
@@ -484,12 +486,15 @@
         }
         buffer_size += chunk_len+1;
         buffer = realloc (buffer, sizeof(char)*buffer_size);
-        if ((ret = recv (sock, buffer+buffer_len, chunk_len, 0)) == -1 || ret != chunk_len) {
+        while (buffer_len < chunk_len && ret != -1) {
+            ret = recv (sock, buffer+buffer_len, chunk_len-buffer_len, 0);
+            buffer_len += ret;
+        }
+        if (ret == -1 || buffer_len != chunk_len) {
             free (buffer);
             buffer = NULL;
             break;
         }
-        buffer_len += ret;
     }
 msg_complete: