From 1acf8374638d36926c5ecd37eb15bd01811720ba Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Wed, 31 Aug 2011 08:01:45 +0000 Subject: [PATCH] StrBufChunkSipLine(): compact buffer if we have a remaining snippet at the end of the buffer --- libcitadel/lib/stringbuf.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index 2ee3a2534..044cecf0a 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -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; } } -- 2.30.2