Skip to content
Snippets Groups Projects
Commit d07221fa authored by slevy's avatar slevy
Browse files

bufferedSocket: compute linelen correctly after appending new data to buffer.

Don't need giveup(), just expired().
Fix off-by-one error in consume().
parent 9c870f90
No related branches found
No related tags found
No related merge requests found
......@@ -119,7 +119,7 @@ class bufferedSocket : public arSocket {
if(linelen < 0) {
char *newline = (char *)memchr(tbuf, '\n', got);
if(newline != 0) { // Yep.
linelen = buf.size() + (newline - tbuf);
linelen = buf.size() - got + (newline - tbuf);
buf[linelen] = '\0'; // Replace final \n or \r\n with \0 or \0\0
if(linelen > 0 && buf[linelen] == '\r')
buf[linelen - 1] = '\0';
......@@ -132,11 +132,6 @@ class bufferedSocket : public arSocket {
return linelen;
}
bool giveup()
{
return seeneof;
}
char *str() {
return &buf[0]; // Return pointer to line, which should be a \000-terminated string.
// Only valid if linelen >= 0.
......@@ -149,7 +144,7 @@ class bufferedSocket : public arSocket {
int consume() {
if(linelen >= 0) {
// have any data following the \n?
if(buf.size() > linelen) {
if(buf.size() > linelen+1) {
int newsize = buf.size() - (linelen+1);
memmove(&buf[0], &buf[linelen+1], newsize);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment