From b227bf6ff1491c01faae8203d32706cdb3cfcefd Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 3 May 2018 14:05:35 -0400 Subject: [PATCH] correct buffering --- .../include/nntpchan/event.hpp | 2 +- .../nntpchan-daemon/libnntpchan/event.cpp | 29 ++++++++++++------- .../libnntpchan/nntp_handler.cpp | 3 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/contrib/backends/nntpchan-daemon/include/nntpchan/event.hpp b/contrib/backends/nntpchan-daemon/include/nntpchan/event.hpp index dfa592e..18da6a6 100644 --- a/contrib/backends/nntpchan-daemon/include/nntpchan/event.hpp +++ b/contrib/backends/nntpchan-daemon/include/nntpchan/event.hpp @@ -47,7 +47,7 @@ public: private: size_t conns; int epollfd; - char readbuf[2048]; + char readbuf[128]; }; } diff --git a/contrib/backends/nntpchan-daemon/libnntpchan/event.cpp b/contrib/backends/nntpchan-daemon/libnntpchan/event.cpp index 7aabbe9..72f9438 100644 --- a/contrib/backends/nntpchan-daemon/libnntpchan/event.cpp +++ b/contrib/backends/nntpchan-daemon/libnntpchan/event.cpp @@ -151,23 +151,30 @@ void Mainloop::Run() } if(ev->events & EPOLLIN && handler->readable()) { - int readed = handler->read(readbuf, sizeof(readbuf)); - if(readed == -1) + bool errored = false; + while(true) { - if(errno != EAGAIN) + int readed = handler->read(readbuf, sizeof(readbuf)); + if(readed == -1) + { + if(errno != EAGAIN) + { + perror("read()"); + handler->close(); + delete handler; + errored = true; + } + break; + } + else if (readed == 0) { - perror("read()"); handler->close(); delete handler; - continue; + errored = true; + break; } } - else if (readed == 0) - { - handler->close(); - delete handler; - continue; - } + if(errored) continue; } if(ev->events & EPOLLOUT && handler->writeable()) { diff --git a/contrib/backends/nntpchan-daemon/libnntpchan/nntp_handler.cpp b/contrib/backends/nntpchan-daemon/libnntpchan/nntp_handler.cpp index c83d1b1..c9cbc44 100644 --- a/contrib/backends/nntpchan-daemon/libnntpchan/nntp_handler.cpp +++ b/contrib/backends/nntpchan-daemon/libnntpchan/nntp_handler.cpp @@ -68,7 +68,8 @@ void NNTPServerHandler::OnData(const char *data, ssize_t l) } ArticleObtained(); diff += 5; - Data(end + 5, l - diff); + if(l - diff) + Data(end + 5, l - diff); return; } if (m_article)