StrBufChunkSipLine(): compact buffer if we have a remaining snippet at the end of...
[citadel.git] / libcitadel / lib / stringbuf.c
index 2ee3a2534aca8384985482867e7a739918612ab9..044cecf0a65037c3f7d2fb9784c8c41913b4ef2e 100644 (file)
@@ -3705,7 +3705,18 @@ eReadState StrBufChunkSipLine(StrBuf *LineBuf, IOBuffer *FB)
                        optr --;
                if ((*(ptr - 1) != '\r') && (*(ptr - 1) != '\n')) {
                        LineBuf->BufUsed = optr - LineBuf->buf;
-                       *optr = '\0';       
+                       *optr = '\0';
+                       if ((FB->ReadWritePointer != NULL) && 
+                           (FB->ReadWritePointer != FB->Buf->buf))
+                       {
+                               /* Ok, the client application read all the data 
+                                  it was interested in so far. Since there is more to read, 
+                                  we now shrink the buffer, and move the rest over.
+                               */
+                               StrBufCutLeft(FB->Buf, 
+                                             FB->ReadWritePointer - FB->Buf->buf);
+                               FB->ReadWritePointer = NULL;
+                       }
                        return eMustReadMore;
                }
        }