Archived
1
0

correct buffering

This commit is contained in:
Jeff Becker 2018-05-03 14:05:35 -04:00
parent 0c41298fe0
commit b227bf6ff1
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
3 changed files with 21 additions and 13 deletions

View File

@ -47,7 +47,7 @@ public:
private: private:
size_t conns; size_t conns;
int epollfd; int epollfd;
char readbuf[2048]; char readbuf[128];
}; };
} }

View File

@ -150,6 +150,9 @@ void Mainloop::Run()
} }
} }
if(ev->events & EPOLLIN && handler->readable()) if(ev->events & EPOLLIN && handler->readable())
{
bool errored = false;
while(true)
{ {
int readed = handler->read(readbuf, sizeof(readbuf)); int readed = handler->read(readbuf, sizeof(readbuf));
if(readed == -1) if(readed == -1)
@ -159,16 +162,20 @@ void Mainloop::Run()
perror("read()"); perror("read()");
handler->close(); handler->close();
delete handler; delete handler;
continue; errored = true;
} }
break;
} }
else if (readed == 0) else if (readed == 0)
{ {
handler->close(); handler->close();
delete handler; delete handler;
continue; errored = true;
break;
} }
} }
if(errored) continue;
}
if(ev->events & EPOLLOUT && handler->writeable()) if(ev->events & EPOLLOUT && handler->writeable())
{ {
int written = handler->write(); int written = handler->write();

View File

@ -68,6 +68,7 @@ void NNTPServerHandler::OnData(const char *data, ssize_t l)
} }
ArticleObtained(); ArticleObtained();
diff += 5; diff += 5;
if(l - diff)
Data(end + 5, l - diff); Data(end + 5, l - diff);
return; return;
} }