Handle situation in where we have multiple buffers to send at the end.
[citadel.git] / libcitadel / tests / stringbuf_stream.c
index 6ea03a7b19dd8c809cdab0e04e52624ea0f0934e..1c4a52ea4b52252a6b0b35b85e926ec95935dcfe 100644 (file)
@@ -70,6 +70,7 @@ static void StreamEncode(void)
        IOBuffer ReadBuffer;
        IOBuffer WriteBuffer;
        int err;
+       int ret = 0;
        int done = 0;
        void *vStream;
        
@@ -102,21 +103,23 @@ static void StreamEncode(void)
 
                done = StrBuf_read_one_chunk_callback(fdin,
                                                      0,
-                                                     &ReadBuffer) < SIZ * 4;
+                                                     &ReadBuffer) < (SIZ * 4) -1 ;
                if (IOBufferStrLength(&ReadBuffer) == 0)
                {
                        done = 1;
                }
                do
                {
-                       StrBufStreamTranscode(ST, &WriteBuffer, &ReadBuffer, NULL, -1, vStream, done);
-
-                       while (IOBufferStrLength(&WriteBuffer) > 0)
-                       {
-                               err = StrBuf_write_one_chunk_callback(fdout,
-                                                                     0,
-                                                                     &WriteBuffer);
-                       }
+                       do {
+                               ret = StrBufStreamTranscode(ST, &WriteBuffer, &ReadBuffer, NULL, -1, vStream, done);
+                               
+                               while (IOBufferStrLength(&WriteBuffer) > 0)
+                               {
+                                       err = StrBuf_write_one_chunk_callback(fdout,
+                                                                             0,
+                                                                             &WriteBuffer);
+                               }
+                       } while (ret > 0);
                } while (IOBufferStrLength(&ReadBuffer) > 0);
        }